mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-27 21:55:15 -05:00
fa fixes
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ export interface FreeAgentPost {
|
||||
discord_id: string
|
||||
twitter_name?: string
|
||||
country?: CountryCode
|
||||
weapons: Weapon[]
|
||||
weapons?: Weapon[]
|
||||
top500: boolean
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
35
utils/validators.js
Normal 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}`)
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user