mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 00:52:50 +00:00
fix(freight-api): auto-unload bookings on final-yard bulk arrival
autoArriveAtFinalYard() bulk-updated booking status to ARRIVED/COMPLETED via raw SQL but never emitted booking.unloadedAtYard, so WarehouseInventoryService's listener never created the warehouse_inventory row — bookings caught by this fallback (e.g. KALITY import arrivals) stayed on awaiting unload indefinitely. Emit the event per row, covering both intercity (DOMESTIC) and IMPORT as the listener already expects.
This commit is contained in:
@@ -327,11 +327,19 @@ export class BookingJourneyService {
|
||||
RETURNING b.id, b.trade_direction`,
|
||||
[schedule.id, schedule.destinationStationId, now],
|
||||
);
|
||||
// Intercity rows just completed — let a ONE_TIME contract close on delivery.
|
||||
for (const row of rows) {
|
||||
// Intercity rows just completed — let a ONE_TIME contract close on delivery.
|
||||
if (row.trade_direction === 'DOMESTIC') {
|
||||
this.events.emit('booking.completed', { bookingId: row.id });
|
||||
}
|
||||
// Same event the per-booking unloadBooking() path emits — WarehouseInventoryService
|
||||
// listens for this to auto-create the warehouse_inventory row (import/intercity only,
|
||||
// it filters EXPORT itself). The bulk SQL update above skipped this entirely, so
|
||||
// bookings caught by this fallback never left "awaiting unload".
|
||||
this.events.emit('booking.unloadedAtYard', {
|
||||
bookingId: row.id,
|
||||
tradeDirection: row.trade_direction,
|
||||
});
|
||||
}
|
||||
return rows.map((r) => r.id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user