feat: update quotation status on expired
This commit is contained in:
parent
4d2dadbc05
commit
18fb64b9cc
5 changed files with 52 additions and 0 deletions
25
src/services/schedule.ts
Normal file
25
src/services/schedule.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { CronJob } from "cron";
|
||||
|
||||
import prisma from "../db";
|
||||
|
||||
const jobs = [
|
||||
CronJob.from({
|
||||
cronTime: "0 0 0 * * *",
|
||||
runOnInit: true,
|
||||
onTick: async () => {
|
||||
await prisma.quotation
|
||||
.updateMany({
|
||||
where: {
|
||||
dueDate: { lte: new Date() },
|
||||
},
|
||||
data: { quotationStatus: "Expired" },
|
||||
})
|
||||
.then(() => console.log("[INFO]: Update expired quotation status, OK."))
|
||||
.catch((e) => console.error(e));
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
export function initSchedule() {
|
||||
for (const job of jobs) job.start();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue