Request validation for cron (#5307)

* chore: add validations for /api/cron.*

* fix: coerce limit to number

* fix: review
This commit is contained in:
Apoorv Mishra
2023-05-07 10:41:20 +05:30
committed by GitHub
parent 3421f24896
commit c8ee501377
5 changed files with 140 additions and 24 deletions

View File

@@ -0,0 +1,18 @@
import { isEmpty } from "lodash";
import { z } from "zod";
import BaseSchema from "../BaseSchema";
export const CronSchema = BaseSchema.extend({
body: z.object({
token: z.string().optional(),
limit: z.coerce.number().gt(0).default(500),
}),
query: z.object({
token: z.string().optional(),
limit: z.coerce.number().gt(0).default(500),
}),
}).refine((req) => !(isEmpty(req.body.token) && isEmpty(req.query.token)), {
message: "token is required",
});
export type CronSchemaReq = z.infer<typeof CronSchema>;