diff --git a/frontend-react/src/components/freeagents/FreeAgentsPage.tsx b/frontend-react/src/components/freeagents/FreeAgentsPage.tsx index e5bb46b46..0fc2dd7af 100644 --- a/frontend-react/src/components/freeagents/FreeAgentsPage.tsx +++ b/frontend-react/src/components/freeagents/FreeAgentsPage.tsx @@ -75,7 +75,9 @@ const FreeAgentsPage: React.FC = () => { 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 } diff --git a/frontend-react/src/types.ts b/frontend-react/src/types.ts index e241a7ee9..4a52a693c 100644 --- a/frontend-react/src/types.ts +++ b/frontend-react/src/types.ts @@ -147,7 +147,7 @@ export interface FreeAgentPost { discord_id: string twitter_name?: string country?: CountryCode - weapons: Weapon[] + weapons?: Weapon[] top500: boolean } } diff --git a/graphql-schemas/fapost.js b/graphql-schemas/fapost.js index 9d73e2afb..e3fa0f698 100644 --- a/graphql-schemas/fapost.js +++ b/graphql-schemas/fapost.js @@ -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 }, diff --git a/utils/validators.js b/utils/validators.js new file mode 100644 index 000000000..4a00865d6 --- /dev/null +++ b/utils/validators.js @@ -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}`) + }) + }) +}