Skip to content

Commit b9b515e

Browse files
committed
Refactor validation function
1 parent 327a1ed commit b9b515e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/backend/src/server/tasks.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,17 @@ const unknownErrorHandler: ErrorRequestHandler = (err, req, res, next) => {
5252
next();
5353
};
5454

55-
const validate =
56-
<T extends z.ZodType<unknown>>(
57-
schema: T,
58-
): RequestHandler<Record<string, string>, unknown, z.infer<T>> =>
59-
async (req, _, next) => {
60-
const validated = await schema.parseAsync(req.body);
61-
req.body = validated;
55+
56+
57+
function validate<T>(
58+
body: z.ZodType<T>,
59+
): RequestHandler<Record<string, string | undefined>, unknown, T> {
60+
return async (req, _, next) => {
61+
req.body = await body.parseAsync(req.body);
6262
return next();
6363
};
64+
}
65+
6466
export function taskRouter(client: pg.Pool, router = Router()) {
6567
router.use(json());
6668

0 commit comments

Comments
 (0)