2023-03-10 20:00:19 +00:00
|
|
|
import type { IntervalLimit } from "@calcom/types/Calendar";
|
|
|
|
|
2023-08-09 22:51:38 +00:00
|
|
|
import { ascendingLimitKeys } from "./intervalLimit";
|
|
|
|
|
2023-03-10 20:00:19 +00:00
|
|
|
export const validateIntervalLimitOrder = (input: IntervalLimit) => {
|
|
|
|
// Sort limits by validationOrder
|
|
|
|
const sorted = Object.entries(input)
|
|
|
|
.sort(([, value], [, valuetwo]) => {
|
|
|
|
return value - valuetwo;
|
|
|
|
})
|
|
|
|
.map(([key]) => key);
|
|
|
|
|
2023-08-09 22:51:38 +00:00
|
|
|
const validationOrderWithoutMissing = ascendingLimitKeys.filter((key) => sorted.includes(key));
|
2023-03-10 20:00:19 +00:00
|
|
|
|
|
|
|
return sorted.every((key, index) => validationOrderWithoutMissing[index] === key);
|
|
|
|
};
|