index.post.mjs
1.56 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { e as eventHandler, r as readBody, i as createMockDeviceType } from '../../../nitro/nitro.mjs';
import { z } from 'zod';
import { D as DEVICE_TYPE_CATEGORY_VALUES } from '../../../_/device-type.mjs';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'node:fs';
import 'node:path';
import 'node:crypto';
import 'node:url';
import '@iconify/utils';
import 'consola';
const payloadSchema = z.object({
name: z.string().trim().min(1),
model: z.string().trim().min(1),
category: z.enum(DEVICE_TYPE_CATEGORY_VALUES),
lengthMm: z.number().positive(),
widthMm: z.number().positive(),
heightMm: z.number().positive(),
weightKg: z.number().positive(),
hasBattery: z.boolean(),
batterySpec: z.string().trim().optional(),
description: z.string().trim().optional()
}).superRefine((value, ctx) => {
if (value.hasBattery && (!value.batterySpec || value.batterySpec.trim().length === 0)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["batterySpec"],
message: "\u542B\u7535\u6C60\u8BBE\u5907\u5FC5\u987B\u586B\u5199\u7535\u6C60\u89C4\u683C\u3002"
});
}
});
const index_post = eventHandler(async (event) => {
const body = await readBody(event);
const parsed = payloadSchema.safeParse(body);
if (!parsed.success) {
return {
success: false,
errorCode: "VALIDATION_ERROR",
message: "\u8BBE\u5907\u7C7B\u578B\u53C2\u6570\u4E0D\u6B63\u786E\u3002"
};
}
return createMockDeviceType(parsed.data);
});
export { index_post as default };
//# sourceMappingURL=index.post.mjs.map