This commit is contained in:
Sendou
2020-03-24 20:02:04 +02:00
parent c4687072c9
commit 095a24edd0
4 changed files with 45 additions and 10 deletions

View File

@@ -75,7 +75,9 @@ const FreeAgentsPage: React.FC<RouteComponentProps> = () => {
const postsFilter = (post: FreeAgentPost) => {
if (post.hidden) return false
if (weapon && post.discord_user.weapons.indexOf(weapon) === -1) {
const usersWeapons = post.discord_user.weapons ?? []
if (weapon && usersWeapons.indexOf(weapon) === -1) {
return false
}

View File

@@ -147,7 +147,7 @@ export interface FreeAgentPost {
discord_id: string
twitter_name?: string
country?: CountryCode
weapons: Weapon[]
weapons?: Weapon[]
top500: boolean
}
}

View File

@@ -198,14 +198,12 @@ const resolvers = {
const faPost = new FAPost({ ...args, discord_id: ctx.user.discord_id })
args.user = ctx.user
await Promise.race([faPost.save(), sendFAPostToDiscord(args)]).catch(
e => {
throw (new UserInputError(),
{
invalidArgs: args,
})
}
)
await Promise.all([faPost.save(), sendFAPostToDiscord(args)]).catch(e => {
throw (new UserInputError(),
{
invalidArgs: args,
})
})
return true
},

35
utils/validators.js Normal file
View File

@@ -0,0 +1,35 @@
const { UserInputError } = require("apollo-server-express")
const DetailedTournament = require("../mongoose-models/detailedtournament")
function isNum(maybeNumber) {
return /^\d+$/.test(maybeNumber)
}
/*name: String!
bracket_url: String!
date: String!
top_3_team_names: [String!]!
top_3_discord_ids: [[String!]!]!*/
function validateDetailedTournamentInput(input) {
if (input.top_3_team_names.length !== 3) {
throw new UserInputError("Length of top_3_team_names was not 3")
}
if (input.top_3_discord_ids.length !== 3) {
throw new UserInputError("Length of top_3_discord_ids was not 3")
}
input.top_3_discord_ids.forEach(discord_id_arr => {
if (discord_id_arr.length !== 4) {
throw new UserInputError(
"Length of top_3_discord_ids contained an array that had invalid length"
)
}
discord_id_arr.forEach(discord_id => {
if (!isNum(discord_id))
throw new UserInputError(`Invalid Discord ID: ${discord_id}`)
})
})
}