Adds safeParseJSON to the body

pull/9078/head
Syed Ali Shahbaz 2022-10-07 13:03:09 +05:30 committed by GitHub
parent 36a0ebfbad
commit 79fabe0333
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -1,5 +1,6 @@
import type { NextApiRequest, NextApiResponse } from "next"; import type { NextApiRequest, NextApiResponse } from "next";
import safeParseJSON from "@lib/helpers/safeParseJSON";
import { withMiddleware } from "@lib/helpers/withMiddleware"; import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { ScheduleResponse } from "@lib/types"; import type { ScheduleResponse } from "@lib/types";
import { schemaSingleScheduleBodyParams, schemaSchedulePublic } from "@lib/validations/schedule"; import { schemaSingleScheduleBodyParams, schemaSchedulePublic } from "@lib/validations/schedule";
@ -13,7 +14,7 @@ export async function scheduleById(
res: NextApiResponse<ScheduleResponse> res: NextApiResponse<ScheduleResponse>
) { ) {
const safeQuery = schemaQueryIdParseInt.safeParse(query); const safeQuery = schemaQueryIdParseInt.safeParse(query);
const safeBody = schemaSingleScheduleBodyParams.safeParse(body); const safeBody = schemaSingleScheduleBodyParams.safeParse(safeParseJSON(body));
if (!safeBody.success) { if (!safeBody.success) {
res.status(400).json({ message: "Bad request" }); res.status(400).json({ message: "Bad request" });
return; return;