You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
603 B
17 lines
603 B
import { createCategory } from "#server/service/collection";
|
|
import { z } from "zod";
|
|
|
|
export default defineWrappedResponseHandler({ auth: "required" }, async (event) => {
|
|
const body = await readBody(event);
|
|
const parsed = z.object({
|
|
name: z.string().min(1),
|
|
icon: z.string().optional(),
|
|
color: z.string().optional(),
|
|
parentId: z.number().optional().nullable(),
|
|
sortOrder: z.number().optional(),
|
|
}).safeParse(body);
|
|
|
|
if (!parsed.success) return R.error("参数校验失败", parsed.error.issues);
|
|
const cat = await createCategory(parsed.data);
|
|
return R.success(cat);
|
|
});
|
|
|