* refactor: Remove intervalLimits from @calcom/lib and export directly * Tackle other places that use parseBookingLimit/parseDurationLimit * More type fixups that were hidden by previous fails * Fixed up booking-limits file * Remove server-only
18 lines
742 B
TypeScript
18 lines
742 B
TypeScript
import type { IntervalLimitUnit, IntervalLimitKey } from "./intervalLimitSchema";
|
|
|
|
export const ascendingLimitKeys: IntervalLimitKey[] = ["PER_DAY", "PER_WEEK", "PER_MONTH", "PER_YEAR"];
|
|
|
|
export const descendingLimitKeys = [...ascendingLimitKeys].reverse();
|
|
|
|
function isIntervalLimitUnit(value: string): value is IntervalLimitUnit {
|
|
return ["day", "week", "month", "year"].includes(value); // Replace with actual values
|
|
}
|
|
/**
|
|
* Turns `PER_DAY` into `day`, `PER_WEEK` into `week` etc.
|
|
*/
|
|
export function intervalLimitKeyToUnit(key: IntervalLimitKey): IntervalLimitUnit {
|
|
const extracted = key.split("_")[1].toLowerCase();
|
|
if (isIntervalLimitUnit(extracted)) return extracted;
|
|
throw new Error(`Invalid interval limit key: ${key}`);
|
|
}
|