enhance contract clearance and train scheduling logic; add filters for clearance documents and improve booking validation

This commit is contained in:
Marshal
2026-07-13 21:40:10 +00:00
parent 3fe4ea72ac
commit 957a185a4d
5 changed files with 45 additions and 7 deletions

View File

@@ -26,6 +26,8 @@ export interface ContractListFilterOptions {
tradeDirection?: string;
paymentCurrency?: string;
customsClearingEnabled?: boolean;
/** true → only contracts with at least one uploaded clearance document. */
hasClearanceDocuments?: boolean;
createdFrom?: string;
createdTo?: string;
}
@@ -284,6 +286,12 @@ export class ContractsRepository extends BaseRepository<Contract> {
customsClearingEnabled: options.customsClearingEnabled,
});
}
if (options.hasClearanceDocuments) {
qb.andWhere(
'EXISTS (SELECT 1 FROM freight.contract_document_review cdr ' +
'WHERE cdr.contract_id = contract.id AND cdr.deleted_at IS NULL)',
);
}
if (options.serviceTypeId) {
qb.andWhere('contract.service_type_id = :serviceTypeId', {
serviceTypeId: options.serviceTypeId,