Skip to content

Commit

Permalink
Merge pull request #1660 from bcgov/hotfix/ALCS-1918
Browse files Browse the repository at this point in the history
Fix empty gov email causing emails to fail and success toast on fail
  • Loading branch information
trslater committed May 7, 2024
2 parents 644275d + ec6143e commit 0ba08ba
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { ServiceNotFoundException } from '@app/common/exceptions/base.exception';
import {
BaseServiceException,
ServiceNotFoundException,
} from '@app/common/exceptions/base.exception';
import {
Body,
Controller,
Expand Down Expand Up @@ -120,11 +123,18 @@ export class NotificationController {
);

if (document) {
await this.notificationSubmissionService.sendAndRecordLTSAPackage(
submission,
document,
user,
);
const emailDidSend =
await this.notificationSubmissionService.sendAndRecordLTSAPackage(
submission,
document,
user,
);

if (!emailDidSend) {
throw new BaseServiceException(
`Failed to send LTSA Package ${fileNumber}`,
);
}
} else {
throw new ServiceNotFoundException(
`Failed to find LTSA Letter on File Number ${fileNumber}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export class NotificationSubmissionService {
submission: NotificationSubmission,
document: NotificationDocument,
user: User,
) {
): Promise<boolean> {
const templateData = await this.generateSrwEmailData(submission, document);

const didSend = await this.emailService.sendEmail({
Expand Down Expand Up @@ -442,6 +442,8 @@ export class NotificationSubmissionService {
NOTIFICATION_STATUS.ALC_RESPONSE_SENT,
);
}

return didSend;
}

private async generateSrwEmailData(
Expand Down Expand Up @@ -470,7 +472,7 @@ export class NotificationSubmissionService {
);

if (localGovernment && localGovernment.emails) {
ccEmails = localGovernment.emails;
ccEmails = localGovernment.emails.filter((email) => email !== '');
}
}

Expand Down
4 changes: 2 additions & 2 deletions services/apps/alcs/src/providers/email/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class EmailService {
parentId?: string;
triggerStatus?: string;
attachments?: Document[];
}) {
}): Promise<boolean> {
const serviceUrl = this.config.get<string>('CHES.URL');
const from = this.config.get<string>('CHES.FROM');
const token = await this.getToken();
Expand Down Expand Up @@ -134,7 +134,7 @@ export class EmailService {
{ to, body, subject, cc, bcc },
'EmailService did not send the email. Set CHES.MODE to production if you need to send an email.',
);
return;
return false;
}
const res = await firstValueFrom(
this.httpService.post<{
Expand Down

0 comments on commit 0ba08ba

Please sign in to comment.