* refactor: convert checkBookingLimits to class service with dependency injection - Create CheckBookingLimitsService class following AvailableSlotsService pattern - Add countBookingsByEventTypeAndDateRange method to BookingRepository - Move direct prisma calls from service to repository layer - Implement dependency injection with proper DI tokens and modules - Update all usage points to use the new service through DI - Maintain backward compatibility with error-throwing wrapper functions - Update tests to use the new service pattern - Resolve TODO comment in AvailableSlotsService for DI integration Co-Authored-By: morgan@cal.com <morgan@cal.com> * chore: DI CheckBookingLimitsService in v2 slots service * chore: bump libraries * chore: create getCheckBookingLimitsService * refactor: convert checkBookingAndDurationLimits to service class with DI - Create CheckBookingAndDurationLimitsService class following DI pattern - Add DI tokens and module for the new service - Update booking-limits container to provide the new service - Refactor handleNewBooking.ts to use service through DI - Maintain backward compatibility with deprecated function export - Preserve all existing functionality while improving code organization Co-Authored-By: morgan@cal.com <morgan@cal.com> * chore: CheckBookingAndDurationLimitsService * chore: bump platform libs --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: morgan@cal.com <morgan@cal.com> Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
import dayjs from "@calcom/dayjs";
|
|
import type { IntervalLimit } from "@calcom/lib/intervalLimits/intervalLimitSchema";
|
|
import type { CheckBookingLimitsService } from "@calcom/lib/intervalLimits/server/checkBookingLimits";
|
|
import { checkDurationLimits } from "@calcom/lib/intervalLimits/server/checkDurationLimits";
|
|
import { withReporting } from "@calcom/lib/sentryWrapper";
|
|
|
|
import type { NewBookingEventType } from "./getEventTypesFromDB";
|
|
|
|
type EventType = Pick<NewBookingEventType, "bookingLimits" | "durationLimits" | "id" | "schedule">;
|
|
|
|
type InputProps = {
|
|
eventType: EventType;
|
|
reqBodyStart: string;
|
|
reqBodyRescheduleUid?: string;
|
|
};
|
|
|
|
export interface ICheckBookingAndDurationLimitsService {
|
|
checkBookingLimitsService: CheckBookingLimitsService;
|
|
}
|
|
|
|
export class CheckBookingAndDurationLimitsService {
|
|
constructor(private readonly dependencies: ICheckBookingAndDurationLimitsService) {}
|
|
|
|
checkBookingAndDurationLimits = withReporting(
|
|
this._checkBookingAndDurationLimits.bind(this),
|
|
"checkBookingAndDurationLimits"
|
|
);
|
|
|
|
async _checkBookingAndDurationLimits({ eventType, reqBodyStart, reqBodyRescheduleUid }: InputProps) {
|
|
if (
|
|
Object.prototype.hasOwnProperty.call(eventType, "bookingLimits") ||
|
|
Object.prototype.hasOwnProperty.call(eventType, "durationLimits")
|
|
) {
|
|
const startAsDate = dayjs(reqBodyStart).toDate();
|
|
if (eventType.bookingLimits && Object.keys(eventType.bookingLimits).length > 0) {
|
|
await this.dependencies.checkBookingLimitsService.checkBookingLimits(
|
|
eventType.bookingLimits as IntervalLimit,
|
|
startAsDate,
|
|
eventType.id,
|
|
reqBodyRescheduleUid,
|
|
eventType.schedule?.timeZone
|
|
);
|
|
}
|
|
if (eventType.durationLimits) {
|
|
await checkDurationLimits(
|
|
eventType.durationLimits as IntervalLimit,
|
|
startAsDate,
|
|
eventType.id,
|
|
reqBodyRescheduleUid
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|