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.
23 lines
839 B
23 lines
839 B
import { batchOperation } from "#server/service/collection";
|
|
import { getContextUser } from "#server/utils/context";
|
|
import { z } from "zod";
|
|
|
|
const batchSchema = z.object({
|
|
ids: z.array(z.number()).min(1),
|
|
action: z.enum(["move", "delete", "star", "unstar", "archive"]),
|
|
categoryId: z.number().optional(),
|
|
});
|
|
|
|
export default defineWrappedResponseHandler({ auth: "required" }, async (event) => {
|
|
const user = getContextUser(event)!;
|
|
const body = await readBody(event);
|
|
const parsed = batchSchema.safeParse(body);
|
|
if (!parsed.success) return R.error("参数校验失败", parsed.error.issues);
|
|
|
|
try {
|
|
await batchOperation(parsed.data.ids, user.id, parsed.data.action, parsed.data.categoryId);
|
|
return R.success({ affected: parsed.data.ids.length });
|
|
} catch (e: any) {
|
|
return R.error(e.message, null);
|
|
}
|
|
});
|
|
|