Skip to content

Commit

Permalink
Revert "fix: Multiple rr-hosts combine to create erroneous availabili…
Browse files Browse the repository at this point in the history
…ty (#18772)"

This reverts commit f5dc22f.
  • Loading branch information
emrysal committed Feb 12, 2025
1 parent 486e3a3 commit 5dbc6d9
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 544 deletions.

This file was deleted.

34 changes: 9 additions & 25 deletions packages/core/getAggregatedAvailability/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,6 @@ import { SchedulingType } from "@calcom/prisma/enums";

import { mergeOverlappingDateRanges } from "./date-range-utils/mergeOverlappingDateRanges";

function uniqueAndSortedDateRanges(ranges: DateRange[]): DateRange[] {
const seen = new Set<string>();

return ranges
.sort((a, b) => {
const startDiff = a.start.valueOf() - b.start.valueOf();
return startDiff !== 0 ? startDiff : a.end.valueOf() - b.end.valueOf();
})
.filter((range) => {
const key = `${range.start.valueOf()}-${range.end.valueOf()}`;
if (seen.has(key)) return false;
seen.add(key);
return true;
});
}

export const getAggregatedAvailability = (
userAvailability: {
dateRanges: DateRange[];
Expand All @@ -32,22 +16,22 @@ export const getAggregatedAvailability = (
schedulingType === SchedulingType.COLLECTIVE ||
schedulingType === SchedulingType.ROUND_ROBIN ||
userAvailability.length > 1;

const fixedHosts = userAvailability.filter(
({ user }) => !schedulingType || schedulingType === SchedulingType.COLLECTIVE || user?.isFixed
);

const fixedDateRanges = mergeOverlappingDateRanges(
intersect(fixedHosts.map((s) => (!isTeamEvent ? s.dateRanges : s.oooExcludedDateRanges)))
const dateRangesToIntersect = fixedHosts.map((s) =>
!isTeamEvent ? s.dateRanges : s.oooExcludedDateRanges
);
const dateRangesToIntersect = !!fixedDateRanges.length ? [fixedDateRanges] : [];
const roundRobinHosts = userAvailability.filter(({ user }) => user?.isFixed !== true);
if (roundRobinHosts.length) {

const unfixedHosts = userAvailability.filter(({ user }) => user?.isFixed !== true);
if (unfixedHosts.length) {
dateRangesToIntersect.push(
roundRobinHosts.flatMap((s) => (!isTeamEvent ? s.dateRanges : s.oooExcludedDateRanges))
unfixedHosts.flatMap((s) => (!isTeamEvent ? s.dateRanges : s.oooExcludedDateRanges))
);
}

const availability = intersect(dateRangesToIntersect);
// we no longer merge overlapping date ranges, rr-hosts need to be individually available here.
return uniqueAndSortedDateRanges(availability);

return mergeOverlappingDateRanges(availability);
};
Loading

0 comments on commit 5dbc6d9

Please sign in to comment.