chore: req validation for api/developer (#5482)

This commit is contained in:
Apoorv Mishra
2023-06-26 19:20:22 +05:30
committed by GitHub
parent 06f2d7a993
commit 9987c15daf
3 changed files with 16 additions and 2 deletions

View File

@@ -5,8 +5,10 @@ import userInviter, { Invite } from "@server/commands/userInviter";
import env from "@server/env";
import Logger from "@server/logging/Logger";
import auth from "@server/middlewares/authentication";
import validate from "@server/middlewares/validate";
import { presentUser } from "@server/presenters";
import { APIContext } from "@server/types";
import * as T from "./schema";
const router = new Router();
@@ -24,8 +26,9 @@ router.post(
"developer.create_test_users",
dev(),
auth(),
async (ctx: APIContext) => {
const { count = 10 } = ctx.request.body;
validate(T.CreateTestUsersSchema),
async (ctx: APIContext<T.CreateTestUsersReq>) => {
const { count = 10 } = ctx.input.body;
const { user } = ctx.state.auth;
const invites = Array(Math.min(count, 100))
.fill(0)

View File

@@ -0,0 +1 @@
export { default } from "./developer";

View File

@@ -0,0 +1,10 @@
import { z } from "zod";
import BaseSchema from "../BaseSchema";
export const CreateTestUsersSchema = BaseSchema.extend({
body: z.object({
count: z.coerce.number().default(10),
}),
});
export type CreateTestUsersReq = z.infer<typeof CreateTestUsersSchema>;