From dc0b4301a3b9c2e7752607a948249ec18bd14c00 Mon Sep 17 00:00:00 2001 From: G Date: Thu, 23 Nov 2023 14:05:54 +0330 Subject: [PATCH] campaign sms url check --- src/features/campaign/campaign.service.ts | 19 ++++++++++--------- src/features/schedule/schedule.service.ts | 23 +++++++++++------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/features/campaign/campaign.service.ts b/src/features/campaign/campaign.service.ts index 47b12ed9a..a95f1e287 100644 --- a/src/features/campaign/campaign.service.ts +++ b/src/features/campaign/campaign.service.ts @@ -13,6 +13,7 @@ import { NeedService } from '../need/need.service'; import { daysDifference, fetchCampaginCode as fetchCampaignCode, + isUnpayable, persianDay, persianMonthStringFarsi, prepareUrl, @@ -222,9 +223,7 @@ export class CampaignService { const from = process.env.SMS_FROM; const text = `سلام،\nتعداد پیامک شما رو به پایان است. \n با احترام \n SAY \n لغو۱۱`; await this.smsRest.send(to, from, text); - throw new ForbiddenException( - 'We need to charge the sms provider', - ); + throw new ForbiddenException('We need to charge the sms provider'); } const persianMonth = persianMonthStringFarsi(new Date()); @@ -242,6 +241,7 @@ export class CampaignService { ), ); + // 1- loop shuffled users let alreadyReceivedEmailCount = 0; let alreadyReceivedSmsCount = 0; @@ -318,7 +318,7 @@ export class CampaignService { for await (const child of shuffleArray(userChildren)) { if (counter <= 3) { const childUnpaidNeeds = - await this.needService.getFlaskChildUnpaidNeeds(child.id); + (await this.needService.getFlaskChildUnpaidNeeds(child.id)).filter(n => !isUnpayable(n)); if (!childUnpaidNeeds || !childUnpaidNeeds[0]) { // we separately email social workers continue; @@ -342,7 +342,7 @@ export class CampaignService { name: n.name_translations.fa, price: n._cost.toLocaleString(), image: - n.type === NeedTypeEnum.PRODUCT + n.type === NeedTypeEnum.PRODUCT && n.img ? n.img : prepareUrl(n.imageUrl), }; @@ -357,7 +357,9 @@ export class CampaignService { } if (flaskUser.is_email_verified) { - const googleCampaignBuilder = String(`?utm_source=monthly_campaign&utm_medium=${CampaignTypeEnum.EMAIL}&utm_campaign=${CampaignNameEnum.MONTHLY_CAMPAIGNS}&utm_id=${campaignEmailCode}`) + const googleCampaignBuilder = String( + `?utm_source=monthly_campaign&utm_medium=${CampaignTypeEnum.EMAIL}&utm_campaign=${CampaignNameEnum.MONTHLY_CAMPAIGNS}&utm_id=${campaignEmailCode}`, + ); const readyToSignNeeds = ( await this.familyService.getFamilyReadyToSignNeeds(flaskUser.id) @@ -370,7 +372,7 @@ export class CampaignService { context: { myChildren: eligibleChildren, readyToSignNeeds, - googleCampaignBuilder + googleCampaignBuilder, }, }); @@ -378,7 +380,6 @@ export class CampaignService { emailReceivers.push(nestUser); } - if (flaskUser.is_phonenumber_verified) { const to = flaskUser.phone_number; const from = process.env.SMS_FROM; @@ -390,7 +391,7 @@ export class CampaignService { }،\n از آخرین نیازهای کودک شما، ${eligibleChildren[0].sayName }: ${shortNeedUrl} لغو۱۱`; - await this.smsRest.send(to, from, text) + await this.smsRest.send(to, from, text); this.logger.log(`SMS Sent to User: ${nestUser.flaskUserId}`); smsReceivers.push(nestUser); diff --git a/src/features/schedule/schedule.service.ts b/src/features/schedule/schedule.service.ts index 802528b9b..d4ae5efc9 100644 --- a/src/features/schedule/schedule.service.ts +++ b/src/features/schedule/schedule.service.ts @@ -124,20 +124,19 @@ export class ScheduleService { } } - // @Cron('00 13 * * Wend', { - // name: 'MonthlyCampaigns try At 13:00 on Wednesday.', // we try every week and only send to those who did not receive (because their child have no needs, etc.) - // timeZone: 'Asia/Tehran', - // }) - @Timeout(5000) + @Cron('53 13 * * Thu', { + name: 'MonthlyCampaigns try At 13:00 on Wednesday.', // 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 - // } + 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 + } // if (process.env.NODE_ENV === 'production') { - this.logger.debug('Sending user Campaigns at 02:00 PM, only on Sunday'); - await this.campaignService.sendUserMonthlyCampaigns(); + this.logger.debug('Sending user Campaigns at 02:00 PM, only on Sunday'); + await this.campaignService.sendUserMonthlyCampaigns(); // } }