From e9035434ae2504c52e33c6ce4591f139377f0cb2 Mon Sep 17 00:00:00 2001 From: "riho.takagi" Date: Wed, 15 Jan 2025 16:14:53 -0500 Subject: [PATCH] Add [PENDING] prefix to the title of pregame calendar events --- .../api/syncSemesterPregameBookings/route.ts | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/booking-app/app/api/syncSemesterPregameBookings/route.ts b/booking-app/app/api/syncSemesterPregameBookings/route.ts index 86c66b5e..33cc3dc5 100644 --- a/booking-app/app/api/syncSemesterPregameBookings/route.ts +++ b/booking-app/app/api/syncSemesterPregameBookings/route.ts @@ -1,4 +1,5 @@ import { toFirebaseTimestampFromString } from "@/components/src/client/utils/serverDate"; +import { TableNames } from "@/components/src/policy"; import { Booking, BookingStatusLabel, @@ -270,7 +271,6 @@ export async function POST(request: Request) { ) as Timestamp; const title = event.summary; const sanitizedTitle = title.replace(/^\[.*?\]\s*/, ""); // `[PENDING]` を削除 - console.log("sanitizedTitle", sanitizedTitle); const existingBookingSnapshot = await db .collection("bookings") @@ -293,13 +293,13 @@ export async function POST(request: Request) { `Renaming existing event title from "${title}" to "${newTitle}".`, ); - //await calendar.events.patch({ - // calendarId: resource.calendarId, - // eventId: event.id!, - // requestBody: { - // summary: newTitle, - // }, - //}); + await calendar.events.patch({ + calendarId: resource.calendarId, + eventId: event.id!, + requestBody: { + summary: newTitle, + }, + }); } continue; } @@ -329,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++; } } }