PJob-prisma/server/api/job/delete.ts

47 lines
1019 B
TypeScript
Raw Permalink Normal View History

2024-04-12 10:23:44 +00:00
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));
});