Scheduling infrastructure for absolutely everyone.
Update calendar when new attendees are added to bookings w/ seats (#3257)
Joe Au-Yeung46266781b5d3
diff --git a/apps/web/pages/api/book/event.ts b/apps/web/pages/api/book/event.tsindex da9ca8794b4..5b2fd3b5cc7 100644--- a/apps/web/pages/api/book/event.ts+++ b/apps/web/pages/api/book/event.ts@@ -234,6 +234,7 @@ async function handler(req: NextApiRequest) {!eventTypeId && !!eventTypeSlug ? getDefaultEvent(eventTypeSlug) : await getEventTypesFromDB(eventTypeId);if (!eventType) throw new HttpError({ statusCode: 404, message: "eventType.notFound" });+ let user: User | null = null;let users = !eventTypeId? await prisma.user.findMany({where: {@@ -362,8 +363,19 @@ async function handler(req: NextApiRequest) {where: {uid: reqBody.bookingUid,},- include: {+ select: {+ id: true,attendees: true,+ references: {+ select: {+ type: true,+ uid: true,+ meetingId: true,+ meetingPassword: true,+ meetingUrl: true,+ externalCalendarId: true,+ },+ },},});if (!booking) throw new HttpError({ statusCode: 404, message: "Booking not found" });@@ -401,6 +413,11 @@ async function handler(req: NextApiRequest) {await sendScheduledSeatsEmails(evt, invitee[0], newSeat);+ user = users[0];+ const credentials = await refreshCredentials(user.credentials);+ const eventManager = new EventManager({ ...user, credentials });+ await eventManager.updateCalendarAttendees(evt, booking);+req.statusCode = 201;return booking;}@@ -577,7 +594,6 @@ async function handler(req: NextApiRequest) {let results: EventResult<AdditionalInformation>[] = [];let referencesToCreate: PartialReference[] = [];- let user: User | null = null;/** Let's start checking for availability */for (const currentUser of users) {@@ -683,7 +699,7 @@ async function handler(req: NextApiRequest) {if (originalRescheduledBooking?.uid) {// Use EventManager to conditionally use all needed integrations.- const updateManager = await eventManager.update(+ const updateManager = await eventManager.reschedule(evt,originalRescheduledBooking.uid,booking?.id,diff --git a/packages/core/EventManager.ts b/packages/core/EventManager.tsindex 9bc0485255c..aebfaf4dc79 100644--- a/packages/core/EventManager.ts+++ b/packages/core/EventManager.ts@@ -156,7 +156,7 @@ export default class EventManager {** @param event*/- public async update(+ public async reschedule(event: CalendarEvent,rescheduleUid: string,newBookingId?: number,@@ -266,6 +266,10 @@ export default class EventManager {};}+ public async updateCalendarAttendees(event: CalendarEvent, booking: PartialBooking) {+ await this.updateAllCalendarEvents(event, booking);+ }+/*** Creates event entries for all calendar integrations given in the credentials.* When noMail is true, no mails will be sent. This is used when the event is