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: { quotationStatus: "Issued", 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(); }