This commit is contained in:
MeowcaTheoRange 2023-07-03 00:30:27 -05:00
parent b3d1a530b6
commit 42b8b0840a
3 changed files with 13 additions and 7 deletions

View file

@ -10,8 +10,7 @@ import {
} from "@/lib/trollcall/perms";
import { changeTroll, getSingleTroll } from "@/lib/trollcall/troll";
import { getSingleUser } from "@/lib/trollcall/user";
import { SubmitTroll } from "@/types/client/troll";
import { PartialUserSchema } from "@/types/client/user";
import { PartialTrollSchema, SubmitTroll } from "@/types/client/troll";
import { Router } from "express";
import { NextApiRequest, NextApiResponse } from "next";
@ -37,7 +36,7 @@ export default async function handler(
} else if (method === "PUT") {
let validatedTroll: Partial<SubmitTroll>;
try {
validatedTroll = (await PartialUserSchema.validate(body, {
validatedTroll = (await PartialTrollSchema.validate(body, {
stripUnknown: true
})) as Partial<SubmitTroll>;
} catch (err) {

View file

@ -109,6 +109,7 @@ export const SubmitTrollSchema = yup
return v === "" ? null : v;
})
.oneOf(TrueSignKeys), // "Keelez Bunbat"
prioritizeTrueSign: yup.boolean().default(false),
class: yup.string().required().oneOf(ClassKeys),
// Trollian
@ -127,10 +128,11 @@ export const SubmitTrollSchema = yup
species: yup
.string()
.notRequired()
.matches(/^([A-z-]+)|()$/, "Letters only"), // "Troll-*" if defined. Otherwise, just "Troll".
.matches(/^([A-z-]+)|()$/, "Letters only")
.max(50), // "Troll-*" if defined. Otherwise, just "Troll".
height: yup.number().required().positive(), // Inches
age: yup.number().required().positive(), // Sweeps
image: yup.string().required().url(),
images: yup.array().of(yup.string().required().url()).required(),
// Meta stuff
policies: yup
.object({
@ -221,6 +223,7 @@ export const PartialTrollSchema = yup
return v === "" ? null : v;
})
.oneOf(TrueSignKeys), // "Keelez Bunbat"
prioritizeTrueSign: yup.boolean(),
class: yup.string().oneOf(ClassKeys),
// Trollian
@ -239,10 +242,13 @@ export const PartialTrollSchema = yup
// Handled! :D
// Physical stuff
species: yup.string().matches(/^([A-z-]+)|()$/, "Letters only"), // "Troll-*" if defined. Otherwise, just "Troll".
species: yup
.string()
.matches(/^([A-z-]+)|()$/, "Letters only")
.max(50), // "Troll-*" if defined. Otherwise, just "Troll".
height: yup.number().positive(), // Inches
age: yup.number().positive(), // Sweeps
image: yup.string().url(),
images: yup.array().of(yup.string().url()),
// Meta stuff
policies: yup.object({
fanart: PolicySchema,

View file

@ -8,6 +8,7 @@
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"noErrorTruncation": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,