mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
fix: improve route direction logic to align with backend derivation rules
This commit is contained in:
@@ -288,22 +288,33 @@ export interface WagonConfig {
|
||||
type: "20ft" | "40ft";
|
||||
}
|
||||
|
||||
/**
|
||||
* Derive the trade direction from the origin/destination yard countries.
|
||||
*
|
||||
* Mirrors the backend's `deriveTradeDirection` exactly so the value the portal
|
||||
* sends always matches what the API re-derives (the API rejects mismatches):
|
||||
* - origin in Djibouti → IMPORT
|
||||
* - destination in Djibouti (origin not) → EXPORT
|
||||
* - everything else (e.g. Ethiopia↔Ethiopia)→ DOMESTIC
|
||||
*
|
||||
* Returns null only while a yard is still unselected, so the UI can wait.
|
||||
*/
|
||||
export function getRouteDirection(
|
||||
origin: Freight.BookingReferenceYard | null | undefined,
|
||||
dest: Freight.BookingReferenceYard | null | undefined,
|
||||
): Freight.ScheduleTradeDirection | null {
|
||||
if (!origin || !dest) return null;
|
||||
if (origin.country === "Ethiopia" && dest.country === "Ethiopia") {
|
||||
return "DOMESTIC";
|
||||
}
|
||||
if (origin.country === "Ethiopia" && dest.country === "Djibouti") {
|
||||
return "EXPORT";
|
||||
}
|
||||
if (origin.country === "Djibouti" && dest.country === "Ethiopia") {
|
||||
|
||||
const originCountry = origin.country?.trim();
|
||||
const destCountry = dest.country?.trim();
|
||||
|
||||
if (originCountry === "Djibouti") {
|
||||
return "IMPORT";
|
||||
}
|
||||
|
||||
return null;
|
||||
if (destCountry === "Djibouti" && originCountry !== "Djibouti") {
|
||||
return "EXPORT";
|
||||
}
|
||||
return "DOMESTIC";
|
||||
}
|
||||
|
||||
export function calcWagons(containers: ContainerConfig[]) {
|
||||
|
||||
Reference in New Issue
Block a user