mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 20:10:56 +00:00
28 lines
986 B
TypeScript
28 lines
986 B
TypeScript
export interface SchedulingPriorityBooking {
|
|
isGovernment?: boolean;
|
|
priorityScore?: number | null;
|
|
// One-time bookings always carry a date; general contracts (never scheduled)
|
|
// may be null — treated as the far future (MAX_SAFE_INTEGER) so they sort last.
|
|
scheduledDate?: Date | string | null;
|
|
}
|
|
|
|
/** Government first, then priority score, then earliest scheduled date. */
|
|
export function compareSchedulingPriority(
|
|
a: SchedulingPriorityBooking,
|
|
b: SchedulingPriorityBooking,
|
|
): number {
|
|
const govDiff = Number(Boolean(b.isGovernment)) - Number(Boolean(a.isGovernment));
|
|
if (govDiff !== 0) return govDiff;
|
|
|
|
const priorityDiff = (b.priorityScore ?? 0) - (a.priorityScore ?? 0);
|
|
if (priorityDiff !== 0) return priorityDiff;
|
|
|
|
const aTime = a.scheduledDate
|
|
? new Date(a.scheduledDate).getTime()
|
|
: Number.MAX_SAFE_INTEGER;
|
|
const bTime = b.scheduledDate
|
|
? new Date(b.scheduledDate).getTime()
|
|
: Number.MAX_SAFE_INTEGER;
|
|
return aTime - bTime;
|
|
}
|