From 72532f36cd84cb7676737e8d7156730029e5506f Mon Sep 17 00:00:00 2001 From: Nathnael Date: Mon, 3 Aug 2026 11:58:33 +0000 Subject: [PATCH] fix: seeder --- apps/edr-freight-api/src/app.module.ts | 18 ++++---- .../src/seed/edr-org.seeder.ts | 41 +++++++++++-------- integration/scripts/it.mjs | 6 ++- 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/apps/edr-freight-api/src/app.module.ts b/apps/edr-freight-api/src/app.module.ts index a3c09df97..73e28205e 100644 --- a/apps/edr-freight-api/src/app.module.ts +++ b/apps/edr-freight-api/src/app.module.ts @@ -65,7 +65,7 @@ import { FreightPositionsSeeder } from "./seed/freight-positions.seeder"; import { PaymentModule } from "./modules/payment/payment.module"; // import { PricingDataSeeder } from "./seed/pricing-data.seeder"; import { FileUploadSettingsSeeder } from "./seed/file-upload-settings.seeder"; -import { YardFacilitiesSeeder } from "./seed/yard-facilities.seeder"; +// import { YardFacilitiesSeeder } from "./seed/yard-facilities.seeder"; // import { IndodeFacilitySeeder } from "./seed/indode-facility.seeder"; // import { Batch14TestDataSeeder } from "./seed/batch1-4-test-data.seeder"; // import { Batch5TestDataSeeder } from "./seed/batch5-test-data.seeder"; @@ -226,7 +226,7 @@ import { LoginAudienceMiddleware } from "./modules/auth/login-audience.middlewar EdrOrgSeeder, FreightPositionsSeeder, FileUploadSettingsSeeder, - YardFacilitiesSeeder, + // YardFacilitiesSeeder, FreightPermissionKeyMigrationSeeder, // Disabled seeds — providers commented out (imports/injection/run too): // DemoUsersSeeder, @@ -253,7 +253,7 @@ export class AppModule implements OnApplicationBootstrap { private readonly edrOrgSeeder: EdrOrgSeeder, private readonly freightPositionsSeeder: FreightPositionsSeeder, private readonly fileUploadSettingsSeeder: FileUploadSettingsSeeder, - private readonly yardFacilitiesSeeder: YardFacilitiesSeeder, + // private readonly yardFacilitiesSeeder: YardFacilitiesSeeder, private readonly freightPermissionKeyMigrationSeeder: FreightPermissionKeyMigrationSeeder, // Disabled seeds — injections commented out (imports/provider/run too): // private readonly demoUsersSeeder: DemoUsersSeeder, @@ -302,7 +302,7 @@ export class AppModule implements OnApplicationBootstrap { // Flags which yards can load/unload cargo (Indode, Sebeta, Modjo, Adama, // Dire Dawa). Idempotent; creates no yards. - await this.yardFacilitiesSeeder.run(); + // await this.yardFacilitiesSeeder.run(); // Dropdown settings are not seeded on boot; run them with // `pnpm seed:dropdown-settings` (src/scripts/seed-dropdown-settings.ts). @@ -333,9 +333,11 @@ export class AppModule implements OnApplicationBootstrap { configure(consumer: MiddlewareConsumer) { consumer.apply(LoggerMiddleware).forRoutes("*"); - consumer.apply(LoginAudienceMiddleware).forRoutes( - { path: "auth/login", method: RequestMethod.POST }, - { path: "auth/mfa-verify", method: RequestMethod.POST }, - ); + consumer + .apply(LoginAudienceMiddleware) + .forRoutes( + { path: "auth/login", method: RequestMethod.POST }, + { path: "auth/mfa-verify", method: RequestMethod.POST }, + ); } } diff --git a/apps/edr-freight-api/src/seed/edr-org.seeder.ts b/apps/edr-freight-api/src/seed/edr-org.seeder.ts index 9f10c3e0e..cd1b2c111 100644 --- a/apps/edr-freight-api/src/seed/edr-org.seeder.ts +++ b/apps/edr-freight-api/src/seed/edr-org.seeder.ts @@ -29,11 +29,13 @@ type SeedOrganization = { export class EdrOrgSeeder { private readonly logger = new Logger(EdrOrgSeeder.name); - constructor(private readonly dataSource: DataSource) {} + constructor(private readonly dataSource: DataSource) { } async run() { if (!this.shouldSeed()) { - this.logger.log(`Skipping EDR org seed because ${SEED_FLAG} is not enabled`); + this.logger.log( + `Skipping EDR org seed because ${SEED_FLAG} is not enabled`, + ); return; } @@ -95,20 +97,22 @@ export class EdrOrgSeeder { manager: EntityManager, organizationId: string, ) { - const organizationConfigurationRepository = - manager.getRepository(OrganizationConfiguration); - - await organizationConfigurationRepository.upsert({ - organizationId, - canCreateBranchByItself: true, - canStartReceivingRecord: true, - }, { - conflictPaths: { organizationId: true }, - }); - - this.logger.log( - `Ensured organization configuration for '${EDR_ORG_KEY}'`, + const organizationConfigurationRepository = manager.getRepository( + OrganizationConfiguration, ); + + await organizationConfigurationRepository.upsert( + { + organizationId, + canCreateBranchByItself: true, + canStartReceivingRecord: true, + }, + { + conflictPaths: { organizationId: true }, + }, + ); + + this.logger.log(`Ensured organization configuration for '${EDR_ORG_KEY}'`); } private async ensureDefaultUnit( @@ -152,7 +156,9 @@ export class EdrOrgSeeder { key: EDR_FREIGHT_APPLICATION.key, name: { ...EDR_FREIGHT_APPLICATION.name }, }); - this.logger.log(`Seeded EDR application '${EDR_FREIGHT_APPLICATION.key}'`); + this.logger.log( + `Seeded EDR application '${EDR_FREIGHT_APPLICATION.key}'`, + ); return { id: insertResult.identifiers[0]?.id as string }; } @@ -181,7 +187,8 @@ export class EdrOrgSeeder { applicationId, })), ) - .orUpdate(["name", "application_id"], ["key"]) + .orIgnore() + // .orUpdate(["name", "application_id"], ["key"]) .execute(); this.logger.log( diff --git a/integration/scripts/it.mjs b/integration/scripts/it.mjs index a30e446b5..e3e2b3075 100644 --- a/integration/scripts/it.mjs +++ b/integration/scripts/it.mjs @@ -143,7 +143,11 @@ function up() { } } -const [cmd, ...extra] = process.argv.slice(2); +const [cmd, ...rawExtra] = process.argv.slice(2); +// `pnpm it:test -- src/foo.it.ts` hands us a literal "--" first. Forwarding it +// makes vitest treat everything after it as CLI options and ignore the file +// filter — the "one file" run silently becomes the whole suite. +const extra = rawExtra[0] === "--" ? rawExtra.slice(1) : rawExtra; switch (cmd) { case "up":