Batch 1 to 3 implementation

This commit is contained in:
hagiye
2026-06-16 11:36:24 +03:00
parent c2b5b3b926
commit f5d6d8e7da
26 changed files with 50 additions and 1250 deletions

View File

@@ -30,17 +30,12 @@ export class CreateWagonDto {
maxPayloadWeight!: number;
@IsOptional()
<<<<<<< HEAD
@IsIn(['AVAILABLE', 'IMPORT_READY', 'EXPORT_READY', 'ASSIGNED', 'MAINTENANCE', 'RETIRED'])
status?: string;
=======
@IsEnum(WagonStatus)
status?: WagonStatus;
@IsOptional()
@IsEnum(WagonReadiness)
readiness?: WagonReadiness;
>>>>>>> 10b011de8feafce5c0bae21594df5b36596587db
@IsOptional()
@IsString()

View File

@@ -12,6 +12,8 @@ import { WagonType } from '../../wagon-types/entities/wagon-type.entity';
export const WAGON_STATUSES = [
WagonStatus.Available,
WagonStatus.Assigned,
WagonStatus.ImportReady,
WagonStatus.ExportReady,
WagonStatus.Maintenance,
WagonStatus.Retired,
] as const;
@@ -56,16 +58,11 @@ export class Wagon extends BaseEntity {
@Column({ name: 'max_payload_weight', type: 'decimal', precision: 10, scale: 2 })
maxPayloadWeight!: number;
<<<<<<< HEAD
@Column({ type: 'varchar', default: 'AVAILABLE' })
status!: string; // AVAILABLE, IMPORT_READY, EXPORT_READY, ASSIGNED, MAINTENANCE, RETIRED
=======
@Column({ type: 'varchar', length: 20, default: WagonStatus.Available })
status!: WagonStatusType;
@Column({ type: 'varchar', length: 20, default: WagonReadiness.ImportReady })
readiness!: WagonReadinessType;
>>>>>>> 10b011de8feafce5c0bae21594df5b36596587db
@Column({ type: 'text', nullable: true })
notes!: string | null;
@@ -84,7 +81,7 @@ export class Wagon extends BaseEntity {
@JoinColumn({ name: 'current_train_schedule_id' })
currentTrainSchedule?: TrainSchedule | null;
/** Fleet master consist grouping separate from operational train_schedules. */
/** Fleet master consist grouping — separate from operational train_schedules. */
@ManyToOne(() => Train, (train) => train.wagons, { onDelete: 'SET NULL' })
@JoinColumn({ name: 'train_id' })
train!: Train | null;

View File

@@ -41,26 +41,16 @@ export class WagonsService {
const status = query.status?.trim();
const readiness = query.readiness?.trim();
const trainId = query.trainId?.trim();
<<<<<<< HEAD
const currentLocationYardId = query.currentLocationYardId?.trim();
=======
const filters = {
...(status ? { status: status as Wagon['status'] } : {}),
...(readiness ? { readiness: readiness as Wagon['readiness'] } : {}),
...(trainId ? { trainId } : {}),
};
>>>>>>> 10b011de8feafce5c0bae21594df5b36596587db
if (search) {
where.push({
wagonNumber: ILike(`%${search}%`),
<<<<<<< HEAD
...(status ? { status } : {}),
...(trainId ? { trainId } : {}),
...(currentLocationYardId ? { currentLocationYardId } : {}),
=======
...filters,
>>>>>>> 10b011de8feafce5c0bae21594df5b36596587db
});
}
@@ -70,12 +60,7 @@ export class WagonsService {
const sortOrder = query.sortOrder?.toUpperCase() === 'DESC' ? 'DESC' : 'ASC';
return this.wagonRepo.find({
<<<<<<< HEAD
where: search ? where : { ...(status ? { status } : {}), ...(trainId ? { trainId } : {}), ...(currentLocationYardId ? { currentLocationYardId } : {}) },
relations: { currentLocationYard: true, wagonType: true },
=======
where: search ? where : filters,
>>>>>>> 10b011de8feafce5c0bae21594df5b36596587db
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,
@@ -131,22 +116,23 @@ export class WagonsService {
const wagon = await this.findById(wagonId);
wagon.trainId = null;
wagon.sequenceNumber = null;
<<<<<<< HEAD
wagon.status = await this.statusForLocation(wagon.currentLocationYardId, 'AVAILABLE');
=======
wagon.status = WagonStatus.Available;
>>>>>>> 10b011de8feafce5c0bae21594df5b36596587db
return this.wagonRepo.save(wagon);
}
private async statusForLocation(yardId?: string | null, fallback = 'AVAILABLE') {
private async statusForLocation(
yardId?: string | null,
fallback: Wagon['status'] = WagonStatus.Available,
): Promise<Wagon['status']> {
if (!yardId) return fallback;
const yard = await this.yardRepo.findOne({ where: { id: yardId } });
const country = yard?.country?.trim().toLowerCase();
if (country === 'ethiopia' || country === 'et') return 'EXPORT_READY';
if (country === 'djibouti' || country === 'djoubti' || country === 'dj') return 'IMPORT_READY';
if (country === 'ethiopia' || country === 'et') return WagonStatus.ExportReady;
if (country === 'djibouti' || country === 'djoubti' || country === 'dj') {
return WagonStatus.ImportReady;
}
return fallback;
}