Files
calendar/packages/features/selectedSlots/repositories/PrismaSelectedSlotRepository.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

93 lines
2.2 KiB
TypeScript

import type { PrismaClient } from "@calcom/prisma";
import type { Prisma } from "@calcom/prisma/client";
import type { ISelectedSlotRepository } from "./ISelectedSlotRepository";
import type { TimeSlot } from "./ISelectedSlotRepository";
export class PrismaSelectedSlotRepository implements ISelectedSlotRepository {
constructor(private prismaClient: PrismaClient) {}
private async findFirst({ where }: { where: Prisma.SelectedSlotsWhereInput }) {
return await this.prismaClient.selectedSlots.findFirst({
where,
});
}
async findReservedByOthers({
slot,
eventTypeId,
uid,
}: {
slot: TimeSlot;
eventTypeId: number;
uid: string;
}) {
return await this.findFirst({
where: {
slotUtcStartDate: slot.utcStartIso,
slotUtcEndDate: slot.utcEndIso,
eventTypeId,
uid: { not: uid },
releaseAt: { gt: new Date() },
},
});
}
async findManyReservedByOthers(slots: TimeSlot[], eventTypeId: number, uid: string) {
return await this.prismaClient.selectedSlots.findMany({
where: {
OR: slots.map((slot) => ({
slotUtcStartDate: slot.utcStartIso,
slotUtcEndDate: slot.utcEndIso,
eventTypeId,
uid: { not: uid },
releaseAt: { gt: new Date() },
})),
},
select: {
slotUtcStartDate: true,
slotUtcEndDate: true,
},
});
}
async findManyUnexpiredSlots({
userIds,
currentTimeInUtc,
}: {
userIds: number[];
currentTimeInUtc: string;
}) {
return this.prismaClient.selectedSlots.findMany({
where: {
userId: { in: userIds },
releaseAt: { gt: currentTimeInUtc },
},
select: {
id: true,
slotUtcStartDate: true,
slotUtcEndDate: true,
userId: true,
isSeat: true,
eventTypeId: true,
uid: true,
},
});
}
async deleteManyExpiredSlots({
eventTypeId,
currentTimeInUtc,
}: {
eventTypeId: number;
currentTimeInUtc: string;
}) {
return this.prismaClient.selectedSlots.deleteMany({
where: {
eventTypeId: { equals: eventTypeId },
releaseAt: { lt: currentTimeInUtc },
},
});
}
}