mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-26 01:09:02 -05:00
duplicate suggestion bug fix
This commit is contained in:
parent
f3aa8692f0
commit
d8b5854747
|
|
@ -17,7 +17,7 @@ const UserPage = () => {
|
|||
const { id } = useParams()
|
||||
const [tab, setTab] = useQueryParam("tab", NumberParam)
|
||||
const { data, error, loading } = useQuery(searchForUser, {
|
||||
variables: { discord_id: id },
|
||||
variables: isNaN(id) ? { short_url: id } : { discord_id: id },
|
||||
})
|
||||
const userLeanQuery = useQuery(userLean)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ const {
|
|||
gql,
|
||||
} = require("apollo-server-express")
|
||||
const User = require("../mongoose-models/user")
|
||||
const Ballot = require("../mongoose-models/ballot")
|
||||
const Suggested = require("../mongoose-models/suggested")
|
||||
const Summary = require("../mongoose-models/summary")
|
||||
const VotedPerson = require("../mongoose-models/votedperson")
|
||||
|
|
@ -77,14 +76,6 @@ const typeDef = gql`
|
|||
score: Float!
|
||||
}
|
||||
|
||||
type Ballot {
|
||||
discord_id: String!
|
||||
plus_server: PlusServer!
|
||||
month: Int!
|
||||
year: Int!
|
||||
votes: [VotedPerson!]!
|
||||
}
|
||||
|
||||
"Voting result of a player"
|
||||
type Summary {
|
||||
discord_id: String!
|
||||
|
|
@ -195,6 +186,22 @@ const resolvers = {
|
|||
|
||||
if (suggestion) throw new UserInputError("Already suggested this month.")
|
||||
|
||||
const duplicateSuggestion = await Suggested.findOne({
|
||||
discord_id: args.discord_id,
|
||||
plus_server: args.server,
|
||||
}).catch(e => {
|
||||
throw (new Error(),
|
||||
{
|
||||
invalidArgs: args,
|
||||
error: e,
|
||||
})
|
||||
})
|
||||
|
||||
if (duplicateSuggestion)
|
||||
throw new UserInputError(
|
||||
"This user has already been suggested this month."
|
||||
)
|
||||
|
||||
if (!user)
|
||||
throw new UserInputError("Suggested user not sendou.ink member.")
|
||||
|
||||
|
|
|
|||
|
|
@ -99,6 +99,8 @@ const resolvers = {
|
|||
let searchCriteria = {}
|
||||
if (args.twitter) searchCriteria = { twitter_name: args.twitter }
|
||||
else if (args.discord_id) searchCriteria = { discord_id: args.discord_id }
|
||||
else if (args.short_url)
|
||||
searchCriteria = { short_url: args.short_url.toLowerCase() }
|
||||
else
|
||||
throw new UserInputError("no twitter or discord id provided", {
|
||||
invalidArgs: args,
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
const mongoose = require("mongoose")
|
||||
|
||||
const ballotSchema = new mongoose.Schema({
|
||||
discord_id: { type: String, required: true },
|
||||
plus_server: { type: String, required: true },
|
||||
month: { type: Number, required: true },
|
||||
year: { type: Number, required: true },
|
||||
votes: { type: [mongoose.Schema.Types.ObjectId], required: true },
|
||||
})
|
||||
|
||||
module.exports = mongoose.model("BallotPerson", ballotSchema)
|
||||
Loading…
Reference in New Issue
Block a user