mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-09 01:18:18 +00:00
EDR last-mile is multi-truck but was modelled as one: setVehicles accepted any number of trucks with no validation, arrival/delivery were stamped once per last_mile record (N trucks shared one timestamp), EDR trucks got no exit paper, and the per-truck EDR handover never happened because deliver() resolved the plate via last_mile_container_allocations — a table nothing writes. - Migration 2260000000000: per-truck arrived_at/departed_at/gross_weight_tons/ net_weight_tons on last_mile_vehicle_assignments, plus a last_mile_vehicle_containers child table (a truck holds 1x40ft OR 2x20ft, so the single container_number scalar could not express a load). Weights are TONNES and named accordingly — the older gross_weight_kg lies about its unit. - setVehicles: enforce the size rule (one 40ft, or two 20ft), container membership, one-container-one-truck, and never more trucks than containers. Bulk carries no containers and is instead gated on tonnage remaining. - Bulk drawdown: remainingTonsForBooking = booking VGM minus the net weighed off every departed truck (both tonnes, no conversion), exposed as GET /last-mile/booking/:bookingId/remaining-tons. - release() now stamps the EDR truck's own arrival and exit (matched by plate, so it works for bulk too) alongside the existing customer-truck stamp. The exit weighing itself is untouched. - New GET /warehouse-inventory/edr-truck-exit-paper/:assignmentId — per-truck exit paper for EDR trucks. Deliberately not signature-gated: EDR handovers are generated at delivery, after the truck has left. - deliver(): resolve the handover plate from the truck's own containers instead of the dead allocations table, so EDR handovers are genuinely per-truck. - Notify the customer (portal inbox + SMS/email) when a truck leaves — one hook in release() covers both self-haul and EDR, since it is the single exit path. Self-haul is intentionally unchanged (one booking-level handover signed once). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { BaseEntity } from '@edr/api-common';
|
|
import { Column, Entity, Index, JoinColumn, ManyToOne } from 'typeorm';
|
|
|
|
import { LastMileVehicleAssignment } from './last-mile-vehicle-assignment.entity';
|
|
|
|
/**
|
|
* A container riding a specific EDR last-mile truck. A truck carries 1x40ft OR
|
|
* 2x20ft, so the assignment needs more than the single legacy `container_number`
|
|
* scalar. Mirrors the self-haul `customer_truck_containers` child table.
|
|
*/
|
|
@Entity({ schema: 'freight', name: 'last_mile_vehicle_containers' })
|
|
@Index(['assignmentId'])
|
|
export class LastMileVehicleContainer extends BaseEntity {
|
|
@Column({ name: 'assignment_id', type: 'uuid' })
|
|
assignmentId!: string;
|
|
|
|
@ManyToOne(() => LastMileVehicleAssignment, (a) => a.containers, {
|
|
nullable: false,
|
|
onDelete: 'CASCADE',
|
|
})
|
|
@JoinColumn({ name: 'assignment_id' })
|
|
assignment?: LastMileVehicleAssignment;
|
|
|
|
/** Denormalised for the "one container, one truck per delivery" unique index. */
|
|
@Column({ name: 'last_mile_id', type: 'uuid' })
|
|
lastMileId!: string;
|
|
|
|
@Column({ name: 'container_number', type: 'varchar', length: 32 })
|
|
containerNumber!: string;
|
|
}
|