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.
 
 
 
 

25 lines
834 B

import { delCache } from "#server/utils/context";
import { z } from "zod";
import { validate } from "#server/utils/validation";
import { createCategory } from "../../service/category";
const createSchema = z.object({
name: z.string().min(1, "名称不能为空").max(100, "名称不能超过 100 字"),
slug: z
.string()
.min(1, "标识不能为空")
.max(100)
.regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "标识只能包含小写字母、数字和连字符"),
parentId: z.string().nullable().optional(),
sortOrder: z.number().int().optional(),
});
export default defineWrappedResponseHandler(async (event) => {
const body = await readBody(event);
const data = validate(createSchema, body);
const category = await createCategory(data);
await delCache("categories:tree");
return R.success(category);
});