Skip to content

Commit 17c249f

Browse files
committed
updates
1 parent 62c8ca8 commit 17c249f

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

src/api/routes/roomRequests.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ import {
2323
QueryCommand,
2424
TransactWriteItemsCommand,
2525
} from "@aws-sdk/client-dynamodb";
26-
import { genericConfig } from "common/config.js";
26+
import { genericConfig, notificationRecipients } from "common/config.js";
2727
import { marshall, unmarshall } from "@aws-sdk/util-dynamodb";
2828
import { z } from "zod";
29+
import { AvailableSQSFunctions, SQSPayload } from "common/types/sqsMessage.js";
30+
import { SendMessageCommand, SQSClient } from "@aws-sdk/client-sqs";
2931

3032
const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
3133
await fastify.register(rateLimiter, {
@@ -241,6 +243,38 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
241243
id: requestId,
242244
status: RoomRequestStatus.CREATED,
243245
});
246+
const sqsPayload: SQSPayload<AvailableSQSFunctions.EmailNotifications> = {
247+
function: AvailableSQSFunctions.EmailNotifications,
248+
metadata: {
249+
initiator: request.username,
250+
reqId: request.id,
251+
},
252+
payload: {
253+
to: [notificationRecipients[fastify.runEnvironment].OfficerBoard],
254+
subject: "A new room request has been created",
255+
content: `${request.username} created a room reservation request. Please log into the ACM management portal for more information.\n\n\nACM @ UIUC Core`,
256+
},
257+
};
258+
if (!fastify.sqsClient) {
259+
fastify.sqsClient = new SQSClient({
260+
region: genericConfig.AwsRegion,
261+
});
262+
}
263+
const result = await fastify.sqsClient.send(
264+
new SendMessageCommand({
265+
QueueUrl: fastify.environmentConfig.SqsQueueUrl,
266+
MessageBody: JSON.stringify(sqsPayload),
267+
}),
268+
);
269+
if (!result.MessageId) {
270+
request.log.error(result);
271+
throw new InternalServerError({
272+
message: "Could not add room reservation email to queue.",
273+
});
274+
}
275+
request.log.info(
276+
`Queued room reservation email to SQS with message ID ${result.MessageId}`,
277+
);
244278
},
245279
);
246280
fastify.get<{

src/common/config.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,22 @@ const roleArns = {
138138

139139
export const EVENT_CACHED_DURATION = 120;
140140

141-
export { genericConfig, environmentConfig, roleArns };
141+
type NotificationRecipientsType = {
142+
[env in RunEnvironment]: {
143+
OfficerBoard: string;
144+
InfraChairs: string;
145+
};
146+
};
147+
148+
const notificationRecipients: NotificationRecipientsType = {
149+
dev: {
150+
OfficerBoard: '[email protected]',
151+
InfraChairs: '[email protected]',
152+
},
153+
prod: {
154+
OfficerBoard: '[email protected]',
155+
InfraChairs: '[email protected]',
156+
}
157+
}
158+
159+
export { genericConfig, environmentConfig, roleArns, notificationRecipients };

0 commit comments

Comments
 (0)