Merge pull request #738 from Tria-plc/freight_feature/usermanagement

fix issue
This commit is contained in:
marshal
2026-07-16 16:00:07 +03:00
committed by GitHub
6 changed files with 160 additions and 12 deletions

View File

@@ -204,17 +204,27 @@ export class ContractsRepository extends BaseRepository<Contract> {
private async attachClearancePhases(contracts: Contract[]): Promise<void> {
if (contracts.length === 0) return;
const ids = contracts.map((c) => c.id);
const rows: Array<{ contract_id: string; current_phase: string | null }> =
await this.dataSource.query(
`SELECT DISTINCT ON (contract_id) contract_id, current_phase
FROM freight.contract_clearance_cycles
WHERE contract_id = ANY($1)
ORDER BY contract_id, cycle_number DESC`,
[ids],
);
const byContract = new Map(rows.map((r) => [r.contract_id, r.current_phase]));
const rows: Array<{
contract_id: string;
current_phase: string | null;
booking_id: string | null;
booking_status: string | null;
}> = await this.dataSource.query(
`SELECT DISTINCT ON (ccc.contract_id)
ccc.contract_id, ccc.current_phase,
b.id AS booking_id, b.status AS booking_status
FROM freight.contract_clearance_cycles ccc
LEFT JOIN freight.bookings b ON b.id = ccc.booking_id
WHERE ccc.contract_id = ANY($1)
ORDER BY ccc.contract_id, ccc.cycle_number DESC`,
[ids],
);
const byContract = new Map(rows.map((r) => [r.contract_id, r]));
for (const contract of contracts) {
contract.clearancePhase = byContract.get(contract.id) ?? null;
const row = byContract.get(contract.id);
contract.clearancePhase = row?.current_phase ?? null;
contract.latestCycleBookingId = row?.booking_id ?? null;
contract.latestCycleBookingStatus = row?.booking_status ?? null;
}
}

View File

@@ -312,6 +312,14 @@ export class Contract extends BaseEntity {
*/
clearancePhase?: string | null;
/**
* Latest clearance cycle's linked booking (id + status), attached alongside
* clearancePhase. Lets the GL queue tell an expired (unpaid) booking apart
* from a live one so it can offer a rebook. Not columns.
*/
latestCycleBookingId?: string | null;
latestCycleBookingStatus?: string | null;
/**
* Body of the most recent CHANGES_REQUESTED review note, attached by
* ContractsService.findById so the portal can show the customer what staff