forked from agentic-review-benchmarks/cal.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookingReferenceRepository.ts
More file actions
79 lines (71 loc) · 2.07 KB
/
BookingReferenceRepository.ts
File metadata and controls
79 lines (71 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { prisma } from "@calcom/prisma";
import type { Prisma, PrismaClient } from "@calcom/prisma/client";
import type { PartialReference } from "@calcom/types/EventManager";
import type { IBookingReferenceRepository } from "@calcom/lib/server/repository/dto/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,
});
}
}