mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-08 13:38:20 +00:00
add contract management types and interfaces for freight contracts
This commit is contained in:
35
apps/edr-freight-api/src/modules/bookings/road.util.ts
Normal file
35
apps/edr-freight-api/src/modules/bookings/road.util.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { ServiceType } from '../rule-engine/entities/service-type.entity';
|
||||
|
||||
/**
|
||||
* Road (truck) services are distinguished by their ServiceType.code. Rail
|
||||
* services are seeded as RAIL_* and go through the train batch pool; a road
|
||||
* service (code starting ROAD_ or TRUCK_, or exactly ROAD/TRUCK) instead bills
|
||||
* by distance and dispatches a truck. Prefix-matching keeps this resilient to
|
||||
* the exact seeded code (e.g. ROAD_CONTAINER, TRUCK_FORWARDING).
|
||||
*/
|
||||
export function isRoadService(
|
||||
serviceType?: Pick<ServiceType, 'code'> | null,
|
||||
): boolean {
|
||||
const code = serviceType?.code?.toUpperCase() ?? '';
|
||||
return (
|
||||
code === 'ROAD' ||
|
||||
code === 'TRUCK' ||
|
||||
code.startsWith('ROAD_') ||
|
||||
code.startsWith('TRUCK_')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Road freight charge for an order: distance (km, from the route line) × the
|
||||
* per-km rate. Returns 0 when either input is missing so callers can add it to
|
||||
* a total without guarding.
|
||||
*/
|
||||
export function roadKmPrice(
|
||||
km: number | null | undefined,
|
||||
perKmRate: number | null | undefined,
|
||||
): number {
|
||||
const distance = Number(km ?? 0);
|
||||
const rate = Number(perKmRate ?? 0);
|
||||
if (!(distance > 0) || !(rate > 0)) return 0;
|
||||
return distance * rate;
|
||||
}
|
||||
Reference in New Issue
Block a user