Skip to content

SSF-188 Automated Order Lifecycle Emails#162

Open
Juwang110 wants to merge 31 commits into
mainfrom
jw/ssf-188-automated-order-lifecycle-emails
Open

SSF-188 Automated Order Lifecycle Emails#162
Juwang110 wants to merge 31 commits into
mainfrom
jw/ssf-188-automated-order-lifecycle-emails

Conversation

@Juwang110
Copy link
Copy Markdown

@Juwang110 Juwang110 commented Apr 21, 2026

ℹ️ Issue

Closes https://vidushimisra.atlassian.net/jira/software/projects/SSF/boards/1?jql=assignee%20%3D%20712020%3A10ef9ad9-e290-4bbd-8c4b-cb215e8d449a&selectedIssue=SSF-188

📝 Description

Email templates for:

  • Pantry’s Food Request has a matched order
  • FM’s donation has been matched to an order
  • Food Request closed

✔️ Verification

BEFORE TESTING: Add 2 new environment variables:

AWS_SES_SENDER_EMAIL (set this to one of your emails, this will be the address that sends the emails for you to verify)
SEND_AUTOMATED_EMAILS (switch this to true to turn on Cognito account creation and email sending permissions)
Add your email that you put in the AWS_SES_SENDER_EMAIL into the following AWS SES Identities: https://us-east-2.console.aws.amazon.com/ses/home?region=us-east-2#/identities

Tested each workflow to ensure the proper sender, subject, message, attachments were all there.

Same testing as #127

I verified it worked via new tests and testing email functionality with postman.

🏕️ (Optional) Future Work / Notes

For food request closed the functionality is as follows (per Yurika):

For manual close (closeRequest endpoint):

  • coordinator = volunteer who hit endpoing with req.user.id

For auto close (updateRequestStatus):

  • coordinator = the last volunteer who touched an associated order of that request that was most recently delivered.

Copy link
Copy Markdown
Collaborator

@sam-schu sam-schu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sending the emails:

  1. For consistency with our other emails, can we send the emails outside of the transaction, so the order is still created even if an email fails to send? (We do plan to add better handling for failed emails across the board)
  2. Can we try sending both emails, even if one fails?

Comment thread apps/backend/src/emails/emailTemplates.ts Outdated
@Juwang110 Juwang110 requested a review from sam-schu April 29, 2026 17:24
Copy link
Copy Markdown
Collaborator

@sam-schu sam-schu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed the emails are properly sent! A few comments on the contents:

  • Can we link the text "log into the platform" rather than including the link at the end of the email?
  • Can we turn the coordinator email into a link?
  • For the manufacturer email, can we make sure the different address lines appear on different lines in the email body, and add a comma between city and state?
814 Cedar Hollow Way
[Unit 1]
Madison, WI 53711
[US]

@Juwang110 Juwang110 requested a review from sam-schu May 4, 2026 19:44
Comment thread apps/backend/src/orders/order.service.ts Outdated
Comment thread apps/backend/src/emails/emailTemplates.ts Outdated
Comment thread apps/backend/src/orders/order.service.ts Outdated
Comment thread apps/backend/src/orders/order.service.ts Outdated
Comment thread apps/backend/src/orders/order.service.spec.ts Outdated
Comment thread apps/backend/src/orders/order.service.spec.ts Outdated
Comment thread apps/backend/src/orders/order.service.spec.ts Outdated
Comment thread apps/backend/src/orders/order.service.spec.ts Outdated
Comment thread apps/backend/src/orders/order.service.spec.ts Outdated
Comment thread apps/backend/src/orders/order.service.spec.ts
@dburkhart07 dburkhart07 removed the request for review from swarkewalia May 5, 2026 05:33
@Juwang110 Juwang110 requested a review from dburkhart07 May 6, 2026 21:02
Comment thread apps/backend/src/emails/emailTemplates.ts Outdated
Comment thread apps/backend/src/emails/emailTemplates.ts Outdated
Comment thread apps/backend/src/foodRequests/request.service.ts Outdated
Comment thread apps/backend/src/orders/order.service.ts Outdated
Comment thread apps/backend/src/orders/order.service.ts Outdated
@Juwang110 Juwang110 requested a review from sam-schu May 7, 2026 20:32
Copy link
Copy Markdown

