-
Notifications
You must be signed in to change notification settings - Fork 1
/
route.ts
33 lines (28 loc) · 800 Bytes
/
route.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import type { Request, Response } from "express";
import multer from "multer";
import { z } from "zod";
import { handleError } from "../../../lib/utils";
const upload = multer({ dest: "uploads/" });
const userSchema = z.object({
name: z.string(),
age: z.string(),
});
export const POST = [
upload.single("file"),
(req: Request, res: Response) => {
try {
const body = req.body;
const file = req.file;
const user = userSchema.parse(body);
return res.status(200).json({
message: "File uploaded successfully",
data: {
file,
user,
},
});
} catch (error) {
return handleError(error, res);
}
},
];