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

57 lines
1.2 KiB
TypeScript
Raw 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
.findUnique({
where: {
id: id,
},
select: {
id: true,
pin: true,
},
})
.then(async (job) => {
return await db.job
.update({
data: {
pin: !job?.pin,
},
where: {
id: job?.id,
},
select: {
pin: true,
},
})
.then((job) => {
return JSON.stringify({
code: 1,
status: "success",
job: {
pin: job.pin,
},
});
})
.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));
});