Skip to content

Commit

Permalink
fix: send all lottery emails to siteemail
Browse files Browse the repository at this point in the history
  • Loading branch information
ludtkemorgan committed Dec 22, 2024
1 parent 734ed4c commit 55841ce
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 31 deletions.
1 change: 1 addition & 0 deletions api/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ ASSET_FILE_SERVICE=
ASSET_FS_CONFIG_s3_REGION=
ASSET_FS_CONFIG_s3_BUCKET=
ASSET_FS_CONFIG_s3_URL_FORMAT=public
SITE_EMAIL=

# aws api keys, used for ses
AWS_ACCESS_KEY_ID=
Expand Down
2 changes: 1 addition & 1 deletion api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function bootstrap() {
// In local development use the built in logger for better readability
logger:
process.env.NODE_ENV === 'development'
? ['error', 'warn', 'log', 'debug']
? ['log']
: WinstonModule.createLogger({
instance: instance,
}),
Expand Down
82 changes: 52 additions & 30 deletions api/src/services/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,16 @@ export class EmailService {
html: string;
text?: string;
},
useCase?: string,
useCase: string,
includeJurisdictionEmail = false,
) {
const siteEmail = this.configService.get('SITE_EMAIL');
const emailsToSendTo =
includeJurisdictionEmail && siteEmail
? [siteEmail, ...mailOptions.emails]
: mailOptions.emails;
const MAX_EMAIL_TO_SEND_IN_BULK = 50;
const emailsChunked = mailOptions.emails.reduce((all, one, i) => {
const emailsChunked = emailsToSendTo.reduce((all, one, i) => {
const chunk = Math.floor(i / MAX_EMAIL_TO_SEND_IN_BULK);
all[chunk] = [].concat(all[chunk] || [], one);
return all;
Expand Down Expand Up @@ -564,14 +570,17 @@ export class EmailService {
`Sending listing approved email for listing ${listingInfo.name} to ${emails.length} emails`,
);

await this.sendBulkSES({
emails: emails,
subject: this.polyglot.t('listingApproved.header'),
html: this.template('listing-approved')({
appOptions: { listingName: listingInfo.name },
listingUrl: `${publicUrl}/listing/${listingInfo.id}`,
}),
});
await this.sendBulkSES(
{
emails: emails,
subject: this.polyglot.t('listingApproved.header'),
html: this.template('listing-approved')({
appOptions: { listingName: listingInfo.name },
listingUrl: `${publicUrl}/listing/${listingInfo.id}`,
}),
},
'listingApproved',
);
}

public async listingOpportunity(listing: Listing) {
Expand Down Expand Up @@ -727,20 +736,28 @@ export class EmailService {
emails: string[],
appUrl: string,
) {
const jurisdiction = await this.getJurisdiction([
{ id: listingInfo.juris },
]);
void (await this.loadTranslations(jurisdiction));
this.logger.log(
`Sending lottery released email for listing ${listingInfo.name} to ${emails.length} emails`,
);
await this.sendBulkSES({
emails: emails,
subject: this.polyglot.t('lotteryReleased.header', {
listingName: listingInfo.name,
}),
html: this.template('lottery-released')({
appOptions: { listingName: listingInfo.name },
appUrl: appUrl,
listingUrl: `${appUrl}/listings/${listingInfo.id}`,
}),
});
await this.sendBulkSES(
{
emails: emails,
subject: this.polyglot.t('lotteryReleased.header', {
listingName: listingInfo.name,
}),
html: this.template('lottery-released')({
appOptions: { listingName: listingInfo.name },
appUrl: appUrl,
listingUrl: `${appUrl}/listings/${listingInfo.id}`,
}),
},
'lotteryReleased',
true,
);
}

public async lotteryPublishedAdmin(
Expand All @@ -755,15 +772,19 @@ export class EmailService {
this.logger.log(
`Sending lottery published admin email for listing ${listingInfo.name} to ${emails.length} emails`,
);
await this.sendBulkSES({
emails: emails,
subject: this.polyglot.t('lotteryPublished.header', {
listingName: listingInfo.name,
}),
html: this.template('lottery-published-admin')({
appOptions: { listingName: listingInfo.name, appUrl: appUrl },
}),
});
await this.sendBulkSES(
{
emails: emails,
subject: this.polyglot.t('lotteryPublished.header', {
listingName: listingInfo.name,
}),
html: this.template('lottery-published-admin')({
appOptions: { listingName: listingInfo.name, appUrl: appUrl },
}),
},
'lotteryPublishedAdmin',
true,
);
}

/**
Expand Down Expand Up @@ -802,6 +823,7 @@ export class EmailService {
}),
},
'lotteryPublishedApplicant',
true,
);
}
}
Expand Down

0 comments on commit 55841ce

Please sign in to comment.