Files
calendar/packages/features/bookings/lib/handleNewBooking/checkBookingAndDurationLimits.ts
Benny JooandGitHub ff38d6c7db refactor: Remove circular deps between @calcom/lib and @calcom/features [1] (#24399)
* add eslint config

* migrate autoLock to features

* migrate teamService to features

* migrate userCreationService

* migrate insights services to features

* migrate ProfileRepository

* update imports

* migrate filter segmen tests

* migrate filter segment repository

* migrate getBusyTimes

* migrate getLocaleFromRequest

* refactor csvUtils

* make filename clearer

* migrate getLuckyUser integration test

* migrate autoLock test to features

* wip

* refactors

* migrate useBookerUrl

* migrate more

* wip

* Migrate eventTypeRepository

* membership repository

* update imports

* update imports

* migrate

* move organization repository

* update imports

* update imports

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix tests

* fix type checks

* fix

* fix

* migrate

* update imports

* fix tests

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix
2025-10-13 12:01:02 -03:00

55 lines
1.9 KiB
TypeScript

import dayjs from "@calcom/dayjs";
import type { IntervalLimit } from "@calcom/lib/intervalLimits/intervalLimitSchema";
import type { CheckBookingLimitsService } from "@calcom/features/bookings/lib/checkBookingLimits";
import { checkDurationLimits } from "@calcom/features/bookings/lib/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
);
}
}
}
}