PJob-prisma/server/api/job/update.ts
2024-04-12 18:23:44 +08:00

62 lines
1.4 KiB
TypeScript

import { Prisma, PrismaClient } from "@prisma/client";
const db = new PrismaClient();
async function up(body: any) {
let result;
const data = body;
await db.data
.update({
data: data.data,
where: {
id: data.data.id,
},
select: {
id: true,
},
})
.then(async (res) => {
return await db.job
.update({
data: {
area: data.area,
name: data.name,
pin: data.pin,
place: data.place,
worktime: data.worktime,
updateTime: new Date(),
},
where: {
id: data.id,
},
select: {
id: true,
name: true,
},
})
.then((job) => {
console.log("ok");
result = JSON.stringify({
code: 1,
status: "success",
job: {
id: job.id,
name: job.name,
},
});
})
.catch((reason) => {
result = JSON.stringify({
code: 0,
status: "faild",
resoan: reason,
});
return result;
});
});
return result;
}
export default defineEventHandler(async (event) => {
const body = await readBody(event);
return await up(body);
});