mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 18:48:11 +00:00
booking operations and trains scheduling also allocations
This commit is contained in:
@@ -1,10 +1,29 @@
|
||||
// apps/edr-freight-api/src/modules/wagons/entities/wagon.entity.ts
|
||||
import { Entity, Column, ManyToOne, OneToMany, JoinColumn } from 'typeorm';
|
||||
import { WagonReadiness, WagonStatus } from '@edr/types';
|
||||
import { Entity, Column, ManyToOne, OneToMany, JoinColumn, Index } from 'typeorm';
|
||||
import { BaseEntity } from '@edr/api-common';
|
||||
import { Train } from '../../trains/entities/train.entity';
|
||||
import { TrainSchedule } from '../../train-schedules/entities/train-schedule.entity';
|
||||
import { TrainSetWagon } from '../../train-sets/entities/train-set-wagon.entity';
|
||||
import { Container } from '../../container-management/entities/container.entity';
|
||||
|
||||
export const WAGON_STATUSES = [
|
||||
WagonStatus.Available,
|
||||
WagonStatus.Assigned,
|
||||
WagonStatus.Maintenance,
|
||||
WagonStatus.Retired,
|
||||
] as const;
|
||||
|
||||
export const WAGON_READINESS_VALUES = [
|
||||
WagonReadiness.ImportReady,
|
||||
WagonReadiness.ExportReady,
|
||||
] as const;
|
||||
|
||||
export type WagonStatusType = (typeof WAGON_STATUSES)[number];
|
||||
export type WagonReadinessType = (typeof WAGON_READINESS_VALUES)[number];
|
||||
|
||||
@Entity({ name: 'wagons', schema: 'freight' })
|
||||
@Index(['readiness'])
|
||||
export class Wagon extends BaseEntity {
|
||||
@Column({ unique: true, name: 'wagon_number' })
|
||||
wagonNumber!: string;
|
||||
@@ -24,13 +43,30 @@ export class Wagon extends BaseEntity {
|
||||
@Column({ name: 'max_payload_weight', type: 'decimal', precision: 10, scale: 2 })
|
||||
maxPayloadWeight!: number;
|
||||
|
||||
@Column({ type: 'varchar', default: 'AVAILABLE' })
|
||||
status!: string; // AVAILABLE, ASSIGNED, MAINTENANCE, RETIRED
|
||||
@Column({ type: 'varchar', length: 20, default: WagonStatus.Available })
|
||||
status!: WagonStatusType;
|
||||
|
||||
@Column({ type: 'varchar', length: 20, default: WagonReadiness.ImportReady })
|
||||
readiness!: WagonReadinessType;
|
||||
|
||||
@Column({ type: 'text', nullable: true })
|
||||
notes!: string | null;
|
||||
|
||||
// Relationship to Train
|
||||
@Column({ name: 'train_set_wagon_id', type: 'uuid', nullable: true })
|
||||
trainSetWagonId!: string | null;
|
||||
|
||||
@ManyToOne(() => TrainSetWagon, { nullable: true, onDelete: 'SET NULL' })
|
||||
@JoinColumn({ name: 'train_set_wagon_id' })
|
||||
trainSetWagon?: TrainSetWagon | null;
|
||||
|
||||
@Column({ name: 'current_train_schedule_id', type: 'uuid', nullable: true })
|
||||
currentTrainScheduleId!: string | null;
|
||||
|
||||
@ManyToOne(() => TrainSchedule, { nullable: true, onDelete: 'SET NULL' })
|
||||
@JoinColumn({ name: 'current_train_schedule_id' })
|
||||
currentTrainSchedule?: TrainSchedule | null;
|
||||
|
||||
/** Fleet master consist grouping — separate from operational train_schedules. */
|
||||
@ManyToOne(() => Train, (train) => train.wagons, { onDelete: 'SET NULL' })
|
||||
@JoinColumn({ name: 'train_id' })
|
||||
train!: Train | null;
|
||||
|
||||
Reference in New Issue
Block a user