@dburkhart07 dburkhart07 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry this is so many comments lol. should hopefully be good after this <3

Comment thread apps/backend/src/foodRequests/request.service.ts Outdated
Comment thread apps/backend/src/foodRequests/request.service.spec.ts Outdated
Comment thread apps/backend/src/foodRequests/request.service.spec.ts
Comment thread apps/backend/src/foodRequests/request.service.spec.ts
Comment thread apps/backend/src/foodRequests/request.service.spec.ts
Comment thread apps/backend/src/orders/order.service.spec.ts
Comment thread apps/backend/src/orders/order.service.ts
Comment thread apps/backend/src/orders/order.service.ts
Comment thread apps/backend/src/orders/order.service.ts
Comment thread apps/backend/src/orders/order.service.ts
Comment thread apps/backend/src/emails/emailTemplates.ts
Comment thread apps/backend/src/emails/emailTemplates.ts Outdated
Comment thread apps/backend/src/emails/emailTemplates.ts
Comment thread apps/backend/src/foodRequests/request.service.ts
Comment thread apps/backend/src/foodRequests/request.service.ts
Comment thread apps/backend/src/emails/emailTemplates.ts Outdated
Comment thread apps/backend/src/foodRequests/request.service.ts Outdated
Comment thread apps/backend/src/orders/order.service.ts
Comment thread apps/backend/src/orders/order.service.ts Outdated
Comment thread apps/backend/src/orders/order.service.ts Outdated
@Juwang110 Juwang110 requested a review from sam-schu May 26, 2026 22:56
@dburkhart07 dburkhart07 self-assigned this May 27, 2026
@Juwang110 Juwang110 requested a review from dburkhart07 May 27, 2026 15:00
Copy link
Copy Markdown

@dburkhart07 dburkhart07 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple last things.

IMPORTANT: Wait for Yurika's clarification before making some changes to updateRequestStatus

Comment thread apps/backend/src/orders/order.service.spec.ts
Comment thread apps/backend/src/orders/order.service.spec.ts
Comment thread apps/backend/src/orders/order.service.spec.ts
Comment thread apps/backend/src/orders/order.service.spec.ts
});

describe('createOrder', () => {
describe('create', () => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add tests for Manufacturer has no donations path


const orders = request.orders || [];

if (!orders.length) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check here really doesn't make sense to me. This would only happen in the case where a request is closed, but has no orders which should be impossible. I think in the case where we try to update a request that has no orders, we should honestly through a bad request exception saying that we can't update a request with no orders yet. Can we add a test for this too?

if (request.status !== FoodRequestStatus.CLOSED) {
const wasAlreadyClosed = request.status === FoodRequestStatus.CLOSED;

if (!wasAlreadyClosed) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here, this logic doesn't really make sense to me. I think if the request is already closed, then we should just throw a BadRequestException and return.

We should then remove the !wasAlreadyClosed check in the conditional, and set the status in the if statement, save the request, and then try catch with the email sending.

});
}

async updateRequestStatus(requestId: number): Promise<void> {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yurika-Kan are we even using this function anymore? its not currently used anywhere in our code.

@@ -767,11 +882,53 @@ describe('RequestsService', () => {
});

it('should not reopen a closed request when updateRequestStatus is called', async () => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending Yurika's clarification, I think we can probably delete this test. Regardless, if we do keep it, this logic should be tested for in the updateRequestStatus and should not be needed here.

@Juwang110 Juwang110 requested a review from Yurika-Kan May 28, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants