mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
* 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
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/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
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|