Skip to content
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

1611 Build endpoint to re-send confirmation email #1621

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading