mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-01 05:27:39 +00:00
Loading queque changes
This commit is contained in:
@@ -65,52 +65,64 @@ export class IndodeFacilitySeeder {
|
||||
constructor(private readonly dataSource: DataSource) {}
|
||||
|
||||
async run(): Promise<void> {
|
||||
await this.dataSource.transaction(async (manager) => {
|
||||
const facilityRepo = manager.getRepository(Facility);
|
||||
const warehouseRepo = manager.getRepository(Warehouse);
|
||||
const yardRepo = manager.getRepository(WarehouseYard);
|
||||
const zoneRepo = manager.getRepository(WarehouseZone);
|
||||
try {
|
||||
await this.dataSource.transaction(async (manager) => {
|
||||
const facilityRepo = manager.getRepository(Facility);
|
||||
const warehouseRepo = manager.getRepository(Warehouse);
|
||||
const yardRepo = manager.getRepository(WarehouseYard);
|
||||
const zoneRepo = manager.getRepository(WarehouseZone);
|
||||
|
||||
// Ensure facility exists
|
||||
const facility = await facilityRepo.findOne({
|
||||
where: { code: INDODE_FACILITY.code },
|
||||
});
|
||||
|
||||
if (facility) {
|
||||
this.logger.log('Indode facility already exists, skipping seed');
|
||||
return;
|
||||
}
|
||||
|
||||
const newFacility = facilityRepo.create(INDODE_FACILITY);
|
||||
const savedFacility = await facilityRepo.save(newFacility);
|
||||
this.logger.log(`Created facility: ${savedFacility.code}`);
|
||||
|
||||
// Create warehouses for the facility
|
||||
for (const warehouseData of WAREHOUSES) {
|
||||
const warehouse = await warehouseRepo.findOne({
|
||||
where: { code: warehouseData.code },
|
||||
// Ensure facility exists
|
||||
const facility = await facilityRepo.findOne({
|
||||
where: { code: INDODE_FACILITY.code },
|
||||
});
|
||||
|
||||
if (warehouse) {
|
||||
this.logger.log(`Warehouse ${warehouseData.code} already exists, skipping`);
|
||||
continue;
|
||||
if (facility) {
|
||||
this.logger.log('Indode facility already exists, skipping seed');
|
||||
return;
|
||||
}
|
||||
|
||||
const newWarehouse = warehouseRepo.create({
|
||||
...warehouseData,
|
||||
facilityId: savedFacility.id,
|
||||
});
|
||||
const savedWarehouse = await warehouseRepo.save(newWarehouse);
|
||||
this.logger.log(`Created warehouse: ${savedWarehouse.code} under facility ${savedFacility.code}`);
|
||||
const newFacility = facilityRepo.create(INDODE_FACILITY);
|
||||
const savedFacility = await facilityRepo.save(newFacility);
|
||||
this.logger.log(`Created facility: ${savedFacility.code}`);
|
||||
|
||||
// Create 11 yards per warehouse
|
||||
await this.createYardsForWarehouse(yardRepo, zoneRepo, savedWarehouse);
|
||||
}
|
||||
// Create warehouses for the facility
|
||||
for (const warehouseData of WAREHOUSES) {
|
||||
try {
|
||||
const warehouse = await warehouseRepo.findOne({
|
||||
where: { code: warehouseData.code },
|
||||
});
|
||||
|
||||
this.logger.log(
|
||||
'Indode Multipurpose Dry Port facility seeded successfully with 2 warehouses and 11 yards each',
|
||||
if (warehouse) {
|
||||
this.logger.log(`Warehouse ${warehouseData.code} already exists, skipping`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const newWarehouse = warehouseRepo.create({
|
||||
...warehouseData,
|
||||
facilityId: savedFacility.id,
|
||||
});
|
||||
const savedWarehouse = await warehouseRepo.save(newWarehouse);
|
||||
this.logger.log(`Created warehouse: ${savedWarehouse.code} under facility ${savedFacility.code}`);
|
||||
|
||||
// Create 11 yards per warehouse
|
||||
await this.createYardsForWarehouse(yardRepo, zoneRepo, savedWarehouse);
|
||||
} catch (warehouseError) {
|
||||
this.logger.warn(
|
||||
`Failed to create warehouse ${warehouseData.code}: ${warehouseError instanceof Error ? warehouseError.message : String(warehouseError)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.log(
|
||||
'Indode Multipurpose Dry Port facility seeded successfully with 2 warehouses and 11 yards each',
|
||||
);
|
||||
});
|
||||
} catch (error) {
|
||||
this.logger.error(
|
||||
`IndodeFacilitySeeder error: ${error instanceof Error ? error.message : String(error)}`,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private async createYardsForWarehouse(
|
||||
|
||||
Reference in New Issue
Block a user