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.
24 lines
674 B
24 lines
674 B
import { delCache } from "#server/utils/context";
|
|
import { z } from "zod";
|
|
import { createTool } from "../../service/tool";
|
|
|
|
const createSchema = z.object({
|
|
name: z.string().min(1).max(50),
|
|
slug: z.string().min(1).max(50),
|
|
icon: z.string().max(100).optional(),
|
|
sortOrder: z.number().int().optional(),
|
|
});
|
|
|
|
export default defineWrappedResponseHandler(async (event) => {
|
|
const body = await readBody(event);
|
|
const parsed = createSchema.safeParse(body);
|
|
|
|
if (!parsed.success) {
|
|
return R.throwError(422, "Validation failed", parsed.error.issues);
|
|
}
|
|
|
|
const tool = await createTool(parsed.data);
|
|
await delCache("tools:list");
|
|
|
|
return R.success(tool);
|
|
});
|
|
|