Skip to content

Commit b16c132

Browse files
committed
add first name to membership provisioned email
1 parent c3cd95c commit b16c132

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

src/api/functions/ses.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export function generateMembershipEmailCommand(
1414
recipientEmail: string,
1515
senderEmail: string,
1616
attachmentBuffer: ArrayBufferLike,
17+
firstName?: string,
1718
): SendRawEmailCommand {
1819
const encodedAttachment = encode(attachmentBuffer as ArrayBuffer);
1920
const boundary = "----BoundaryForEmail";
@@ -81,7 +82,7 @@ export function generateMembershipEmailCommand(
8182
<img src="https://static.acm.illinois.edu/banner-blue.png" style="height: 100px; width: 210px; align-self: center;"/>
8283
<br />
8384
<div class="wrap">
84-
<h2 style="text-align: center;">Welcome</h2>
85+
<h2 style="text-align: center;">Welcome${firstName && `, ${firstName}`}!</h2>
8586
<p>
8687
Thank you for becoming a member of ACM @ UIUC! Attached is your membership pass.
8788
You can add it to your Apple or Google Wallet for easy access.

src/api/routes/membership.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,30 @@ const membershipPlugin: FastifyPluginAsync = async (fastify, _options) => {
360360
event.data.object.metadata.initiator === "purchase-membership"
361361
) {
362362
const customerEmail = event.data.object.customer_email;
363+
const firstName = event.data.object.custom_fields.filter(
364+
(x) => x.key === "firstName",
365+
)[0].text?.value;
366+
const lastName = event.data.object.custom_fields.filter(
367+
(x) => x.key === "lastName",
368+
)[0].text?.value;
363369
if (!customerEmail) {
364370
request.log.info("No customer email found.");
365371
return reply
366372
.code(200)
367373
.send({ handled: false, requestId: request.id });
368374
}
375+
if (!firstName) {
376+
request.log.info("First name not found.");
377+
return reply
378+
.code(200)
379+
.send({ handled: false, requestId: request.id });
380+
}
381+
if (!lastName) {
382+
request.log.info("Last name not found.");
383+
return reply
384+
.code(200)
385+
.send({ handled: false, requestId: request.id });
386+
}
369387
const sqsPayload: SQSPayload<AvailableSQSFunctions.ProvisionNewMember> =
370388
{
371389
function: AvailableSQSFunctions.ProvisionNewMember,
@@ -375,6 +393,8 @@ const membershipPlugin: FastifyPluginAsync = async (fastify, _options) => {
375393
},
376394
payload: {
377395
email: customerEmail,
396+
firstName,
397+
lastName,
378398
},
379399
};
380400
if (!fastify.sqsClient) {

src/api/sqs/handlers/emailMembershipPassHandler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { SESClient } from "@aws-sdk/client-ses";
1414
export const emailMembershipPassHandler: SQSHandlerFunction<
1515
AvailableSQSFunctions.EmailMembershipPass
1616
> = async (payload, metadata, logger) => {
17-
const email = payload.email;
17+
const { email, firstName } = payload;
1818
const commonConfig = { region: genericConfig.AwsRegion };
1919
const clients = await getAuthorizedClients(logger, commonConfig);
2020
const entraIdToken = await getEntraIdToken({
@@ -37,6 +37,7 @@ export const emailMembershipPassHandler: SQSHandlerFunction<
3737
email,
3838
`membership@${environmentConfig[runEnvironment].EmailDomain}`,
3939
pkpass.buffer,
40+
firstName,
4041
);
4142
if (runEnvironment === "dev" && email === "[email protected]") {
4243
return;

src/api/sqs/handlers/provisionNewMember.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { setKey } from "api/functions/redisCache.js";
1717
export const provisionNewMemberHandler: SQSHandlerFunction<
1818
AvailableSQSFunctions.ProvisionNewMember
1919
> = async (payload, metadata, logger) => {
20-
const { email } = payload;
20+
const { email, firstName, lastName } = payload;
2121
const commonConfig = { region: genericConfig.AwsRegion };
2222
const clients = await getAuthorizedClients(logger, commonConfig);
2323
const entraToken = await getEntraIdToken({

src/common/types/sqsMessage.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ export const sqsPayloadSchemas = {
3838
),
3939
[AvailableSQSFunctions.EmailMembershipPass]: createSQSSchema(
4040
AvailableSQSFunctions.EmailMembershipPass,
41-
z.object({ email: z.string().email() })
41+
z.object({ email: z.email(), firstName: z.optional(z.string().min(1)) })
4242
),
4343
[AvailableSQSFunctions.ProvisionNewMember]: createSQSSchema(
4444
AvailableSQSFunctions.ProvisionNewMember,
45-
z.object({ email: z.string().email() })
45+
z.object({ email: z.email(), firstName: z.string().min(1), lastName: z.string().min(1) })
4646
),
4747
[AvailableSQSFunctions.SendSaleEmail]: createSQSSchema(
4848
AvailableSQSFunctions.SendSaleEmail,
4949
z.object({
50-
email: z.string().email(),
50+
email: z.email(),
5151
qrCodeContent: z.string().min(1),
5252
itemName: z.string().min(1),
5353
quantity: z.number().min(1),
@@ -58,8 +58,8 @@ export const sqsPayloadSchemas = {
5858
),
5959
[AvailableSQSFunctions.EmailNotifications]: createSQSSchema(
6060
AvailableSQSFunctions.EmailNotifications, z.object({
61-
to: z.array(z.string().email()).min(1),
62-
cc: z.optional(z.array(z.string().email()).min(1)),
61+
to: z.array(z.email()).min(1),
62+
cc: z.optional(z.array(z.email()).min(1)),
6363
bcc: z.optional(z.array(z.string().email()).min(1)),
6464
subject: z.string().min(1),
6565
content: z.string().min(1),

0 commit comments

Comments
 (0)