mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 08:48:11 +00:00
feat(freight): basics of train scheduling
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import { BaseEntity } from '@edr/api-common';
|
||||
import { Column, Entity, Index, JoinColumn, ManyToOne, OneToMany } from 'typeorm';
|
||||
|
||||
import { WagonBookingAllocation } from '../../train-schedules/entities/wagon-booking-allocation.entity';
|
||||
import { WagonType } from '../../wagon-types/entities/wagon-type.entity';
|
||||
import { TrainSet } from './train-set.entity';
|
||||
|
||||
@Entity({ schema: 'freight', name: 'train_set_wagons' })
|
||||
@Index(['trainSetId', 'sequenceNo'], { unique: true })
|
||||
export class TrainSetWagon extends BaseEntity {
|
||||
@Column({ name: 'train_set_id', type: 'uuid' })
|
||||
trainSetId!: string;
|
||||
|
||||
@ManyToOne(() => TrainSet, (trainSet) => trainSet.wagons, { onDelete: 'CASCADE' })
|
||||
@JoinColumn({ name: 'train_set_id' })
|
||||
trainSet?: TrainSet;
|
||||
|
||||
@Column({ name: 'wagon_type_id', type: 'uuid' })
|
||||
wagonTypeId!: string;
|
||||
|
||||
@ManyToOne(() => WagonType, (wagonType) => wagonType.trainSetWagons)
|
||||
@JoinColumn({ name: 'wagon_type_id' })
|
||||
wagonType?: WagonType;
|
||||
|
||||
@Column({ name: 'sequence_no', type: 'int' })
|
||||
sequenceNo!: number;
|
||||
|
||||
@Column({ name: 'capacity_tons', type: 'numeric', precision: 10, scale: 3 })
|
||||
capacityTons!: number;
|
||||
|
||||
@Column({ name: 'length_meters', type: 'numeric', precision: 10, scale: 3 })
|
||||
lengthMeters!: number;
|
||||
|
||||
@Column({ name: 'assigned_weight_tons', type: 'numeric', precision: 10, scale: 3, default: 0 })
|
||||
assignedWeightTons!: number;
|
||||
|
||||
@OneToMany(() => WagonBookingAllocation, (allocation) => allocation.trainSetWagon)
|
||||
allocations?: WagonBookingAllocation[];
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { BaseEntity } from '@edr/api-common';
|
||||
import { Column, Entity, Index, JoinColumn, ManyToOne, OneToMany, OneToOne } from 'typeorm';
|
||||
|
||||
import { Locomotive } from '../../locomotives/entities/locomotive.entity';
|
||||
import { TrainSchedule } from '../../train-schedules/entities/train-schedule.entity';
|
||||
import { TrainSetWagon } from './train-set-wagon.entity';
|
||||
|
||||
export const TRAIN_SET_STATUSES = [
|
||||
'DRAFT',
|
||||
'ASSIGNED',
|
||||
'DISPATCHED',
|
||||
'COMPLETED',
|
||||
'CANCELLED',
|
||||
] as const;
|
||||
|
||||
export type TrainSetStatus = (typeof TRAIN_SET_STATUSES)[number];
|
||||
|
||||
@Entity({ schema: 'freight', name: 'train_sets' })
|
||||
@Index(['locomotiveId'])
|
||||
@Index(['status'])
|
||||
export class TrainSet extends BaseEntity {
|
||||
@Column({ name: 'locomotive_id', type: 'uuid' })
|
||||
locomotiveId!: string;
|
||||
|
||||
@ManyToOne(() => Locomotive, (locomotive) => locomotive.trainSets)
|
||||
@JoinColumn({ name: 'locomotive_id' })
|
||||
locomotive?: Locomotive;
|
||||
|
||||
@Column({ name: 'total_weight_tons', type: 'numeric', precision: 10, scale: 3 })
|
||||
totalWeightTons!: number;
|
||||
|
||||
@Column({ name: 'total_length_meters', type: 'numeric', precision: 10, scale: 3 })
|
||||
totalLengthMeters!: number;
|
||||
|
||||
@Column({ name: 'wagon_count', type: 'int' })
|
||||
wagonCount!: number;
|
||||
|
||||
@Column({ name: 'status', type: 'varchar', length: 20, default: 'DRAFT' })
|
||||
status!: TrainSetStatus;
|
||||
|
||||
@OneToMany(() => TrainSetWagon, (wagon) => wagon.trainSet)
|
||||
wagons?: TrainSetWagon[];
|
||||
|
||||
@OneToOne(() => TrainSchedule, (schedule) => schedule.trainSet)
|
||||
trainSchedule?: TrainSchedule;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { BaseRepository } from '@edr/api-common';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { TrainSetWagon } from './entities/train-set-wagon.entity';
|
||||
|
||||
@Injectable()
|
||||
export class TrainSetWagonsRepository extends BaseRepository<TrainSetWagon> {
|
||||
constructor(
|
||||
@InjectRepository(TrainSetWagon)
|
||||
repository: Repository<TrainSetWagon>,
|
||||
) {
|
||||
super(repository);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
import { TrainSet } from './entities/train-set.entity';
|
||||
import { TrainSetWagon } from './entities/train-set-wagon.entity';
|
||||
import { TrainSetWagonsRepository } from './train-set-wagons.repository';
|
||||
import { TrainSetsRepository } from './train-sets.repository';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([TrainSet, TrainSetWagon])],
|
||||
providers: [TrainSetsRepository, TrainSetWagonsRepository],
|
||||
exports: [TrainSetsRepository, TrainSetWagonsRepository],
|
||||
})
|
||||
export class TrainSetsModule {}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { BaseRepository } from '@edr/api-common';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { TrainSet } from './entities/train-set.entity';
|
||||
|
||||
@Injectable()
|
||||
export class TrainSetsRepository extends BaseRepository<TrainSet> {
|
||||
constructor(
|
||||
@InjectRepository(TrainSet)
|
||||
repository: Repository<TrainSet>,
|
||||
) {
|
||||
super(repository);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user