import { PrismaClient } from "@prisma/client"; const db = new PrismaClient(); async function del(id: number) { return await db.job .delete({ where: { id: id, }, select: { dataId: true, }, }) .then(async (job) => { return await db.data .delete({ where: { id: !job.dataId ? 1 : job.dataId, }, }) .then(() => { return JSON.stringify({ code: 1, status: "success", }); }) .catch((err) => { return JSON.stringify({ code: 0, status: "failed", reason: err, }); }); }) .catch((err) => { return JSON.stringify({ code: 0, status: "failed", reason: err, }); }); } export default defineEventHandler(async (event) => { const body = await readBody(event); return await del(Number(body.id)); });