This commit is contained in:
powermaker450 2024-08-18 23:45:00 -04:00
parent 34bcb07a1a
commit 6298fe8cfc
3 changed files with 19 additions and 14 deletions

View file

@ -18,7 +18,6 @@ http
const sender = `${bold(emp("Client:"))} ${emp(req.headers["user-agent"])}`; const sender = `${bold(emp("Client:"))} ${emp(req.headers["user-agent"])}`;
req.on("data", async (chunk) => { req.on("data", async (chunk) => {
if (req.url === "/post") { if (req.url === "/post") {
let data: Review[] = checkFile("data.json", "utf8"); let data: Review[] = checkFile("data.json", "utf8");
let temp: any; let temp: any;
@ -69,7 +68,7 @@ http
req.on("end", () => { req.on("end", () => {
if (!isPost) { if (!isPost) {
res.writeHead(404, {"Content-Type": "text/plain"}); res.writeHead(404, { "Content-Type": "text/plain" });
res.write(`Cannot ${req.method} ${req.url}`); res.write(`Cannot ${req.method} ${req.url}`);
res.end(); res.end();
} }

View file

@ -2,11 +2,17 @@ import { object, string, number, InferType } from "yup";
export const reviewSchema = object({ export const reviewSchema = object({
username: string().strict(true).max(30).required(), username: string().strict(true).max(30).required(),
rating: number().positive().max(5).test( rating: number()
.positive()
.max(5)
.test(
"maxDigitsAfterDecimal", "maxDigitsAfterDecimal",
"Rating can only have at most one integer at half intervals (.0 or .5)", "Rating can only have at most one integer at half intervals (.0 or .5)",
number => { !((number! * 10) % 5) } (number) => {
).required(), !((number! * 10) % 5);
},
)
.required(),
title: string().strict(true).max(50).required(), title: string().strict(true).max(50).required(),
content: string().strict(true).max(2000).notRequired(), content: string().strict(true).max(2000).notRequired(),
}); });

View file

@ -5,7 +5,7 @@ export class Responder {
public success(message: string): string { public success(message: string): string {
return JSON.stringify({ return JSON.stringify({
message: message message: message,
}); });
} }
@ -13,8 +13,8 @@ export class Responder {
return JSON.stringify({ return JSON.stringify({
error: { error: {
type: error.name, type: error.name,
message: error.message message: error.message,
} },
}); });
} }
@ -22,8 +22,8 @@ export class Responder {
return JSON.stringify({ return JSON.stringify({
error: { error: {
type: "RequestError", type: "RequestError",
message: errorMessage message: errorMessage,
} },
}); });
} }
@ -31,8 +31,8 @@ export class Responder {
return JSON.stringify({ return JSON.stringify({
error: { error: {
type: "JsonError", type: "JsonError",
message: errorMessage message: errorMessage,
} },
}); });
} }
} }