fix seeds
This commit is contained in:
@@ -1,18 +1,21 @@
|
||||
import type { Logger } from '@core/shared/application';
|
||||
import { EnsureInitialData } from '../../../../../adapters/bootstrap/EnsureInitialData';
|
||||
import type { EnsureInitialData } from '../../../../../adapters/bootstrap/EnsureInitialData';
|
||||
import { SeedRacingData, type RacingSeedDependencies } from '../../../../../adapters/bootstrap/SeedRacingData';
|
||||
import { Module, OnModuleInit } from '@nestjs/common';
|
||||
import { ModuleRef } from '@nestjs/core';
|
||||
import { Inject, Module, OnModuleInit } from '@nestjs/common';
|
||||
import { getApiPersistence } from '../../env';
|
||||
import { BootstrapProviders } from './BootstrapProviders';
|
||||
import { InMemoryRacingPersistenceModule } from '../../persistence/inmemory/InMemoryRacingPersistenceModule';
|
||||
import { InMemorySocialPersistenceModule } from '../../persistence/inmemory/InMemorySocialPersistenceModule';
|
||||
import { BootstrapProviders, ENSURE_INITIAL_DATA_TOKEN } from './BootstrapProviders';
|
||||
|
||||
@Module({
|
||||
imports: [InMemoryRacingPersistenceModule, InMemorySocialPersistenceModule],
|
||||
providers: BootstrapProviders,
|
||||
})
|
||||
export class BootstrapModule implements OnModuleInit {
|
||||
constructor(
|
||||
private readonly ensureInitialData: EnsureInitialData,
|
||||
private readonly moduleRef: ModuleRef,
|
||||
@Inject(ENSURE_INITIAL_DATA_TOKEN) private readonly ensureInitialData: EnsureInitialData,
|
||||
@Inject('Logger') private readonly logger: Logger,
|
||||
@Inject('RacingSeedDependencies') private readonly seedDeps: RacingSeedDependencies,
|
||||
) {}
|
||||
|
||||
async onModuleInit() {
|
||||
@@ -21,14 +24,7 @@ export class BootstrapModule implements OnModuleInit {
|
||||
await this.ensureInitialData.execute();
|
||||
|
||||
if (this.shouldSeedRacingData()) {
|
||||
const logger = this.tryGet<Logger>('Logger');
|
||||
const seedDeps = this.tryGetSeedDeps();
|
||||
|
||||
if (!logger || !seedDeps) {
|
||||
console.log('[Bootstrap] Racing seed skipped (missing providers)');
|
||||
} else {
|
||||
await new SeedRacingData(logger, seedDeps).execute();
|
||||
}
|
||||
await new SeedRacingData(this.logger, this.seedDeps).execute();
|
||||
}
|
||||
|
||||
console.log('[Bootstrap] Application data initialized successfully');
|
||||
@@ -41,62 +37,4 @@ export class BootstrapModule implements OnModuleInit {
|
||||
private shouldSeedRacingData(): boolean {
|
||||
return getApiPersistence() === 'inmemory';
|
||||
}
|
||||
|
||||
private tryGet<T>(token: string): T | undefined {
|
||||
try {
|
||||
return this.moduleRef.get(token, { strict: false });
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
private tryGetSeedDeps(): RacingSeedDependencies | undefined {
|
||||
const driverRepository = this.tryGet<RacingSeedDependencies['driverRepository']>('IDriverRepository');
|
||||
const leagueRepository = this.tryGet<RacingSeedDependencies['leagueRepository']>('ILeagueRepository');
|
||||
const raceRepository = this.tryGet<RacingSeedDependencies['raceRepository']>('IRaceRepository');
|
||||
const resultRepository = this.tryGet<RacingSeedDependencies['resultRepository']>('IResultRepository');
|
||||
const standingRepository = this.tryGet<RacingSeedDependencies['standingRepository']>('IStandingRepository');
|
||||
const leagueMembershipRepository = this.tryGet<RacingSeedDependencies['leagueMembershipRepository']>(
|
||||
'ILeagueMembershipRepository',
|
||||
);
|
||||
const raceRegistrationRepository = this.tryGet<RacingSeedDependencies['raceRegistrationRepository']>(
|
||||
'IRaceRegistrationRepository',
|
||||
);
|
||||
const teamRepository = this.tryGet<RacingSeedDependencies['teamRepository']>('ITeamRepository');
|
||||
const teamMembershipRepository = this.tryGet<RacingSeedDependencies['teamMembershipRepository']>(
|
||||
'ITeamMembershipRepository',
|
||||
);
|
||||
const feedRepository = this.tryGet<RacingSeedDependencies['feedRepository']>('IFeedRepository');
|
||||
const socialGraphRepository = this.tryGet<RacingSeedDependencies['socialGraphRepository']>('ISocialGraphRepository');
|
||||
|
||||
if (
|
||||
!driverRepository ||
|
||||
!leagueRepository ||
|
||||
!raceRepository ||
|
||||
!resultRepository ||
|
||||
!standingRepository ||
|
||||
!leagueMembershipRepository ||
|
||||
!raceRegistrationRepository ||
|
||||
!teamRepository ||
|
||||
!teamMembershipRepository ||
|
||||
!feedRepository ||
|
||||
!socialGraphRepository
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
driverRepository,
|
||||
leagueRepository,
|
||||
raceRepository,
|
||||
resultRepository,
|
||||
standingRepository,
|
||||
leagueMembershipRepository,
|
||||
raceRegistrationRepository,
|
||||
teamRepository,
|
||||
teamMembershipRepository,
|
||||
feedRepository,
|
||||
socialGraphRepository,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user