Your Name 2561c66cb8
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
feat: update workflow categories and admin notifications
2026-05-07 19:31:14 +08:00

64 lines
1.5 KiB
TypeScript

import { and, eq } from "drizzle-orm";
import { z } from "zod";
import { db } from "@/lib/db";
import { dingTalkNotificationTask } from "@/lib/db/schema";
import { ChatSDKError } from "@/lib/errors";
import { requireAdmin } from "@/lib/middleware/admin";
const paramsSchema = z.object({
id: z.string().uuid("通知任务 ID 不合法"),
});
export async function DELETE(
_request: Request,
context: { params: Promise<{ id: string }> },
) {
try {
await requireAdmin();
const params = paramsSchema.parse(await context.params);
const [task] = await db
.update(dingTalkNotificationTask)
.set({
status: "cancelled",
cancelledAt: new Date(),
updatedAt: new Date(),
})
.where(
and(
eq(dingTalkNotificationTask.id, params.id),
eq(dingTalkNotificationTask.status, "pending"),
),
)
.returning();
if (!task) {
return Response.json(
{ success: false, error: "该任务不存在,或已无法取消" },
{ status: 409 },
);
}
return Response.json({
success: true,
task,
});
} catch (error) {
if (error instanceof ChatSDKError) {
return error.toResponse();
}
if (error instanceof z.ZodError) {
return Response.json(
{ success: false, error: error.issues[0]?.message || "参数校验失败" },
{ status: 400 },
);
}
return Response.json(
{ success: false, error: "取消钉钉通知任务失败" },
{ status: 500 },
);
}
}