feat: update quotation status on expired

This commit is contained in:
Methapon Metanipat 2024-11-07 13:44:49 +07:00
parent 4d2dadbc05
commit 18fb64b9cc
5 changed files with 52 additions and 0 deletions

25
src/services/schedule.ts Normal file
View 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();
}