Skip to content
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
28 changes: 26 additions & 2 deletions src/services/attendee/attendee-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,20 @@ attendeeRouter.post(
.maybeSingle()
.throwOnError();

const { data: event } = await SupabaseDB.EVENTS.select()
.eq("eventId", eventId)
.maybeSingle()
.throwOnError();

if (!event) {
return res
.status(StatusCodes.NOT_FOUND)
.json({ error: "EventNotFound" });
}

const topicName = `event_${event.name.replace(/[^a-zA-Z0-9-_.~%]/g, "_")}`;

if (device?.deviceId) {
const topicName = `event_${eventId}`;
await getFirebaseAdmin()
.messaging()
.subscribeToTopic(device?.deviceId, topicName);
Expand Down Expand Up @@ -113,8 +125,20 @@ attendeeRouter.delete(
.maybeSingle()
.throwOnError();

const { data: event } = await SupabaseDB.EVENTS.select()
.eq("eventId", eventId)
.maybeSingle()
.throwOnError();

if (!event) {
return res
.status(StatusCodes.NOT_FOUND)
.json({ error: "EventNotFound" });
}

const topicName = `event_${event.name.replace(/[^a-zA-Z0-9-_.~%]/g, "_")}`;

if (device?.deviceId) {
const topicName = `event_${eventId}`;
await getFirebaseAdmin()
.messaging()
.unsubscribeFromTopic(device?.deviceId, topicName);
Expand Down
10 changes: 5 additions & 5 deletions src/services/notifications/notifications-router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describe("/notifications", () => {

const expectedTopics = [
"allUsers",
`event_Test Event`,
`event_Test_Event`,
currentDayTopic,
"food_wave_1",
].sort();
Expand Down Expand Up @@ -252,7 +252,7 @@ describe("Attendee Favorite/Unfavorite Logic", () => {
// Setup: Create the user and the specific event for this test
await insertTestUser();
await SupabaseDB.EVENTS.insert({
id: testEventId,
eventId: testEventId,
name: "Test Event",
description: "Test event description",
startTime: new Date().toISOString(),
Expand All @@ -272,7 +272,7 @@ describe("Attendee Favorite/Unfavorite Logic", () => {
// Verify
expect(mockSubscribe).toHaveBeenCalledWith(
TEST_DEVICE_ID,
`event_${testEventId}`
`event_${"Test Event".replace(/[^a-zA-Z0-9-_.~%]/g, "_")}`
);

// Cleanup
Expand All @@ -284,7 +284,7 @@ describe("Attendee Favorite/Unfavorite Logic", () => {
// Setup: Create the user who has *already* favorited the event
await insertTestUser({ favoriteEvents: [testEventId] });
await SupabaseDB.EVENTS.insert({
id: testEventId,
eventId: testEventId,
name: "Test Event",
description: "Test event description",
startTime: new Date().toISOString(),
Expand All @@ -304,7 +304,7 @@ describe("Attendee Favorite/Unfavorite Logic", () => {
// Verify
expect(mockUnsubscribe).toHaveBeenCalledWith(
TEST_DEVICE_ID,
`event_${testEventId}`
`event_${"Test Event".replace(/[^a-zA-Z0-9-_.~%]/g, "_")}`
);

// Cleanup
Expand Down
6 changes: 5 additions & 1 deletion src/services/notifications/notifications-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ notificationsRouter.get(

const { data: events } =
await SupabaseDB.EVENTS.select("name").throwOnError();
const eventTopics = events.map((event) => `event_${event.name}`) ?? [];
const eventTopics =
events?.map(
(event) =>
`event_${event.name.replace(/[^a-zA-Z0-9-_.~%]/g, "_")}`
) ?? [];
const { data: customTopicsData } =
await SupabaseDB.CUSTOM_TOPICS.select("topicName").throwOnError();
const customTopics =
Expand Down