Skip to content

Commit

Permalink
Added resend confirmation email endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
dhochbaum-dcp committed Dec 11, 2024
1 parent e2303fa commit 48b343a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
29 changes: 28 additions & 1 deletion server/src/subscriber/subscriber.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Controller, Get, Param, Patch, Post, Req, Res } from "@nestjs/common";
import { ConfigService } from "../config/config.service";
import { SubscriberService } from "./subscriber.service";
import { SubscriberService, ValidSubscriptionSet } from "./subscriber.service";
import { Request } from "express";
import validateEmail from "../_utils/validate-email";
import * as Sentry from "@sentry/nestjs";
Expand Down Expand Up @@ -142,4 +142,31 @@ export class SubscriberController {
});
return;
}

@Post("/subscribers/:email/resend-confirmation")
async resendConfirmation(@Param() params, @Res() response) {
const existingUser = await this.subscriberService.findByEmail(params.email);
if (existingUser.code === 404) {
response.status(404).send({
error: "User not found."
})
return;
}

const userId = existingUser['1'].result[params.email].contact.custom_fields[`zap_${this.sendgridEnvironment}_id`];
var subscriptions = <ValidSubscriptionSet>{}

for (const [key, value] of Object.entries(existingUser['1'].result[params.email].contact.custom_fields)) {
if(((key.includes(this.sendgridEnvironment)) && !(key.endsWith("_confirmed") || key.endsWith("_id")))) {
subscriptions[key.split("_")[2]] = value;
}
}

// Send the confirmation email
await this.subscriberService.sendConfirmationEmail(params.email, this.sendgridEnvironment, subscriptions, userId);
response.status(201).send({
message: "Confirmation email sent"
});
return;
}
}
2 changes: 1 addition & 1 deletion server/src/subscriber/subscriber.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const validCustomFieldValues = [0, 1] as const;
export type CustomFieldValueTuple = typeof validCustomFieldValues;
type CustomFieldValue = CustomFieldValueTuple[number];

type ValidSubscriptionSet = Record<CustomFieldName, CustomFieldValue>;
export type ValidSubscriptionSet = Record<CustomFieldName, CustomFieldValue>;

type HttpMethod = 'get' | 'GET' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'delete' | 'DELETE';

Expand Down

0 comments on commit 48b343a

Please sign in to comment.