Skip to content

Commit

Permalink
campaign update
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan-g committed Mar 6, 2024
1 parent a4659a0 commit 44d3f19
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
11 changes: 6 additions & 5 deletions src/features/campaign/campaign.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
40 changes: 20 additions & 20 deletions src/features/schedule/schedule.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,26 +127,26 @@ export class ScheduleService {
}
}
// ERROR [Scheduler] ServerError: Can't send mail - all recipients were rejected: 550 <[email protected]> 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.',
Expand Down

0 comments on commit 44d3f19

Please sign in to comment.