mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-07-17 09:26:20 -05:00
* compiles but looks ugly * create sr record working version * validate and tsify * chakra ui v 1.0 icon fixes * new ui first ver * remove unused icon * remove imports , color picker work * color picker done * set bg color proper * suggests vouches page * remove unused deps * voting history page * build analyzer improvements * calendar page new * footer stay down * ui refresh stuff * x trends dont show tier if no weapons * draft cup page new look * plus faq page * cra 4 beta * top logo placed center * weapon images new import style * top nav aling correctly in mobile resolution * nav changes * initial xleaderboard * peak x powers backend * graphql codegen * switched to apollo/client package * initial xleaderboard table * insert player ids * dataloaders * ts-node dev dep * x leaderboard basic * xleaderboard testing * x rank placements backend * all leaderboards frontend components initial * pagination tweaking * ran prettier * leaderboards doneish * top 500 browser basic * top 500 browser * pagination tweaks * implemented filters * user page placements * remove useless * useEffect only call on name change * markdown use new table style * use mode images * search by player id * link to xsearch from leaderboards * translated * disable next if no pagecount * remove comment
133 lines
3.4 KiB
JavaScript
133 lines
3.4 KiB
JavaScript
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);
|
|
}
|
|
|
|
async function validateDetailedTournamentInput(input) {
|
|
const problems = [];
|
|
const existingTournament = await DetailedTournament.findOne({
|
|
name: input.name,
|
|
});
|
|
|
|
if (existingTournament) {
|
|
problems.push("Tournament with that name already exists");
|
|
}
|
|
|
|
//date not validated
|
|
|
|
if (input.top_3_team_names.length !== 3) {
|
|
problems.push("Length of top_3_team_names was not 3");
|
|
}
|
|
|
|
if (input.top_3_discord_ids.length !== 3) {
|
|
problems.push("Length of top_3_discord_ids was not 3");
|
|
}
|
|
|
|
input.top_3_discord_ids.forEach((discord_id_arr) => {
|
|
if (discord_id_arr.length !== 4) {
|
|
problems.push(
|
|
"Length of top_3_discord_ids contained an array that had invalid length"
|
|
);
|
|
}
|
|
|
|
discord_id_arr.forEach((discord_id) => {
|
|
if (!isNum(discord_id))
|
|
problems.push(`Invalid Discord ID: ${discord_id}`);
|
|
});
|
|
});
|
|
|
|
return problems;
|
|
}
|
|
|
|
function validateDetailedMapInput(input) {
|
|
const problems = [];
|
|
if (!stages.includes(input.stage)) {
|
|
problems.push(`Invalid stage name: ${input.stage}`);
|
|
}
|
|
|
|
if (!["SZ", "TC", "RM", "CB", "TW"].includes(input.mode)) {
|
|
problems.push(`Invalid mode name: ${input.mode}`);
|
|
}
|
|
|
|
if (input.duration < 0 || input.duration > 500) {
|
|
problems.push(`Invalid duration: ${input.duration}`);
|
|
}
|
|
|
|
if (input.winners.score <= input.losers.score) {
|
|
problems.push("Losing team has greater or equal score as the winner team");
|
|
}
|
|
|
|
input.winners.players.forEach((player) =>
|
|
validateDetailedPlayerInput(player, problems)
|
|
);
|
|
input.losers.players.forEach((player) =>
|
|
validateDetailedPlayerInput(player, problems)
|
|
);
|
|
|
|
return problems;
|
|
}
|
|
|
|
function validateDetailedPlayerInput(input, problems) {
|
|
if (input.discord_id && !isNum(input.discord_id)) {
|
|
problems.push(`Invalid Discord ID: ${input.discord_id}`);
|
|
}
|
|
|
|
if (!weapons.includes(input.weapon)) {
|
|
problems.push(`Invalid weapon: ${input.weapon}`);
|
|
}
|
|
|
|
if (input.main_abilities.length !== 3) {
|
|
problems.push(
|
|
`Invalid main abilities length: ${input.main_abilities.length}`
|
|
);
|
|
}
|
|
|
|
if (input.sub_abilities.flat().length !== 9) {
|
|
problems.push(
|
|
`Invalid sub abilities length: ${input.sub_abilities.flat().length}`
|
|
);
|
|
}
|
|
|
|
if (input.kills < 0 || input.kills > 50) {
|
|
problems.push(`Invalid kill count: ${input.kills}`);
|
|
}
|
|
|
|
if (input.assists < 0 || input.assists > 50) {
|
|
problems.push(`Invalid assist count: ${input.assists}`);
|
|
}
|
|
|
|
if (input.deaths < 0 || input.deaths > 50) {
|
|
problems.push(`Invalid death count: ${input.deaths}`);
|
|
}
|
|
|
|
if (input.specials < 0 || input.specials > 50) {
|
|
problems.push(`Invalid special count: ${input.specials}`);
|
|
}
|
|
|
|
if (input.paint < 0 || input.paint > 5000) {
|
|
problems.push(`Invalid paint count: ${input.paint}`);
|
|
}
|
|
|
|
if (input.gear) {
|
|
if (input.gear.length !== 3)
|
|
problems.push(`Invalid gear length: ${input.gear.length}`);
|
|
|
|
input.gear.forEach((gearPiece) => {
|
|
if (!gear.includes(gearPiece)) {
|
|
problems.push(`Invalid gear: ${gearPiece}`);
|
|
}
|
|
});
|
|
}
|
|
|
|
return problems;
|
|
}
|
|
|
|
module.exports = {
|
|
validateDetailedTournamentInput,
|
|
validateDetailedMapInput,
|
|
};
|