feat: reset RR every month (#17472)

* only fetch bookings of this month for weighted rr

* test set up

* only get bookings of current month

* reverts test setup

* first changes for weight adjustments

* reset booking count + adjust calibration

* depreciate weightAdjustment

* get only bookings created this month

* fix typo

* make sure createdAt for hosts is correct

* use earliest possibel date as fallback

* add missing createdAt date to tests

* fix typo

* clean up changes in tests

* fix typo

* change end date to current date

* fix: Fall back to empty host array when no hosts are found

* fix: Restructure code a little

* fixed test, incorrectly used now outdated var

* perf: remove Dayjs from getLuckyUser

* Refactor getHostsWithCalibration for optimised performance, intentionally break test as findMany is always an array

* Better mock for host.findMany

* Remove team-event-types.test.ts, move to appropriate package

* TypeScript cannot auto-infer that an array is non-empty when assigning to a var

* fix: Type Fixes and DistributionMethod enum add

* Optimise tests

* Added test to show that bookings made before a newHost was added affect the lucky user result

* Throw error when the usersWithHighestPriority is empty, which should never happen

---------

Co-authored-by: CarinaWolli <[email protected]>
Co-authored-by: Alex van Andel <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-11-07 10:24:23 +00:00
1 parent 52093862ce
commit 9873e373dc
26 files changed
+808 -876

No files matched your search

@@ -74,7 +74,6 @@ const CheckedHostField = ({
userId: parseInt(option.value, 10),
priority: option.priority ?? 2,
weight: option.weight ?? 100,
weightAdjustment: option.weightAdjustment ?? 0,
scheduleId: option.defaultScheduleId,
}))
);
@@ -15,7 +15,6 @@ export type CheckedSelectOption = {
value: string;
priority?: number;
weight?: number;
weightAdjustment?: number;
isFixed?: boolean;
disabled?: boolean;
defaultScheduleId?: number | null;
@@ -24,7 +24,6 @@ export type Host = {
userId: number;
priority: number;
weight: number;
weightAdjustment: number;
scheduleId?: number | null;
};
@@ -53,7 +53,6 @@ export const PriorityDialog = (props: IDialog) => {
priority: host.userId === parseInt(option.value, 10) ? newPriority.value : host.priority,
isFixed: false,
weight: host.weight,
weightAdjustment: host.weightAdjustment,
};
});
@@ -135,7 +134,6 @@ export const WeightDialog = (props: IDialog) => {
priority: host.priority,
weight: host.userId === parseInt(option.value, 10) ? newWeight : host.weight,
isFixed: false,
weightAdjustment: host.weightAdjustment,
};
});
@@ -145,7 +145,6 @@ const FixedHosts = ({
userId: parseInt(teamMember.value, 10),
priority: 2,
weight: 100,
weightAdjustment: 0,
// if host was already added, retain scheduleId
scheduleId: host?.scheduleId || teamMember.defaultScheduleId,
};
@@ -194,7 +193,6 @@ const FixedHosts = ({
userId: parseInt(teamMember.value, 10),
priority: 2,
weight: 100,
weightAdjustment: 0,
// if host was already added, retain scheduleId
scheduleId: host?.scheduleId || teamMember.defaultScheduleId,
};
@@ -279,7 +277,6 @@ const RoundRobinHosts = ({
userId: parseInt(teamMember.value, 10),
priority: 2,
weight: 100,
weightAdjustment: 0,
// if host was already added, retain scheduleId
scheduleId: host?.scheduleId || teamMember.defaultScheduleId,
};
@@ -26,7 +26,6 @@ export type Host = {
userId: number;
priority: number;
weight: number;
weightAdjustment: number;
scheduleId?: number | null;
};
export type TeamMember = {