mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 16:35:42 +00:00
add dispute functionality for contract duty and implement collection dates
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
|
||||
import { Contract } from './entities/contract.entity';
|
||||
import { INTERCITY_DOCUMENTS_SETTING_CODE } from '../bookings/clearance.util';
|
||||
|
||||
@@ -84,3 +86,47 @@ export function contractClearanceCodes(contract: Contract): {
|
||||
includesCustoms,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Djibouti GL cannot record a Delivery Order without saying WHEN the vessel
|
||||
* arrived and WHEN the DO was collected — the file alone leaves the import
|
||||
* timeline unauditable. Shared by the contract and per-booking DO uploads so
|
||||
* one endpoint can never be laxer than the other.
|
||||
*
|
||||
* Returns the normalized `YYYY-MM-DD` pair; throws if either is missing,
|
||||
* unparseable, or the DO predates the vessel's arrival.
|
||||
*/
|
||||
export function assertDoCollectionDates(dates?: {
|
||||
vesselArrivalDate?: string;
|
||||
doCollectedDate?: string;
|
||||
}): { vesselArrivalDate: string; doCollectedDate: string } {
|
||||
const vesselArrivalDate = normalizeDoDate(
|
||||
dates?.vesselArrivalDate,
|
||||
'Vessel arrival date',
|
||||
);
|
||||
const doCollectedDate = normalizeDoDate(
|
||||
dates?.doCollectedDate,
|
||||
'DO collected date',
|
||||
);
|
||||
|
||||
if (doCollectedDate < vesselArrivalDate) {
|
||||
throw new BadRequestException(
|
||||
'DO collected date cannot be earlier than the vessel arrival date.',
|
||||
);
|
||||
}
|
||||
|
||||
return { vesselArrivalDate, doCollectedDate };
|
||||
}
|
||||
|
||||
/** `YYYY-MM-DD` or throw — the column is a DATE, so time zones never enter. */
|
||||
function normalizeDoDate(value: string | undefined, label: string): string {
|
||||
const trimmed = value?.trim();
|
||||
if (!trimmed) {
|
||||
throw new BadRequestException(`${label} is required to upload a Delivery Order.`);
|
||||
}
|
||||
const date = trimmed.slice(0, 10);
|
||||
if (!/^\d{4}-\d{2}-\d{2}$/.test(date) || Number.isNaN(Date.parse(date))) {
|
||||
throw new BadRequestException(`${label} is not a valid date.`);
|
||||
}
|
||||
return date;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user