From a01820815d6848d2b4c4052ecc184081c97c7bdf Mon Sep 17 00:00:00 2001 From: Gurveer Sohal Date: Sat, 23 Dec 2023 01:19:30 -0700 Subject: [PATCH] fix --- backend/src/controllers/cron/email.ts | 12 +++++++++++- backend/src/services/cron/email.ts | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/backend/src/controllers/cron/email.ts b/backend/src/controllers/cron/email.ts index 772aa443..5d9a12de 100644 --- a/backend/src/controllers/cron/email.ts +++ b/backend/src/controllers/cron/email.ts @@ -31,7 +31,12 @@ export const getEmail = async (req: Request, res: Response) => { }) const utcExpr = cron?.expression.split(" ") - const days = utcExpr[utcExpr.length-1].split(",") + let days = utcExpr[utcExpr.length-1] + if (days.length > 3) { + days = days.split(",") + } else { + days = [days] + } const minutes = parseInt(utcExpr[1]) const hours = parseInt(utcExpr[2]) @@ -42,6 +47,11 @@ export const getEmail = async (req: Request, res: Response) => { } const tuple = convertToMT(minutes, hours, "MON") let cronExpression = `0 ${tuple[0]} ${tuple[1]} * * ` + if (setDays.length > 1) { + cronExpression += setDays.join(",") + } else { + cronExpression += setDays[0] + } return res.status(200).json({ cron : { ...cron, expression: cronExpression diff --git a/backend/src/services/cron/email.ts b/backend/src/services/cron/email.ts index 52f4cb0b..e75537a2 100644 --- a/backend/src/services/cron/email.ts +++ b/backend/src/services/cron/email.ts @@ -61,7 +61,7 @@ export const convertToMT = (minute: number, hour: number, day: string) : [number } const newHour = (hour+increment+24)%24 - if (newHour < hour) day = days[day] + if (newHour > hour) day = days[day] return [minute, newHour, day] } \ No newline at end of file