From 04df22648e0b389cd2fa3e061d790868209659a7 Mon Sep 17 00:00:00 2001 From: "riho.takagi" Date: Wed, 15 Jan 2025 15:52:00 -0500 Subject: [PATCH] Debugging events with no prefix --- .../api/syncSemesterPregameBookings/route.ts | 66 ++++++++++++------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/booking-app/app/api/syncSemesterPregameBookings/route.ts b/booking-app/app/api/syncSemesterPregameBookings/route.ts index 24cbcfbb..86c66b5e 100644 --- a/booking-app/app/api/syncSemesterPregameBookings/route.ts +++ b/booking-app/app/api/syncSemesterPregameBookings/route.ts @@ -1,5 +1,4 @@ import { toFirebaseTimestampFromString } from "@/components/src/client/utils/serverDate"; -import { TableNames } from "@/components/src/policy"; import { Booking, BookingStatusLabel, @@ -281,8 +280,27 @@ export async function POST(request: Request) { if (!existingBookingSnapshot.empty) { console.log( - `Skipping event with title "${title}", startDate "${event.start?.dateTime}" as it already exists.`, + `A Booking with title "${title}" and startDate "${event.start?.dateTime}" already exists.`, ); + + // Add [PENDING] + if ( + !title.startsWith("[") && + !title.includes(`[${BookingStatusLabel.PENDING}]`) + ) { + const newTitle = `[${BookingStatusLabel.PENDING}] ${title}`; + console.log( + `Renaming existing event title from "${title}" to "${newTitle}".`, + ); + + //await calendar.events.patch({ + // calendarId: resource.calendarId, + // eventId: event.id!, + // requestBody: { + // summary: newTitle, + // }, + //}); + } continue; } @@ -311,28 +329,28 @@ export async function POST(request: Request) { console.log("newBooking", newBooking); const newTitle = `[${BookingStatusLabel.PENDING}] ${event.summary}`; - const bookingDocRef = await db - .collection(TableNames.BOOKING) - .add({ - ...newBooking, - requestedAt: admin.firestore.FieldValue.serverTimestamp(), - firstApprovedAt: - admin.firestore.FieldValue.serverTimestamp(), - }); - - //Add all requesters as guests to the calendar event - if (event.id) { - await calendar.events.patch({ - calendarId: resource.calendarId, - eventId: event.id, - requestBody: { - summary: newTitle, - }, - }); - } - - console.log(`New Booking created with ID: ${bookingDocRef.id}`); - totalNewBookings++; + //const bookingDocRef = await db + // .collection(TableNames.BOOKING) + // .add({ + // ...newBooking, + // requestedAt: admin.firestore.FieldValue.serverTimestamp(), + // firstApprovedAt: + // admin.firestore.FieldValue.serverTimestamp(), + // }); + + ////Add all requesters as guests to the calendar event + //if (event.id) { + // await calendar.events.patch({ + // calendarId: resource.calendarId, + // eventId: event.id, + // requestBody: { + // summary: newTitle, + // }, + // }); + //} + + //console.log(`New Booking created with ID: ${bookingDocRef.id}`); + //totalNewBookings++; } } }