trains, wagons,containers and cargoes schema and API

This commit is contained in:
hagiye
2026-06-04 15:56:29 +03:00
parent 18015ceaff
commit 71ac89edc7
66 changed files with 2077 additions and 90 deletions

View File

@@ -0,0 +1,41 @@
// apps/edr-freight-api/src/modules/wagons/entities/wagon.entity.ts
import { Entity, Column, ManyToOne, OneToMany, JoinColumn } from 'typeorm';
import { BaseEntity } from '@edr/api-common';
import { Train } from '../../trains/entities/train.entity';
import { Container } from '../../container-management/entities/container.entity';
@Entity({ name: 'wagons', schema: 'freight' })
export class Wagon extends BaseEntity {
@Column({ unique: true, name: 'wagon_number' })
wagonNumber!: string;
@Column({ name: 'wagon_type_id', type: 'uuid' })
wagonTypeId!: string;
@Column({ name: 'train_id', type: 'uuid', nullable: true })
trainId!: string | null;
@Column({ name: 'sequence_number', type: 'int', nullable: true })
sequenceNumber!: number | null;
@Column({ name: 'tare_weight', type: 'decimal', precision: 10, scale: 2 })
tareWeight!: number;
@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: 'text', nullable: true })
notes!: string | null;
// Relationship to Train
@ManyToOne(() => Train, (train) => train.wagons, { onDelete: 'SET NULL' })
@JoinColumn({ name: 'train_id' })
train!: Train | null;
// Relationship to Container
@OneToMany(() => Container, (container) => container.wagon)
containers!: Container[];
}