Skip to content
14 changes: 14 additions & 0 deletions packages/lib/__tests__/buildCalEventFromBooking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ const createBooking = (overrides = {}) => ({
},
destinationCalendar: null,
user: null,
iCalSequence: 0,
iCalUID: "icaluid",
...overrides,
});

Expand Down Expand Up @@ -121,6 +123,10 @@ describe("buildCalEventFromBooking", () => {
destinationCalendar: [],
seatsPerTimeSlot: booking.eventType?.seatsPerTimeSlot,
seatsShowAttendees: true,
customReplyToEmail: undefined,
hideOrganizerEmail: undefined,
iCalSequence: 0,
iCalUID: booking.iCalUID,
});

expect(parseRecurringEvent).toHaveBeenCalledWith(booking.eventType?.recurringEvent);
Expand All @@ -135,6 +141,8 @@ describe("buildCalEventFromBooking", () => {
userPrimaryEmail: null,
attendees: [],
eventType: null,
iCalUID: "icaluid",
iCalSequence: 0,
});

const organizer = createOrganizer({ name: null, locale: null });
Expand Down Expand Up @@ -170,6 +178,10 @@ describe("buildCalEventFromBooking", () => {
destinationCalendar: [],
seatsPerTimeSlot: undefined,
seatsShowAttendees: undefined,
customReplyToEmail: undefined,
hideOrganizerEmail: undefined,
iCalSequence: 0,
iCalUID: "icaluid",
});

// @ts-expect-error - locale is set in mock
Expand All @@ -192,6 +204,8 @@ describe("buildCalEventFromBooking", () => {
credentialId: 1,
},
},
iCalUID: "icaluid",
iCalSequence: 0,
});

const organizer = createOrganizer();
Expand Down
4 changes: 4 additions & 0 deletions packages/lib/buildCalEventFromBooking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ type Booking = {
} | null;
attendees: Attendee[];
eventType: EventType | null;
iCalUID: string | null;
iCalSequence: number;
};

export const buildCalEventFromBooking = async ({
Expand Down Expand Up @@ -110,5 +112,7 @@ export const buildCalEventFromBooking = async ({
seatsPerTimeSlot: booking.eventType?.seatsPerTimeSlot,
seatsShowAttendees: booking.eventType?.seatsShowAttendees,
customReplyToEmail: booking.eventType?.customReplyToEmail,
iCalUID: booking.iCalUID ?? booking.uid,
iCalSequence: booking.iCalSequence ?? 0,
};
};
6 changes: 5 additions & 1 deletion packages/lib/server/repository/booking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,13 +522,15 @@ export class BookingRepository {

async updateLocationById({
where: { id },
data: { location, metadata, referencesToCreate },
data: { location, metadata, referencesToCreate, responses, iCalSequence },
}: {
where: { id: number };
data: {
location: string;
metadata: Record<string, unknown>;
referencesToCreate: Prisma.BookingReferenceCreateInput[];
responses?: Record<string, unknown>;
iCalSequence?: number;
};
}) {
await this.prismaClient.booking.update({
Expand All @@ -538,6 +540,8 @@ export class BookingRepository {
data: {
location,
metadata,
...(responses && { responses }),
...(iCalSequence !== undefined && { iCalSequence }),
references: {
create: referencesToCreate,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import logger from "@calcom/lib/logger";
import { safeStringify } from "@calcom/lib/safeStringify";
import { getUsersCredentialsIncludeServiceAccountKey } from "@calcom/lib/server/getUsersCredentials";
import { getTranslation } from "@calcom/lib/server/i18n";
import { BookingRepository } from "@calcom/lib/server/repository/booking";
import { CredentialRepository } from "@calcom/lib/server/repository/credential";
import { UserRepository } from "@calcom/lib/server/repository/user";
import { prisma } from "@calcom/prisma";
Expand Down Expand Up @@ -97,26 +98,24 @@ async function updateBookingLocationInDb({
};
});

await prisma.booking.update({
where: {
id: booking.id,
},
const bookingRepository = new BookingRepository(prisma);
await bookingRepository.updateLocationById({
where: { id: booking.id },
data: {
location: evt.location,
metadata: {
...(typeof booking.metadata === "object" && booking.metadata),
...bookingMetadataUpdate,
},
references: {
create: referencesToCreate,
},
referencesToCreate,
responses: {
...(typeof booking.responses === "object" && booking.responses),
location: {
value: evt.location,
optionValue: "",
},
},
iCalSequence: (evt.iCalSequence || 0) + 1,
},
});
}
Expand Down
Loading