mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 04:08:11 +00:00
train
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
// apps/edr-freight-api/src/modules/trains/entities/train.entity.ts
|
||||
import { BaseEntity } from '@edr/api-common';
|
||||
import { Freight } from '@edr/types';
|
||||
import { Column, Entity, OneToMany } from 'typeorm';
|
||||
import { Column, Entity, JoinColumn, ManyToOne, OneToMany } from 'typeorm';
|
||||
import { Yard } from '../../rule-engine/entities/yard.entity';
|
||||
import { Wagon } from '../../wagons/entities/wagon.entity';
|
||||
import { TrainLocomotive } from './train-locomotive.entity';
|
||||
|
||||
/**
|
||||
* Fleet master data — named wagon consist in inventory (POST /trains).
|
||||
* Operational departures use train_schedules + locomotives; scheduling never creates trains rows.
|
||||
* Fleet master data — a train built in the Train Builder: a coded consist
|
||||
* (e.g. 81001) of 2+ locomotives and ordered wagons, assembled in one yard.
|
||||
* Operational departures reference it through `train_sets.train_id`; the
|
||||
* schedule's own composition still lives on the train set.
|
||||
*/
|
||||
@Entity({ schema: 'freight', name: 'trains' })
|
||||
export class Train extends BaseEntity {
|
||||
@@ -56,7 +60,19 @@ export class Train extends BaseEntity {
|
||||
@Column({ name: 'remarks', type: 'text', nullable: true })
|
||||
remarks?: string;
|
||||
|
||||
/** Yard where the train currently sits (set at build, moved on schedule arrival). */
|
||||
@Column({ name: 'current_yard_id', type: 'uuid', nullable: true })
|
||||
currentYardId!: string | null;
|
||||
|
||||
@ManyToOne(() => Yard, { nullable: true, onDelete: 'SET NULL' })
|
||||
@JoinColumn({ name: 'current_yard_id' })
|
||||
currentYard?: Yard | null;
|
||||
|
||||
// --- relationships ---
|
||||
@OneToMany(() => Wagon, (wagon) => wagon.train)
|
||||
wagons!: Wagon[]; // fixed typo: was 'wagens'
|
||||
@OneToMany(() => Wagon, (wagon) => wagon.train)
|
||||
wagons!: Wagon[];
|
||||
|
||||
/** Locomotives pulling this train (minimum 2), ordered by sequenceNo. */
|
||||
@OneToMany(() => TrainLocomotive, (link) => link.train)
|
||||
locomotives?: TrainLocomotive[];
|
||||
}
|
||||
Reference in New Issue
Block a user