feat(warehouse): fetch all PAID bookings in one call, classified IMPORT/EXPORT by route

- eligibleBookings(direction?) now returns all import+export bookings when direction omitted
  (DOMESTIC excluded); per-direction filter preserved for backward compatibility
- GET /warehouse-inventory/eligible-bookings (no query) returns the combined set
- Frontend: single shared useEligibleBookings() query; both Receive tabs filter client-side
  by route-derived direction, so only one HTTP request fires

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Hagernesh
2026-06-20 20:15:26 +00:00
parent 0ab508e377
commit a8bc5b19de
6 changed files with 28 additions and 12 deletions

View File

@@ -61,9 +61,10 @@ export class WarehouseInventoryController {
}
@Get('eligible-bookings')
@ApiOperation({ summary: 'Eligible PAID bookings for a direction (IMPORT/EXPORT) not yet received' })
eligibleBookings(@Query('direction') direction: 'IMPORT' | 'EXPORT') {
return this.inventoryService.eligibleBookings(direction === 'EXPORT' ? 'EXPORT' : 'IMPORT');
@ApiOperation({ summary: 'PAID bookings not yet received, classified IMPORT/EXPORT by route; omit direction for all' })
eligibleBookings(@Query('direction') direction?: string) {
const dir = direction === 'IMPORT' || direction === 'EXPORT' ? direction : undefined;
return this.inventoryService.eligibleBookings(dir);
}
@Post('receive-bulk')

View File

@@ -468,8 +468,12 @@ export class WarehouseInventoryService {
// ── Receive (Import/Export bulk) ───────────────────────────────────────────
/** Eligible PAID bookings for a direction (DERIVED FROM ROUTE) that have NOT been received yet. */
async eligibleBookings(direction: 'IMPORT' | 'EXPORT'): Promise<EligibleBookingRow[]> {
/**
* Eligible PAID bookings that have NOT been received yet, classified IMPORT/EXPORT by route
* (origin/destination yard countries). Pass a direction to filter to one; omit it to return
* all import + export bookings in a single call (DOMESTIC routes are excluded either way).
*/
async eligibleBookings(direction?: 'IMPORT' | 'EXPORT'): Promise<EligibleBookingRow[]> {
const rows: Array<
EligibleBookingRow & { originCountry: string | null; destinationCountry: string | null }
> = await this.dataSource.query(
@@ -504,7 +508,9 @@ export class WarehouseInventoryService {
...r,
direction: deriveTradeDirection({ country: r.originCountry }, { country: r.destinationCountry }),
}))
.filter((r) => r.direction === direction);
.filter((r) =>
direction ? r.direction === direction : r.direction === 'IMPORT' || r.direction === 'EXPORT',
);
}
/** Bulk-receive eligible PAID bookings into a location. Skips duplicates / wrong direction. */