Replace wagon/locomotive readiness with yard tracking, assign unassigned bookings from origin-yard fleet, standardize rates on USD with CBE ETB conversion, and update fleet/scheduling UI

This commit is contained in:
marshal
2026-06-14 01:32:39 +03:00
parent b73bf2154e
commit 87b0ce6339
45 changed files with 1249 additions and 520 deletions

View File

@@ -1,4 +1,4 @@
import { WagonReadiness, WagonStatus } from '@edr/types';
import { WagonStatus } from '@edr/types';
import { IsString, IsUUID, IsOptional, IsInt, Min, IsNumber, IsEnum } from 'class-validator';
export class CreateWagonDto {
@@ -30,8 +30,8 @@ export class CreateWagonDto {
status?: WagonStatus;
@IsOptional()
@IsEnum(WagonReadiness)
readiness?: WagonReadiness;
@IsUUID()
currentYardId?: string;
@IsOptional()
@IsString()

View File

@@ -1,4 +1,4 @@
import { WagonReadiness, WagonStatus } from '@edr/types';
import { WagonStatus } from '@edr/types';
import { ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { IsEnum, IsInt, IsOptional, IsString, IsUUID, Max, Min } from 'class-validator';
@@ -14,10 +14,10 @@ export class ListWagonsQueryDto {
@IsEnum(WagonStatus)
status?: WagonStatus;
@ApiPropertyOptional({ enum: WagonReadiness })
@ApiPropertyOptional({ description: 'Filter by current yard' })
@IsOptional()
@IsEnum(WagonReadiness)
readiness?: WagonReadiness;
@IsUUID()
currentYardId?: string;
@ApiPropertyOptional()
@IsOptional()

View File

@@ -1,11 +1,12 @@
// apps/edr-freight-api/src/modules/wagons/entities/wagon.entity.ts
import { WagonReadiness, WagonStatus } from '@edr/types';
import { 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';
import { Yard } from '../../rule-engine/entities/yard.entity';
export const WAGON_STATUSES = [
WagonStatus.Available,
@@ -14,16 +15,10 @@ export const WAGON_STATUSES = [
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'])
@Index(['currentYardId'])
export class Wagon extends BaseEntity {
@Column({ unique: true, name: 'wagon_number' })
wagonNumber!: string;
@@ -46,8 +41,12 @@ export class Wagon extends BaseEntity {
@Column({ type: 'varchar', length: 20, default: WagonStatus.Available })
status!: WagonStatusType;
@Column({ type: 'varchar', length: 20, default: WagonReadiness.ImportReady })
readiness!: WagonReadinessType;
@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;
@Column({ type: 'text', nullable: true })
notes!: string | null;

View File

@@ -1,4 +1,4 @@
import { WagonReadiness, WagonStatus } from '@edr/types';
import { WagonStatus } from '@edr/types';
import { Injectable, NotFoundException, ConflictException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, DataSource, FindOptionsOrder, FindOptionsWhere, ILike } from 'typeorm';
@@ -24,11 +24,11 @@ export class WagonsService {
const wagon = this.wagonRepo.create({
...dto,
status: dto.status ?? WagonStatus.Available,
readiness: dto.readiness ?? WagonReadiness.ImportReady,
});
// Convert undefined to null for nullable fields
if (dto.trainId === undefined) wagon.trainId = null;
if (dto.sequenceNumber === undefined) wagon.sequenceNumber = null;
if (dto.currentYardId === undefined) wagon.currentYardId = null;
return this.wagonRepo.save(wagon);
}
@@ -39,7 +39,7 @@ export class WagonsService {
const wagonTypeId = query.wagonTypeId?.trim();
const filters: FindOptionsWhere<Wagon> = {
...(query.status ? { status: query.status } : {}),
...(query.readiness ? { readiness: query.readiness } : {}),
...(query.currentYardId ? { currentYardId: query.currentYardId } : {}),
...(trainId ? { trainId } : {}),
...(wagonTypeId ? { wagonTypeId } : {}),
};
@@ -51,13 +51,14 @@ export class WagonsService {
});
}
const sortBy = ['wagonNumber', 'tareWeight', 'maxPayloadWeight', 'status', 'readiness', 'sequenceNumber'].includes(query.sortBy ?? '')
const sortBy = ['wagonNumber', 'tareWeight', 'maxPayloadWeight', 'status', 'currentYardId', 'sequenceNumber'].includes(query.sortBy ?? '')
? (query.sortBy as keyof Wagon)
: 'wagonNumber';
const sortOrder = query.sortOrder?.toUpperCase() === 'DESC' ? 'DESC' : 'ASC';
return this.wagonRepo.find({
where: search ? where : filters,
relations: { currentYard: true },
order: { [sortBy]: sortOrder } as FindOptionsOrder<Wagon>,
skip: query.page && query.limit ? (Number(query.page) - 1) * Number(query.limit) : undefined,
take: query.limit ? Number(query.limit) : undefined,
@@ -65,7 +66,10 @@ export class WagonsService {
}
async findById(id: string): Promise<Wagon> {
const wagon = await this.wagonRepo.findOne({ where: { id } });
const wagon = await this.wagonRepo.findOne({
where: { id },
relations: { currentYard: true },
});
if (!wagon) throw new NotFoundException(`Wagon ${id} not found`);
return wagon;
}