From c7fae98516cda62e00900904da46136cd2495d55 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 5 Mar 2025 17:22:38 +0700 Subject: [PATCH] feat: clear expired notification date --- src/services/schedule.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/services/schedule.ts b/src/services/schedule.ts index df15f1f..bd12bf8 100644 --- a/src/services/schedule.ts +++ b/src/services/schedule.ts @@ -1,3 +1,4 @@ +import dayjs from "dayjs"; import { CronJob } from "cron"; import prisma from "../db"; @@ -25,6 +26,18 @@ const jobs = [ .catch((e) => console.error("[ERR]: Update expired quotation status, FAILED.", e)); }, }), + CronJob.from({ + cronTime: "0 0 0 * * *", + runOnInit: true, + onTick: async () => { + await prisma.notification + .deleteMany({ + where: { createdAt: { lte: dayjs().subtract(1, "month").toDate() } }, + }) + .then(() => console.log("[INFO]: Delete expired notification, OK.")) + .catch((e) => console.error("[ERR]: Update expired quotation status, FAILED.", e)); + }, + }), ]; export function initSchedule() {