Prettier
This commit is contained in:
parent
34bcb07a1a
commit
6298fe8cfc
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
16
src/types.ts
16
src/types.ts
|
@ -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()
|
||||||
"maxDigitsAfterDecimal",
|
.positive()
|
||||||
"Rating can only have at most one integer at half intervals (.0 or .5)",
|
.max(5)
|
||||||
number => { !((number! * 10) % 5) }
|
.test(
|
||||||
).required(),
|
"maxDigitsAfterDecimal",
|
||||||
|
"Rating can only have at most one integer at half intervals (.0 or .5)",
|
||||||
|
(number) => {
|
||||||
|
!((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(),
|
||||||
});
|
});
|
||||||
|
|
|
@ -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,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue