feat: complete train scheduling integration

This commit is contained in:
hagiye
2026-06-06 05:52:47 +03:00
parent 29247d4140
commit 788de5381e
56 changed files with 1191 additions and 141 deletions

View File

@@ -2,13 +2,14 @@ import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Cargo } from './entities/cargoes.entity';
import { Container } from '../container-management/entities/container.entity';
import { CargoType } from '../rule-engine/entities/cargo-type.entity';
import { CargoesController } from './cargoes.controller';
import { CargoesService } from './cargoes.service';
@Module({
imports: [TypeOrmModule.forFeature([Cargo, Container])],
imports: [TypeOrmModule.forFeature([Cargo, Container, CargoType])],
controllers: [CargoesController],
providers: [CargoesService],
exports: [CargoesService],
})
export class CargoesModule {}
export class CargoesModule {}

View File

@@ -7,6 +7,7 @@ import { LoadCargoDto } from './dto/load-cargo.dto';
import { DeliverCargoDto } from './dto/deliver-cargo.dto';
import { Cargo } from './entities/cargoes.entity';
import { Container } from '../container-management/entities/container.entity';
import { CargoType } from '../rule-engine/entities/cargo-type.entity';
@Injectable()
export class CargoesService {
@@ -15,9 +16,30 @@ export class CargoesService {
private readonly cargoRepo: Repository<Cargo>,
@InjectRepository(Container)
private readonly containerRepo: Repository<Container>,
@InjectRepository(CargoType)
private readonly cargoTypeRepo: Repository<CargoType>,
) {}
async create(dto: CreateCargoDto): Promise<Cargo> {
const existing = await this.cargoRepo.findOne({
where: { cargoReference: dto.cargoReference },
});
if (existing) {
throw new ConflictException(`Cargo reference "${dto.cargoReference}" already exists`);
}
const container = await this.containerRepo.findOne({ where: { id: dto.containerId } });
if (!container) {
throw new NotFoundException(`Container ${dto.containerId} not found`);
}
if (dto.cargoTypeId) {
const cargoType = await this.cargoTypeRepo.findOne({
where: { id: dto.cargoTypeId, isActive: true },
});
if (!cargoType) throw new NotFoundException(`Cargo type ${dto.cargoTypeId} not found`);
}
const cargo = this.cargoRepo.create(dto);
return this.cargoRepo.save(cargo);
}
@@ -62,6 +84,24 @@ export class CargoesService {
async update(id: string, dto: UpdateCargoDto): Promise<Cargo> {
const cargo = await this.findById(id);
if (dto.cargoReference && dto.cargoReference !== cargo.cargoReference) {
const existing = await this.cargoRepo.findOne({
where: { cargoReference: dto.cargoReference },
});
if (existing) {
throw new ConflictException(`Cargo reference "${dto.cargoReference}" already exists`);
}
}
if (dto.containerId) {
const container = await this.containerRepo.findOne({ where: { id: dto.containerId } });
if (!container) throw new NotFoundException(`Container ${dto.containerId} not found`);
}
if (dto.cargoTypeId) {
const cargoType = await this.cargoTypeRepo.findOne({
where: { id: dto.cargoTypeId, isActive: true },
});
if (!cargoType) throw new NotFoundException(`Cargo type ${dto.cargoTypeId} not found`);
}
Object.assign(cargo, dto);
return this.cargoRepo.save(cargo);
}