* refactor: handleNewBooking #3 * refactor: create booking factor * refactor: handleNewBooking * refactor: seats and rescheduleUId * chore: remove comment * fix: type err * chore: add missing statement * chore: use less params and other improvements * chore: name * chore: improvement * fix: type err * Typo fix * chore: fix type err * refactor: more readable * refactor: improve code * fix: conflicts --------- Co-authored-by: Joe Au-Yeung <j.auyeung419@gmail.com> Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com>
28 lines
823 B
TypeScript
28 lines
823 B
TypeScript
import type { Logger } from "tslog";
|
|
|
|
import dayjs from "@calcom/dayjs";
|
|
import { HttpError } from "@calcom/lib/http-error";
|
|
|
|
type Props = {
|
|
reqBodyStart: string;
|
|
reqBodyEnd: string;
|
|
eventTypeMultipleDuration?: number[];
|
|
eventTypeLength: number;
|
|
logger: Logger<unknown>;
|
|
};
|
|
|
|
export const validateEventLength = ({
|
|
reqBodyStart,
|
|
reqBodyEnd,
|
|
eventTypeMultipleDuration,
|
|
eventTypeLength,
|
|
logger,
|
|
}: Props) => {
|
|
const reqEventLength = dayjs(reqBodyEnd).diff(dayjs(reqBodyStart), "minutes");
|
|
const validEventLengths = eventTypeMultipleDuration?.length ? eventTypeMultipleDuration : [eventTypeLength];
|
|
if (!validEventLengths.includes(reqEventLength)) {
|
|
logger.warn({ message: "NewBooking: Invalid event length" });
|
|
throw new HttpError({ statusCode: 400, message: "Invalid event length" });
|
|
}
|
|
};
|