Skip to content

Commit

Permalink
Build out service
Browse files Browse the repository at this point in the history
  • Loading branch information
pratishta committed Dec 2, 2024
1 parent 0f3fa0c commit 82c8614
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions server/src/subscriber/subscriber.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ export class SubscriberController {
async modifySubscriptions(@Req() request: Request, @Param("id") id, @Res() response) {
const email = await this.subscriberService.getUserById(id);
console.log(email);
// Send the confirmation email
await this.subscriberService.sendModifySubscriptionEmail(email, this.sendgridEnvironment, id);

return;
// get id from request
// get email using service
Expand Down
21 changes: 20 additions & 1 deletion server/src/subscriber/subscriber.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,27 @@ export class SubscriberService {
* @param {string} id - The id needed for confirmation
* @returns {object}
*/
async sendModifySubscriptionEmail(email: string, environment: string, subscriptions: ValidSubscriptionSet, id: string) {
async sendModifySubscriptionEmail(email: string, environment: string, id: string) {
console.log(id);
// https://github.com/sendgrid/sendgrid-nodejs/blob/main/docs/use-cases/transactional-templates.md
const msg = {
to: email,
from: '[email protected]', // Your verified sender
templateId: '', //FAKE_TEMPLATE_ID,
dynamicTemplateData: {
"id": id,
"domain": environment === "production" ? "zap.planning.nyc.gov" : "zap-staging.planninglabs.nyc",
// "subscriptions": this.convertSubscriptionsToHandlebars(subscriptions)
}
}
this.mailer.send(msg)
.then((response) => {
return {isError: false, statusCode: response[0].statusCode}
})
.catch((error) => {
console.error(error)
return {isError: true, ...error}
})
}

/**
Expand Down

0 comments on commit 82c8614

Please sign in to comment.