Skip to content

Commit

Permalink
campaign sms url check
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan-g committed Nov 23, 2023
1 parent 263acd4 commit dc0b430
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
19 changes: 10 additions & 9 deletions src/features/campaign/campaign.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { NeedService } from '../need/need.service';
import {
daysDifference,
fetchCampaginCode as fetchCampaignCode,
isUnpayable,
persianDay,
persianMonthStringFarsi,
prepareUrl,
Expand Down Expand Up @@ -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());
Expand All @@ -242,6 +241,7 @@ export class CampaignService {
),
);


// 1- loop shuffled users
let alreadyReceivedEmailCount = 0;
let alreadyReceivedSmsCount = 0;
Expand Down Expand Up @@ -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;
Expand All @@ -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),
};
Expand All @@ -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)
Expand All @@ -370,15 +372,14 @@ export class CampaignService {
context: {
myChildren: eligibleChildren,
readyToSignNeeds,
googleCampaignBuilder
googleCampaignBuilder,
},
});

this.logger.log(`Email Sent to User: ${nestUser.flaskUserId}`);
emailReceivers.push(nestUser);
}


if (flaskUser.is_phonenumber_verified) {
const to = flaskUser.phone_number;
const from = process.env.SMS_FROM;
Expand All @@ -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);
Expand Down
23 changes: 11 additions & 12 deletions src/features/schedule/schedule.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
// }
}

Expand Down

0 comments on commit dc0b430

Please sign in to comment.