Update calendar when new attendees are added to bookings w/ seats (#3257)

Co-authored-by: Omar López <zomars@me.com>
Co-authored-by: Alex van Andel <me@alexvanandel.com>
This commit is contained in:
authored and GitHub committed 2022-07-12 09:16:34 -04:00
1 parent 5fa336c195
commit 46266781b5
2 files changed
+24 -4

No files matched your search

+19 -3
View File
@@ -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,
+5 -1
View File
@@ -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