feat(train): enhance train history and scheduling features

- Added a reason field to train history entries for detach/maintenance actions.
- Updated TrainHistoryPanel to display the reason for wagon detachments.
- Introduced per-wagon load/unload functionality in ScheduleWorkspacePanel with a modal for managing individual wagons.
- Implemented API endpoints for loading and unloading specific wagons, including the ability to cancel remaining wagons with a reason.
- Refactored detach request handling in TrainBuilderDetailPage to streamline the process and remove the approval flow, requiring a reason for detachments.
- Updated types and services to support new wagon loading/unloading features and booking wagon retrieval.
This commit is contained in:
Marshal
2026-08-28 07:33:28 +00:00
parent 8b8870e85e
commit ba56974e32
26 changed files with 1435 additions and 583 deletions

View File

@@ -0,0 +1,65 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
/**
* Per-wagon loading. Staff may confirm loading wagon-by-wagon instead of the
* whole booking at once:
* - bookings.loading_started_at — first wagon loaded; the booking stays PAID
* until every remaining wagon is LOADED (remaining = allocated cancelled).
* Also shields a mid-load booking from the dispatch "left behind" unassign.
* - wagon_booking_allocations.loaded_at / loaded_by_user_id — per-wagon
* confirmation audit.
* - booking_wagon_cancellations.fault — who caused an at-loading cancel of
* the never-loaded remainder: CUSTOMER (fee applies) or EDR (no fee, credit
* rebookable in full).
*/
export class PerWagonLoading3760000000000 implements MigrationInterface {
name = 'PerWagonLoading3760000000000';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE freight.bookings
ADD COLUMN IF NOT EXISTS loading_started_at timestamptz`,
);
await queryRunner.query(
`ALTER TABLE freight.wagon_booking_allocations
ADD COLUMN IF NOT EXISTS loaded_at timestamptz`,
);
await queryRunner.query(
`ALTER TABLE freight.wagon_booking_allocations
ADD COLUMN IF NOT EXISTS loaded_by_user_id uuid`,
);
await queryRunner.query(
`ALTER TABLE freight.wagon_booking_allocations
ADD COLUMN IF NOT EXISTS unloaded_at timestamptz`,
);
await queryRunner.query(
`ALTER TABLE freight.wagon_booking_allocations
ADD COLUMN IF NOT EXISTS unloaded_by_user_id uuid`,
);
await queryRunner.query(
`ALTER TABLE freight.booking_wagon_cancellations
ADD COLUMN IF NOT EXISTS fault varchar(16)`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE freight.booking_wagon_cancellations DROP COLUMN IF EXISTS fault`,
);
await queryRunner.query(
`ALTER TABLE freight.wagon_booking_allocations DROP COLUMN IF EXISTS loaded_by_user_id`,
);
await queryRunner.query(
`ALTER TABLE freight.wagon_booking_allocations DROP COLUMN IF EXISTS unloaded_by_user_id`,
);
await queryRunner.query(
`ALTER TABLE freight.wagon_booking_allocations DROP COLUMN IF EXISTS unloaded_at`,
);
await queryRunner.query(
`ALTER TABLE freight.wagon_booking_allocations DROP COLUMN IF EXISTS loaded_at`,
);
await queryRunner.query(
`ALTER TABLE freight.bookings DROP COLUMN IF EXISTS loading_started_at`,
);
}
}

View File

@@ -0,0 +1,27 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
/**
* Why a wagon left (or joined) the consist, on the adjustment log itself.
*
* SCHEDULED-run detach / send-to-maintenance now requires a reason instead of
* a second staffer's approval, so the reason has to read back where the change
* reads back: the train-builder History tab. Nullable — every other writer
* (trip cuts, couples, arrival returns) keeps logging without one.
*/
export class WagonAdjustmentReason3770000000000 implements MigrationInterface {
name = 'WagonAdjustmentReason3770000000000';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE freight.schedule_wagon_adjustment_logs
ADD COLUMN IF NOT EXISTS reason varchar(500)`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE freight.schedule_wagon_adjustment_logs
DROP COLUMN IF EXISTS reason`,
);
}
}