mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 01:20:55 +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";
|
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(
|
export function getRouteDirection(
|
||||||
origin: Freight.BookingReferenceYard | null | undefined,
|
origin: Freight.BookingReferenceYard | null | undefined,
|
||||||
dest: Freight.BookingReferenceYard | null | undefined,
|
dest: Freight.BookingReferenceYard | null | undefined,
|
||||||
): Freight.ScheduleTradeDirection | null {
|
): Freight.ScheduleTradeDirection | null {
|
||||||
if (!origin || !dest) return null;
|
if (!origin || !dest) return null;
|
||||||
if (origin.country === "Ethiopia" && dest.country === "Ethiopia") {
|
|
||||||
return "DOMESTIC";
|
const originCountry = origin.country?.trim();
|
||||||
}
|
const destCountry = dest.country?.trim();
|
||||||
if (origin.country === "Ethiopia" && dest.country === "Djibouti") {
|
|
||||||
return "EXPORT";
|
if (originCountry === "Djibouti") {
|
||||||
}
|
|
||||||
if (origin.country === "Djibouti" && dest.country === "Ethiopia") {
|
|
||||||
return "IMPORT";
|
return "IMPORT";
|
||||||
}
|
}
|
||||||
|
if (destCountry === "Djibouti" && originCountry !== "Djibouti") {
|
||||||
return null;
|
return "EXPORT";
|
||||||
|
}
|
||||||
|
return "DOMESTIC";
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calcWagons(containers: ContainerConfig[]) {
|
export function calcWagons(containers: ContainerConfig[]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user