From eb998bfdddcbba9f3cde842b9c5193ca6ae72888 Mon Sep 17 00:00:00 2001 From: Hagernesh Date: Fri, 17 Jul 2026 12:20:12 +0000 Subject: [PATCH] Facility --- apps/edr-freight-api/src/app.module.ts | 3 +++ .../src/seed/indode-facility.seeder.ts | 20 ++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/apps/edr-freight-api/src/app.module.ts b/apps/edr-freight-api/src/app.module.ts index 5a9ae9ef9..a347b163b 100644 --- a/apps/edr-freight-api/src/app.module.ts +++ b/apps/edr-freight-api/src/app.module.ts @@ -275,6 +275,9 @@ export class AppModule implements OnApplicationBootstrap { // await this.demoUsersSeeder.run(); // await this.freightStaffUsersSeeder.run(); // await this.pricingDataSeeder.run(); + // IndodeFacilitySeeder keys its warehouses on INDODE_OPEN / INDODE_CLOSED, so + // it will not recognise a hand-created Indode warehouse and will seed a second + // one alongside it. Only enable it against an Indode that has no warehouse. // await this.indodeFacilitySeeder.run(); // await this.batch14TestDataSeeder.run(); // await this.batch5TestDataSeeder.run(); diff --git a/apps/edr-freight-api/src/seed/indode-facility.seeder.ts b/apps/edr-freight-api/src/seed/indode-facility.seeder.ts index 4182c4661..763bc6c54 100644 --- a/apps/edr-freight-api/src/seed/indode-facility.seeder.ts +++ b/apps/edr-freight-api/src/seed/indode-facility.seeder.ts @@ -74,20 +74,22 @@ export class IndodeFacilitySeeder { const yardRepo = manager.getRepository(WarehouseYard); const zoneRepo = manager.getRepository(WarehouseZone); - // Ensure facility exists - const facility = await facilityRepo.findOne({ + // Ensure facility exists. An existing facility row is not proof the + // warehouses under it survived, so reuse it and carry on rather than + // returning — otherwise a facility with no warehouses stays that way. + const existing = await facilityRepo.findOne({ where: { code: INDODE_FACILITY.code }, }); - if (facility) { - this.logger.log('Indode facility already exists, skipping seed'); - return; + let savedFacility: Facility; + if (existing) { + savedFacility = await facilityRepo.save({ ...existing, ...INDODE_FACILITY }); + this.logger.log(`Facility ${savedFacility.code} already exists, reusing`); + } else { + savedFacility = await facilityRepo.save(facilityRepo.create(INDODE_FACILITY)); + this.logger.log(`Created facility: ${savedFacility.code}`); } - 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) { try {