Files
calendar/packages/features/bookingReference/repositories/BookingReferenceRepository.ts
T
Benny JooandGitHub cb7844fd22 refactor: Migrate repositories/services from /lib to /features (#25925)
* deployment

* update imports

* booking report

* update import paths

* watch list

* watch list

* api key

* api key

* selected slots

* wip

* event type translation

* work flow step

* booking reference

* fix tests

* fix

* fix

* migrate

* wip

* address

* fix
2025-12-17 14:14:50 +00:00

61 lines
1.5 KiB
TypeScript

import { prisma } from "@calcom/prisma";
import type { Prisma } from "@calcom/prisma/client";
import type { PartialReference } from "@calcom/types/EventManager";
const bookingReferenceSelect = {
id: true,
type: true,
uid: true,
meetingId: true,
meetingUrl: true,
credentialId: true,
deleted: true,
bookingId: true,
} satisfies Prisma.BookingReferenceSelect;
export class BookingReferenceRepository {
static async findDailyVideoReferenceByRoomName({ roomName }: { roomName: string }) {
return prisma.bookingReference.findFirst({
where: {
type: "daily_video",
uid: roomName,
meetingId: roomName,
bookingId: { not: null },
deleted: null,
},
select: bookingReferenceSelect,
});
}
/**
* If rescheduling a booking with new references from the EventManager. Delete the previous references and replace them with new ones
*/
static async replaceBookingReferences({
bookingId,
newReferencesToCreate,
}: {
bookingId: number;
newReferencesToCreate: PartialReference[];
}) {
const newReferenceTypes = newReferencesToCreate.map((reference) => reference.type);
await prisma.bookingReference.updateMany({
where: {
bookingId,
type: {
in: newReferenceTypes,
},
},
data: {
deleted: true,
},
});
await prisma.bookingReference.createMany({
data: newReferencesToCreate.map((reference) => {
return { ...reference, bookingId };
}),
});
}
}