refactor: move getTotalBookingDuration to BookingRepository (#22931)

* refactor: move getTotalBookingDuration to BookingRepository

- Move getTotalBookingDuration function from standalone file to BookingRepository class
- Update all usage sites to call method through repository instance
- Remove standalone function file packages/lib/server/queries/booking/index.ts
- Add prisma import to util.ts for BookingRepository instantiation
- Maintain exact same method signature and functionality

Co-Authored-By: [email protected] <[email protected]>

* fix: remove eslint-config-next to resolve TypeScript ESLint conflicts

- Remove eslint-config-next dependency that was causing version conflicts
- Resolves 'Class extends value undefined is not a constructor or null' errors
- ESLint 'next' config issue appears to be pre-existing in main branch

Co-Authored-By: [email protected] <[email protected]>

* fixup! Merge branch 'main' into devin/move-getTotalBookingDuration-1754460208

* chore: bump platform libs

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: [email protected] <[email protected]>
Co-authored-by: Morgan <[email protected]>
This commit is contained in:
authored and GitHub committed 2025-08-07 10:53:18 +03:00
1 parent 895ed48bd6
commit cfda4757e4
8 files changed
+106 -76

No files matched your search

@@ -42,7 +42,6 @@ import logger from "@calcom/lib/logger";
import { isRestrictionScheduleEnabled } from "@calcom/lib/restrictionSchedule";
import { safeStringify } from "@calcom/lib/safeStringify";
import { withReporting } from "@calcom/lib/sentryWrapper";
import { getTotalBookingDuration } from "@calcom/lib/server/queries/booking";
import type { ISelectedSlotRepository } from "@calcom/lib/server/repository/ISelectedSlotRepository";
import type { BookingRepository } from "@calcom/lib/server/repository/booking";
import type { EventTypeRepository } from "@calcom/lib/server/repository/eventTypeRepository";
@@ -400,7 +399,12 @@ export class AvailableSlotsService {
if (!limit) continue;
const unit = intervalLimitKeyToUnit(key);
const periodStartDates = this.dependencies.userAvailabilityService.getPeriodStartDatesBetween(dateFrom, dateTo, unit, timeZone);
const periodStartDates = this.dependencies.userAvailabilityService.getPeriodStartDatesBetween(
dateFrom,
dateTo,
unit,
timeZone
);
for (const periodStart of periodStartDates) {
if (globalLimitManager.isAlreadyBusy(periodStart, unit, timeZone)) continue;
@@ -435,7 +439,12 @@ export class AvailableSlotsService {
if (!limit) continue;
const unit = intervalLimitKeyToUnit(key);
const periodStartDates = this.dependencies.userAvailabilityService.getPeriodStartDatesBetween(dateFrom, dateTo, unit, timeZone);
const periodStartDates = this.dependencies.userAvailabilityService.getPeriodStartDatesBetween(
dateFrom,
dateTo,
unit,
timeZone
);
for (const periodStart of periodStartDates) {
if (limitManager.isAlreadyBusy(periodStart, unit, timeZone)) continue;
@@ -486,7 +495,12 @@ export class AvailableSlotsService {
if (!limit) continue;
const unit = intervalLimitKeyToUnit(key);
const periodStartDates = this.dependencies.userAvailabilityService.getPeriodStartDatesBetween(dateFrom, dateTo, unit, timeZone);
const periodStartDates = this.dependencies.userAvailabilityService.getPeriodStartDatesBetween(
dateFrom,
dateTo,
unit,
timeZone
);
for (const periodStart of periodStartDates) {
if (limitManager.isAlreadyBusy(periodStart, unit, timeZone)) continue;
@@ -499,8 +513,7 @@ export class AvailableSlotsService {
}
if (unit === "year") {
// TODO: DI getTotalBookingDuration
const totalYearlyDuration = await getTotalBookingDuration({
const totalYearlyDuration = await this.dependencies.bookingRepo.getTotalBookingDuration({
eventId: eventType.id,
startDate: periodStart.toDate(),
endDate: periodStart.endOf(unit).toDate(),
@@ -586,7 +599,12 @@ export class AvailableSlotsService {
if (!limit) continue;
const unit = intervalLimitKeyToUnit(key);
const periodStartDates = this.dependencies.userAvailabilityService.getPeriodStartDatesBetween(dateFrom, dateTo, unit, timeZone);
const periodStartDates = this.dependencies.userAvailabilityService.getPeriodStartDatesBetween(
dateFrom,
dateTo,
unit,
timeZone
);
for (const periodStart of periodStartDates) {
if (globalLimitManager.isAlreadyBusy(periodStart, unit, timeZone)) continue;
@@ -634,7 +652,12 @@ export class AvailableSlotsService {
if (!limit) continue;
const unit = intervalLimitKeyToUnit(key);
const periodStartDates = this.dependencies.userAvailabilityService.getPeriodStartDatesBetween(dateFrom, dateTo, unit, timeZone);
const periodStartDates = this.dependencies.userAvailabilityService.getPeriodStartDatesBetween(
dateFrom,
dateTo,
unit,
timeZone
);
for (const periodStart of periodStartDates) {
if (limitManager.isAlreadyBusy(periodStart, unit, timeZone)) continue;