forked from Code-4-Community/scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 0
[SSF-180, 189, 193] - Automated Emails Implementation #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
swarkewalia
wants to merge
15
commits into
main
Choose a base branch
from
sk/SSF-180-automated-emails
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e1fd3af
automated email updates
swarkewalia de35710
fix donation tests
swarkewalia af27eb6
automated email user updates
swarkewalia d401ac5
merge conflicts
swarkewalia 88656ed
Merge branch 'main' into sk/SSF-189-automated-email-user-updates
swarkewalia ec84028
Merge branch 'main' into sk/SSF-189-automated-email-user-updates
swarkewalia a3e6265
Merged main
dburkhart07 98a90b8
comments
dburkhart07 a5d820a
Comments
dburkhart07 a3829d1
Comments
dburkhart07 e9db864
Combined both email prs into one
dburkhart07 23765b8
Fixed formatting and added tests for volunteer assignment email
dburkhart07 0c09e2a
fixed logit to always process the donation, even if the email send fails
dburkhart07 a6c8e3b
Added Resubmit Previous frontend, as well as used theme.ts colors thr…
dburkhart07 f4317fe
comments
dburkhart07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { | ||
| BadRequestException, | ||
| Injectable, | ||
| InternalServerErrorException, | ||
| Logger, | ||
| NotFoundException, | ||
| } from '@nestjs/common'; | ||
|
|
@@ -18,11 +19,12 @@ import { DonationItemsService } from '../donationItems/donationItems.service'; | |
| import { ReplaceDonationItemsDto } from '../donationItems/dtos/create-donation-items.dto'; | ||
| import { DonationItem } from '../donationItems/donationItems.entity'; | ||
| import { Allocation } from '../allocations/allocations.entity'; | ||
| import { EmailsService } from '../emails/email.service'; | ||
| import { emailTemplates } from '../emails/emailTemplates'; | ||
|
|
||
| @Injectable() | ||
| export class DonationService { | ||
| private readonly logger = new Logger(DonationService.name); | ||
|
|
||
| constructor( | ||
| @InjectRepository(Donation) private repo: Repository<Donation>, | ||
| @InjectRepository(Allocation) | ||
|
|
@@ -33,6 +35,7 @@ export class DonationService { | |
| private manufacturerRepo: Repository<FoodManufacturer>, | ||
| private donationItemsService: DonationItemsService, | ||
| @InjectDataSource() private dataSource: DataSource, | ||
| private emailsService: EmailsService, | ||
| ) {} | ||
|
|
||
| async findOne(donationId: number): Promise<Donation> { | ||
|
|
@@ -50,7 +53,10 @@ export class DonationService { | |
|
|
||
| async getAll(): Promise<Donation[]> { | ||
| return this.repo.find({ | ||
| relations: ['foodManufacturer'], | ||
| relations: [ | ||
| 'foodManufacturer', | ||
| 'foodManufacturer.foodManufacturerRepresentative', | ||
| ], | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -206,13 +212,24 @@ export class DonationService { | |
| break; | ||
| } | ||
|
|
||
| this.logger.log(`Placeholder for sending automated email`); | ||
|
|
||
| /** | ||
| * IMPORTANT: future logic below should only proceed if the email is successfully sent | ||
| */ | ||
| const emailSent = true; | ||
| if (!emailSent) continue; | ||
| let message = null; | ||
| try { | ||
| message = emailTemplates.fmRecurringDonationReminder({ | ||
| fmName: donation.foodManufacturer.foodManufacturerName, | ||
| resubmitDonationId: donation.donationId, | ||
| }); | ||
|
|
||
| await this.emailsService.sendEmails( | ||
| [donation.foodManufacturer.foodManufacturerRepresentative.email], | ||
| message.subject, | ||
| message.bodyHTML, | ||
| ); | ||
| } catch { | ||
| this.logger.warn( | ||
| `Automated email failed to send. Skipping recurrence update for donation id ${donation.donationId}`, | ||
| ); | ||
| continue; | ||
| } | ||
|
|
||
| dates.splice(i, 1); | ||
| i--; | ||
|
|
@@ -228,11 +245,22 @@ export class DonationService { | |
|
|
||
| // cascading recalculation of next dates when replacement dates are also expired | ||
| while (nextDate.getTime() <= today.getTime() && occurrences > 0) { | ||
| this.logger.log( | ||
| `Placeholder for sending automated email for replacement date`, | ||
| ); | ||
| const cascadeEmailSent = true; | ||
| if (!cascadeEmailSent) break; | ||
| try { | ||
|
dburkhart07 marked this conversation as resolved.
|
||
| await this.emailsService.sendEmails( | ||
| [ | ||
| donation.foodManufacturer.foodManufacturerRepresentative | ||
| .email, | ||
| ], | ||
| message.subject, | ||
| message.bodyHTML, | ||
| ); | ||
| } catch { | ||
| // Early escape to prevent getting stuck in while loop | ||
| this.logger.warn( | ||
| `Cascading recalculation of next dates failed for donation id ${donation.donationId}, exiting early`, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we mention the automated email failure here? |
||
| ); | ||
| break; | ||
| } | ||
|
|
||
| occurrences -= 1; | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.