Files
calendar/packages/lib/server/repository/PrismaSelectedSlotRepository.ts
T
Alex van AndelGitHubDevin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>Somay Chauhan
fde1d671fb refactor: rename SelectedSlotsRepository to PrismaSelectedSlotRepository (#22705)
* refactor: rename SelectedSlotsRepository to PrismaSelectedSlotRepository

- Rename class from SelectedSlotsRepository to PrismaSelectedSlotRepository for consistency
- Update all imports and type references throughout the codebase
- Update DI module bindings and variable names
- Maintain type safety without breaking changes

Co-Authored-By: alex@cal.com <me@alexvanandel.com>

* refactor: complete PrismaSelectedSlotRepository rename

- Update DI module binding property name from selectedSlotsRepo to selectedSlotRepo
- Update test mock to use PrismaSelectedSlotRepository class name
- Ensure all references are consistently updated

Co-Authored-By: alex@cal.com <me@alexvanandel.com>

* fix: rename file to prismaSelectedSlotRepository.ts and fix plural variable references

- Rename apps/api/v2/src/lib/repositories/prisma-selected-slots.repository.ts to prismaSelectedSlotRepository.ts
- Update class name from PrismaSelectedSlotsRepository to PrismaSelectedSlotRepository
- Fix plural variable reference selectedSlotsRepository to selectedSlotRepository in service
- Update all import paths to reference the new file name
- Maintain consistency with camelCase naming convention

Co-Authored-By: alex@cal.com <me@alexvanandel.com>

* fix: rename SelectedSlotsRepositoryFixture to SelectedSlotRepositoryFixture for consistency

- Rename test fixture class from SelectedSlotsRepositoryFixture to SelectedSlotRepositoryFixture (singular)
- Update all import statements in test files to use the renamed class
- Resolves naming mismatch between fixture class and variable declarations
- Fixes TypeScript compilation errors in CI tests

Co-Authored-By: alex@cal.com <me@alexvanandel.com>

* feat: add SelectedSlotRepositoryInterface and update DI to use interface

Co-Authored-By: alex@cal.com <me@alexvanandel.com>

* refactor: rename selectedSlots.ts to selectedSlot.ts and update all imports

Co-Authored-By: alex@cal.com <me@alexvanandel.com>

* fix: update test mock import path after file rename

Co-Authored-By: alex@cal.com <me@alexvanandel.com>

* Update apps/api/v2/src/lib/modules/available-slots.module.ts

* Update apps/api/v2/src/lib/modules/available-slots.module.ts

* Implement DTO

* dont declare dependencies locally, duplicating

* Small DTO/token fix

* chore: bump @calcom/platform-libraries from 0.0.266 to 0.0.267

* oops.

* Update fixture names also

* Omg these vscode actions preventing saves

* Final fix, hopefully

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Somay Chauhan <somaychauhan98@gmail.com>
2025-07-25 16:59:32 -07: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 },
},
});
}
}