fapost else if to be sure

This commit is contained in:
Sendou
2020-03-25 00:57:05 +02:00
parent 636e9262ad
commit acd03a2906
6 changed files with 708 additions and 757 deletions

View File

@@ -38,7 +38,6 @@ const FAPostModal: React.FC<FAPostModalProps> = ({ closeModal, post }) => {
)
const [showErrors, setShowErrors] = useState(false)
const [deleting, setDeleting] = useState(false)
const [disableSubmit, setDisableSubmit] = useState(false)
const toast = useToast()
const { themeColor, grayWithShade } = useContext(MyThemeContext)
@@ -130,7 +129,6 @@ const FAPostModal: React.FC<FAPostModalProps> = ({ closeModal, post }) => {
const actionType = post ? "EDIT" : "NEW"
const handleSubmit = () => {
if (disableSubmit) return
if (
form.playstyles?.length === 0 ||
!form.can_vc ||
@@ -143,10 +141,8 @@ const FAPostModal: React.FC<FAPostModalProps> = ({ closeModal, post }) => {
return
}
setDisableSubmit(true)
if (actionType === "NEW") addFreeAgentPost()
if (actionType === "EDIT") editFreeAgentPost()
setDisableSubmit(false)
else if (actionType === "EDIT") editFreeAgentPost()
}
return (

View File

@@ -163,14 +163,8 @@ const resolvers = {
invalidArgs: args,
})
const items = gear.flatMap(brand => {
const headItems = brand.head ? brand.head : []
const clothesItems = brand.clothes ? brand.clothes : []
const shoesItems = brand.shoes ? brand.shoes : []
return headItems.concat(clothesItems).concat(shoesItems)
})
if (args.headgearItem) {
if (!items.includes(args.headgearItem))
if (!gear.includes(args.headgearItem))
throw new UserInputError("Invalid headgear item.", {
invalidArgs: args,
})
@@ -178,7 +172,7 @@ const resolvers = {
args.headgearItem = undefined
}
if (args.clothingItem) {
if (!items.includes(args.clothingItem))
if (!gear.includes(args.clothingItem))
throw new UserInputError("Invalid clothing item.", {
invalidArgs: args,
})
@@ -186,7 +180,7 @@ const resolvers = {
args.clothingItem = undefined
}
if (args.shoesItem) {
if (!items.includes(args.shoesItem))
if (!gear.includes(args.shoesItem))
throw new UserInputError("Invalid shoes item.", {
invalidArgs: args,
})
@@ -254,26 +248,20 @@ const resolvers = {
invalidArgs: args,
})
const items = gear.flatMap(brand => {
const headItems = brand.head ? brand.head : []
const clothesItems = brand.clothes ? brand.clothes : []
const shoesItems = brand.shoes ? brand.shoes : []
return headItems.concat(clothesItems).concat(shoesItems)
})
if (args.headgearItem) {
if (!items.includes(args.headgearItem))
if (!gear.includes(args.headgearItem))
throw new UserInputError("Invalid headgear item.", {
invalidArgs: args,
})
}
if (args.clothingItem) {
if (!items.includes(args.clothingItem))
if (!gear.includes(args.clothingItem))
throw new UserInputError("Invalid clothing item.", {
invalidArgs: args,
})
}
if (args.shoesItem) {
if (!items.includes(args.shoesItem))
if (!gear.includes(args.shoesItem))
throw new UserInputError("Invalid shoes item.", {
invalidArgs: args,
})

View File

@@ -1,12 +1,12 @@
const { UserInputError, gql } = require("apollo-server-express")
const DetailedTournament = require("../mongoose-models/detailedtournament")
const DetailedSet = require("../mongoose-models/detailedset")
const DetailedMatch = require("../mongoose-models/detailedmatch")
const typeDef = gql`
extend type Mutation {
addDetailedTournament(
tournament: DetailedTournamentInput!
maps: [DetailedMapInput!]!
matches: [DetailedMatchInput!]!
lanistaToken: String!
): Boolean!
}
@@ -28,9 +28,20 @@ const typeDef = gql`
type: EventType!
}
input DetailedMapInput {
input DetailedMatchInput {
round_name: String!
round_number: Int!
game_number: Int!
match_details: [DetailedMapInput!]!
}
type DetailedMatch {
round_name: String!
round_number: Int!
match_details: [DetailedMap!]!
type: EventType!
}
input DetailedMapInput {
stage: String!
mode: Mode!
duration: Int!
@@ -40,15 +51,12 @@ const typeDef = gql`
type DetailedMap {
tournament_id: DetailedTournament!
round_number: Int!
game_number: Int!
stage: String!
mode: Mode!
"Duration of the round in seconds"
duration: Int!
winners: TeamInfo!
losers: TeamInfo!
type: EventType!
}
input TeamInfoInput {

View File

@@ -19,18 +19,22 @@ const TeamInfo = {
score: Number,
}
const detailedSetSchema = new mongoose.Schema({
const Map = {
tournament_id: {
type: mongoose.Schema.Types.ObjectId,
ref: "DetailedTournament",
},
round_number: Number,
game_number: Number,
stage: String,
mode: String,
duration: Number,
winners: TeamInfo,
losers: TeamInfo,
}
const detailedMatchSchema = new mongoose.Schema({
round_number: Number,
round_name: String,
match_details: [Map],
})
module.exports = mongoose.model("DetailedSet", detailedSetSchema)
module.exports = mongoose.model("DetailedMatch", detailedMatchSchema)

File diff suppressed because it is too large Load Diff

View File

@@ -1,16 +1,13 @@
const { UserInputError } = require("apollo-server-express")
const DetailedTournament = require("../mongoose-models/detailedtournament")
const weapons = require("../utils/weapons")
const gear = require("../utils/gear")
const stages = require("../utils/maps")
function isNum(maybeNumber) {
return /^\d+$/.test(maybeNumber)
}
/*name: String!
bracket_url: String!
date: String!
top_3_team_names: [String!]!
top_3_discord_ids: [[String!]!]!*/
async function validateDetailedTournamentInput(input) {
const existingTournament = await DetailedTournament.find({ name: input.name })
@@ -18,6 +15,8 @@ async function validateDetailedTournamentInput(input) {
throw new UserInputError("Tournament with that name already exists")
}
//date not validated
if (input.top_3_team_names.length !== 3) {
throw new UserInputError("Length of top_3_team_names was not 3")
}
@@ -39,3 +38,95 @@ async function validateDetailedTournamentInput(input) {
})
})
}
async function validateDetailedMapInput(input) {
if (!stages.includes(input.stage)) {
throw new UserInputError(`Invalid stage name: ${input.stage}`)
}
if (!["SZ", "TC", "RM", "CB", "TW"].includes(input.mode)) {
throw new UserInputError(`Invalid mode name: ${input.mode}`)
}
if (input.duration < 0 || input.duration > 500) {
throw new UserInputError(`Invalid duration: ${input.duration}`)
}
if (input.winners.score <= input.losers.score) {
throw new UserInputError(
"Losing team has greater or equal score as the winner team"
)
}
input.winners.players.forEach(player => validateDetailedPlayerInput(player))
input.losers.players.forEach(player => validateDetailedPlayerInput(player))
}
/*input DetailedPlayerInput {
discord_id: String!
weapon: String!
main_abilities: [Ability!]!
sub_abilities: [Ability]!
kills: Int!
assists: Int!
deaths: Int!
specials: Int!
paint: Int!
gear: [String]!
}*/
async function validateDetailedPlayerInput(input) {
if (!isNum(input.discord_id)) {
throw new UserInputError(`Invalid Discord ID: ${input.discord_id}`)
}
if (!weapons.includes(input.weapon)) {
throw new UserInputError(`Invalid weapon: ${input.weapon}`)
}
if (input.main_abilities.length !== 3) {
throw new UserInputError(
`Invalid main abilities length: ${input.main_abilities.length}`
)
}
if (input.sub_abilities.length !== 9) {
throw new UserInputError(
`Invalid main abilities length: ${input.sub_abilities.length}`
)
}
if (input.kills < 0 || input.kills > 50) {
throw new UserInputError(`Invalid kill count: ${input.kills}`)
}
if (input.assists < 0 || input.assists > 50) {
throw new UserInputError(`Invalid assist count: ${input.assists}`)
}
if (input.deaths < 0 || input.deaths > 50) {
throw new UserInputError(`Invalid death count: ${input.deaths}`)
}
if (input.specials < 0 || input.specials > 50) {
throw new UserInputError(`Invalid special count: ${input.specials}`)
}
if (input.paint < 0 || input.paint > 5000) {
throw new UserInputError(`Invalid paint count: ${input.paint}`)
}
if (input.gear.length !== 3) {
throw new UserInputError(`Invalid gear length: ${input.gear.length}`)
}
input.gear.forEach(gearPiece => {
if (!gear.includes(gearPiece)) {
throw new UserInputError(`Invalid gear: ${gearPiece}`)
}
})
}
module.exports = {
validateDetailedTournamentInput,
}