Request validation for cron (#5307)
* chore: add validations for /api/cron.* * fix: coerce limit to number * fix: review
This commit is contained in:
18
server/routes/api/cron/schema.ts
Normal file
18
server/routes/api/cron/schema.ts
Normal 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>;
|
||||
Reference in New Issue
Block a user