mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 16:28:12 +00:00
booking operations and trains scheduling also allocations
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { Freight } from "@edr/types";
|
||||
|
||||
import type { Wagon } from "@/services/wagon.service";
|
||||
|
||||
export function wagonMatchesScheduleDirection(
|
||||
wagon: Pick<Wagon, "status" | "readiness">,
|
||||
scheduleDirection?: string | null,
|
||||
options?: { allowPinned?: boolean },
|
||||
): boolean {
|
||||
if (options?.allowPinned) return true;
|
||||
if (wagon.status !== Freight.WagonStatus.Available) return false;
|
||||
if (!scheduleDirection || scheduleDirection === "DOMESTIC") return true;
|
||||
if (scheduleDirection === "IMPORT") {
|
||||
return wagon.readiness === Freight.WagonReadiness.ImportReady;
|
||||
}
|
||||
if (scheduleDirection === "EXPORT") {
|
||||
return wagon.readiness === Freight.WagonReadiness.ExportReady;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export function filterWagonsForSchedule(
|
||||
wagons: Wagon[],
|
||||
scheduleDirection?: string | null,
|
||||
pinnedWagonIds?: Set<string>,
|
||||
): Wagon[] {
|
||||
return wagons.filter((wagon) => {
|
||||
const isPinned = pinnedWagonIds?.has(wagon.id) ?? false;
|
||||
return wagonMatchesScheduleDirection(wagon, scheduleDirection, {
|
||||
allowPinned: isPinned,
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user