add booking request functionality for GENERAL customs contracts

- Create migration for booking_requests table with necessary fields and indexes.
- Implement BookingRequestRepository for database operations related to booking requests.
- Develop BookingRequestService to handle business logic for submitting, accepting, rejecting, and canceling booking requests.
- Create DTOs for creating booking requests and reviewing them.
- Define BookingRequest entity to map to the booking_requests table.
- Add UI components for managing shipment requests, including detail and list pages.
- Implement OperationDatePicker component for selecting available shipment days.
This commit is contained in:
Marshal
2026-06-29 09:30:44 +00:00
parent aeb5e0046e
commit 0f7cac2b68
46 changed files with 2665 additions and 992 deletions

View File

@@ -0,0 +1,55 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
/**
* Seeds the admin-configurable "contract validity periods" setting (days). Stored
* as a dropdown_settings row whose options each hold a day count in `value`, so
* backoffice manages them through the existing Dropdown Settings UI and the
* contract staff-accept dialog only offers the configured durations.
*/
export class SeedContractValidityPeriods1792000000004
implements MigrationInterface
{
name = 'SeedContractValidityPeriods1792000000004';
private readonly code = 'contract_validity_periods';
private readonly options: Array<{ value: string; label: string }> = [
{ value: '180', label: '6 months' },
{ value: '365', label: '1 year' },
{ value: '730', label: '2 years' },
];
public async up(queryRunner: QueryRunner): Promise<void> {
const existing = await queryRunner.query(
`SELECT id FROM freight.dropdown_settings WHERE code = $1 LIMIT 1;`,
[this.code],
);
if (existing.length > 0) return;
const inserted = await queryRunner.query(
`INSERT INTO freight.dropdown_settings (code, label, description, multiple)
VALUES ($1, $2, $3, false)
RETURNING id;`,
[
this.code,
'Contract Validity Periods (days)',
'Validity durations (in days) a staff can choose when accepting a submitted contract.',
],
);
const settingId = inserted[0].id;
for (let i = 0; i < this.options.length; i++) {
const opt = this.options[i];
await queryRunner.query(
`INSERT INTO freight.dropdown_options (setting_id, value, label, display_order)
VALUES ($1, $2, $3, $4);`,
[settingId, opt.value, opt.label, i],
);
}
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DELETE FROM freight.dropdown_settings WHERE code = $1;`,
[this.code],
);
}
}

View File

@@ -0,0 +1,75 @@
import { MigrationInterface, QueryRunner, Table, TableIndex } from 'typeorm';
/**
* Customer shipment requests for GENERAL customs (Path B) contracts. The customer
* submits date + quantities; Global Logistics reviews, then creates the booking
* on their behalf and per-booking clearance begins. Additive — no change to
* existing tables; ONE_TIME contracts are unaffected.
*/
export class CreateBookingRequests1827000000000 implements MigrationInterface {
name = 'CreateBookingRequests1827000000000';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
schema: 'freight',
name: 'booking_requests',
columns: [
{ name: 'id', type: 'uuid', isPrimary: true, generationStrategy: 'uuid', default: 'gen_random_uuid()' },
{ name: 'reference', type: 'varchar', length: '40', default: "''" },
{ name: 'contract_id', type: 'uuid' },
{ name: 'requested_by_user_id', type: 'uuid', isNullable: true },
{ name: 'contract_route_id', type: 'uuid', isNullable: true },
{ name: 'scheduled_date', type: 'timestamptz', isNullable: true },
{ name: 'status', type: 'varchar', length: '16', default: "'PENDING'" },
{ name: 'requested_lines', type: 'jsonb', default: "'{}'::jsonb" },
{ name: 'notes', type: 'text', isNullable: true },
{ name: 'created_booking_id', type: 'uuid', isNullable: true },
{ name: 'reviewed_by_staff_id', type: 'uuid', isNullable: true },
{ name: 'reviewed_at', type: 'timestamptz', isNullable: true },
{ name: 'review_note', type: 'text', isNullable: true },
{ name: 'created_at', type: 'timestamptz', default: 'now()' },
{ name: 'updated_at', type: 'timestamptz', default: 'now()' },
{ name: 'deleted_at', type: 'timestamptz', isNullable: true },
],
foreignKeys: [
{
columnNames: ['contract_id'],
referencedSchema: 'freight',
referencedTableName: 'contracts',
referencedColumnNames: ['id'],
onDelete: 'CASCADE',
},
{
columnNames: ['created_booking_id'],
referencedSchema: 'freight',
referencedTableName: 'bookings',
referencedColumnNames: ['id'],
onDelete: 'SET NULL',
},
],
}),
true,
);
await queryRunner.createIndex(
'freight.booking_requests',
new TableIndex({ name: 'idx_booking_requests_contract', columnNames: ['contract_id'] }),
);
await queryRunner.createIndex(
'freight.booking_requests',
new TableIndex({ name: 'idx_booking_requests_status', columnNames: ['status'] }),
);
await queryRunner.createIndex(
'freight.booking_requests',
new TableIndex({
name: 'idx_booking_requests_contract_status',
columnNames: ['contract_id', 'status'],
}),
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('freight.booking_requests', true);
}
}