* refactor: move repositories from lib to features domain folders - Move HolidayRepository to features/holidays/repositories - Move PrismaTrackingRepository to features/bookings/repositories - Move PrismaBookingPaymentRepository to features/bookings/repositories - Move PrismaRoutingFormResponseRepository to features/routing-forms/repositories - Move PrismaAssignmentReasonRepository to features/assignment-reason/repositories - Move VerificationTokenRepository to features/auth/repositories - Move WorkspacePlatformRepository to features/workspace-platform/repositories - Move DTO files to their respective feature domains - Merge lib DestinationCalendarRepository into features version - Merge lib SelectedCalendarRepository into features version - Update all import paths across the codebase This follows the vertical slice architecture pattern by organizing repositories by domain rather than by technical layer. Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: update VerificationTokenService import path to new location Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: update test file imports to use new repository locations Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * mv * fix structure * fix * refactor: merge unit tests for SelectedCalendarRepository into single file Co-Authored-By: benny@cal.com <sldisek783@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
80 lines
2.0 KiB
TypeScript
80 lines
2.0 KiB
TypeScript
import { prisma } from "@calcom/prisma";
|
|
import type { Prisma, PrismaClient } from "@calcom/prisma/client";
|
|
import type { PartialReference } from "@calcom/types/EventManager";
|
|
|
|
import type { IBookingReferenceRepository } from "./IBookingReferenceRepository";
|
|
|
|
const bookingReferenceSelect = {
|
|
id: true,
|
|
type: true,
|
|
uid: true,
|
|
meetingId: true,
|
|
meetingUrl: true,
|
|
credentialId: true,
|
|
deleted: true,
|
|
bookingId: true,
|
|
} satisfies Prisma.BookingReferenceSelect;
|
|
|
|
export class BookingReferenceRepository implements IBookingReferenceRepository {
|
|
private prismaClient: PrismaClient;
|
|
constructor(private deps: { prismaClient: PrismaClient }) {
|
|
this.prismaClient = deps.prismaClient;
|
|
}
|
|
|
|
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 };
|
|
}),
|
|
});
|
|
}
|
|
|
|
async updateManyByBookingId(
|
|
bookingId: number,
|
|
data: Prisma.BookingReferenceUpdateManyMutationInput
|
|
): Promise<void> {
|
|
await this.prismaClient.bookingReference.updateMany({
|
|
where: {
|
|
bookingId,
|
|
},
|
|
data,
|
|
});
|
|
}
|
|
}
|