feat: implement manual consolidation candidate selection logic and update related tests

This commit is contained in:
marshalyordanos
2026-09-04 13:52:19 +03:00
parent eaa006a932
commit ca84aac456
6 changed files with 210 additions and 93 deletions

View File

@@ -660,24 +660,25 @@ export class ContractBookingService {
const rows = await this.bookingsRepository.findManualConsolidationCandidates(
booking,
);
return rows.map((row) => {
const lines = row.bookingContainers ?? [];
return {
id: row.id,
reference: row.reference,
contractId: row.contractId ?? null,
companyName: row.company?.name ?? null,
status: row.status,
tradeDirection: row.tradeDirection ?? null,
originYardId: row.originYardId ?? null,
destinationYardId: row.destinationYardId ?? null,
scheduledDate: row.scheduledDate ? row.scheduledDate.toISOString() : null,
ft20Quantity: lines
.filter((line) => Number(line.containerType?.sizeFt) === 20)
.reduce((sum, line) => sum + Number(line.quantity || 0), 0),
hasCargo: lines.length > 0,
};
});
// ft20Quantity comes back from the repository already resolved — persisted
// container lines when the booking has them, otherwise the quantities its
// booking request was accepted with. Recomputing it here from
// bookingContainers would report 0 for every not-yet-completed booking.
return rows.map(({ booking: row, ft20Quantity }) => ({
id: row.id,
reference: row.reference,
contractId: row.contractId ?? null,
companyName: row.company?.name ?? null,
status: row.status,
tradeDirection: row.tradeDirection ?? null,
originYardId: row.originYardId ?? null,
destinationYardId: row.destinationYardId ?? null,
scheduledDate: row.scheduledDate ? row.scheduledDate.toISOString() : null,
ft20Quantity,
// Cargo is known — from either source — since a candidate with an unknown
// count is never offered.
hasCargo: true,
}));
}
/**