From 44d3f19beac210ea0170b731f76d6eaf1f12512f Mon Sep 17 00:00:00 2001 From: G Date: Wed, 6 Mar 2024 23:35:17 +0330 Subject: [PATCH] campaign update --- src/features/campaign/campaign.service.ts | 11 ++++--- src/features/schedule/schedule.service.ts | 40 +++++++++++------------ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/features/campaign/campaign.service.ts b/src/features/campaign/campaign.service.ts index f6212359a..1856f485f 100644 --- a/src/features/campaign/campaign.service.ts +++ b/src/features/campaign/campaign.service.ts @@ -11,12 +11,13 @@ import { ServerError } from 'src/filters/server-exception.filter'; import { ChildrenService } from '../children/children.service'; import { NeedService } from '../need/need.service'; import { - fetchCampaginCode as fetchCampaignCode, isUnpayable, + fetchCampaignCode, persianMonthStringFarsi, prepareUrl, removeDuplicates, shuffleArray, + persianMonth, } from 'src/utils/helpers'; import { CampaignNameEnum, @@ -301,11 +302,11 @@ export class CampaignService { } // 0 -setup - const persianMonth = persianMonthStringFarsi(new Date()); - if (!persianMonth) { + const persianStringMonth = persianMonthStringFarsi(new Date()); + if (!persianStringMonth) { throw new ServerError('We need the month string'); } - const tittle = `نیازهای ${persianMonth} ماه کودکان شما`; + const tittle = `نیازهای ${persianStringMonth} ماه کودکان شما`; const flaskUsers = await this.userService.getFlaskUsers(); const shuffledUsers = shuffleArray(flaskUsers); @@ -468,7 +469,7 @@ export class CampaignService { try { await this.mailerService.sendMail({ to: flaskUser.emailAddress, - subject: `نیازهای ${persianMonth} ماه کودکان شما`, + subject: `نیازهای ${persianStringMonth} ماه کودکان شما`, template: './monthlyCampaign', // `.hbs` extension is appended automatically context: { myChildren: eligibleChildren, diff --git a/src/features/schedule/schedule.service.ts b/src/features/schedule/schedule.service.ts index 9b038b619..44bfa5d6c 100644 --- a/src/features/schedule/schedule.service.ts +++ b/src/features/schedule/schedule.service.ts @@ -127,26 +127,26 @@ export class ScheduleService { } } // ERROR [Scheduler] ServerError: Can't send mail - all recipients were rejected: 550 No such user here - // @Cron(' 00 00 13 * * Thu', { - // name: 'MonthlyCampaigns try At 13:00 on Thursdays.', // we try every week and only send to those who did not receive (because their child have no needs, etc.) - // timeZone: 'Asia/Tehran', - // }) - // async handleSummaryMailCron() { - // const farsiDay = persianDay(new Date()); - // if (farsiDay > 20) { - // this.logger.warn( - // `We are near the end of this month let's skip one more week`, - // ); - // return; - // } - // // ############## BE CAREFUL ################# - // if (process.env.NODE_ENV === 'production') { - // this.logger.debug( - // 'Sending user Campaigns at 01:00 PM, only on Thursdays', - // ); - // await this.campaignService.sendUserMonthlyCampaigns(); - // } - // } + @Cron(' 00 00 13 * * Thu', { + name: 'MonthlyCampaigns try At 13:00 on Thursdays.', // we try every week and only send to those who did not receive (because their child have no needs, etc.) + timeZone: 'Asia/Tehran', + }) + async handleSummaryMailCron() { + const farsiDay = persianDay(new Date()); + if (farsiDay > 20) { + this.logger.warn( + `We are near the end of this month let's skip one more week`, + ); + return; + } + // ############## BE CAREFUL ################# + if (process.env.NODE_ENV === 'production') { + this.logger.debug( + 'Sending user Campaigns at 01:00 PM, only on Thursdays', + ); + await this.campaignService.sendUserMonthlyCampaigns(); + } + } @Cron('30 8 * * Sat', { name: 'Reminders At 08:30 on Saturday.',