Skip to content

Commit

Permalink
Merge pull request #558 from ITPNYU/main
Browse files Browse the repository at this point in the history
Debugging events with no prefix
  • Loading branch information
rlho authored Jan 15, 2025
2 parents 671d7d3 + 04df226 commit 020fdd8
Showing 1 changed file with 42 additions and 24 deletions.
66 changes: 42 additions & 24 deletions booking-app/app/api/syncSemesterPregameBookings/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { toFirebaseTimestampFromString } from "@/components/src/client/utils/serverDate";
import { TableNames } from "@/components/src/policy";
import {
Booking,
BookingStatusLabel,
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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++;
}
}
}
Expand Down

0 comments on commit 020fdd8

Please sign in to comment.