seed data

This commit is contained in:
2025-12-26 22:22:39 +01:00
parent 1e8d84b31b
commit b4f86abf90
10 changed files with 926 additions and 218 deletions

View File

@@ -0,0 +1,129 @@
import { Global, Module } from '@nestjs/common';
import type { Logger } from '@core/shared/application/Logger';
import type { IDriverRepository } from '@core/racing/domain/repositories/IDriverRepository';
import type { ILeagueRepository } from '@core/racing/domain/repositories/ILeagueRepository';
import type { IRaceRepository } from '@core/racing/domain/repositories/IRaceRepository';
import type { IResultRepository } from '@core/racing/domain/repositories/IResultRepository';
import type { IStandingRepository } from '@core/racing/domain/repositories/IStandingRepository';
import type { ILeagueMembershipRepository } from '@core/racing/domain/repositories/ILeagueMembershipRepository';
import type { IRaceRegistrationRepository } from '@core/racing/domain/repositories/IRaceRegistrationRepository';
import type { ITeamRepository } from '@core/racing/domain/repositories/ITeamRepository';
import type { ITeamMembershipRepository } from '@core/racing/domain/repositories/ITeamMembershipRepository';
import type { IFeedRepository } from '@core/social/domain/repositories/IFeedRepository';
import type { ISocialGraphRepository } from '@core/social/domain/repositories/ISocialGraphRepository';
import { getPointsSystems } from '@adapters/bootstrap/PointsSystems';
import { InMemoryDriverRepository } from '@adapters/racing/persistence/inmemory/InMemoryDriverRepository';
import { InMemoryLeagueRepository } from '@adapters/racing/persistence/inmemory/InMemoryLeagueRepository';
import { InMemoryRaceRepository } from '@adapters/racing/persistence/inmemory/InMemoryRaceRepository';
import { InMemoryResultRepository } from '@adapters/racing/persistence/inmemory/InMemoryResultRepository';
import { InMemoryStandingRepository } from '@adapters/racing/persistence/inmemory/InMemoryStandingRepository';
import { InMemoryLeagueMembershipRepository } from '@adapters/racing/persistence/inmemory/InMemoryLeagueMembershipRepository';
import { InMemoryRaceRegistrationRepository } from '@adapters/racing/persistence/inmemory/InMemoryRaceRegistrationRepository';
import { InMemoryTeamRepository } from '@adapters/racing/persistence/inmemory/InMemoryTeamRepository';
import { InMemoryTeamMembershipRepository } from '@adapters/racing/persistence/inmemory/InMemoryTeamMembershipRepository';
import {
InMemoryFeedRepository,
InMemorySocialGraphRepository,
} from '@adapters/social/persistence/inmemory/InMemorySocialAndFeed';
export const DRIVER_REPOSITORY_TOKEN = 'IDriverRepository';
export const LEAGUE_REPOSITORY_TOKEN = 'ILeagueRepository';
export const RACE_REPOSITORY_TOKEN = 'IRaceRepository';
export const RESULT_REPOSITORY_TOKEN = 'IResultRepository';
export const STANDING_REPOSITORY_TOKEN = 'IStandingRepository';
export const LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN = 'ILeagueMembershipRepository';
export const RACE_REGISTRATION_REPOSITORY_TOKEN = 'IRaceRegistrationRepository';
export const TEAM_REPOSITORY_TOKEN = 'ITeamRepository';
export const TEAM_MEMBERSHIP_REPOSITORY_TOKEN = 'ITeamMembershipRepository';
export const FEED_REPOSITORY_TOKEN = 'IFeedRepository';
export const SOCIAL_GRAPH_REPOSITORY_TOKEN = 'ISocialGraphRepository';
@Global()
@Module({
providers: [
{
provide: DRIVER_REPOSITORY_TOKEN,
useFactory: (logger: Logger): IDriverRepository => new InMemoryDriverRepository(logger),
inject: ['Logger'],
},
{
provide: LEAGUE_REPOSITORY_TOKEN,
useFactory: (logger: Logger): ILeagueRepository => new InMemoryLeagueRepository(logger),
inject: ['Logger'],
},
{
provide: RACE_REPOSITORY_TOKEN,
useFactory: (logger: Logger): IRaceRepository => new InMemoryRaceRepository(logger),
inject: ['Logger'],
},
{
provide: RESULT_REPOSITORY_TOKEN,
useFactory: (logger: Logger, raceRepo: IRaceRepository): IResultRepository =>
new InMemoryResultRepository(logger, raceRepo),
inject: ['Logger', RACE_REPOSITORY_TOKEN],
},
{
provide: STANDING_REPOSITORY_TOKEN,
useFactory: (
logger: Logger,
resultRepo: IResultRepository,
raceRepo: IRaceRepository,
leagueRepo: ILeagueRepository,
): IStandingRepository => new InMemoryStandingRepository(logger, getPointsSystems(), resultRepo, raceRepo, leagueRepo),
inject: ['Logger', RESULT_REPOSITORY_TOKEN, RACE_REPOSITORY_TOKEN, LEAGUE_REPOSITORY_TOKEN],
},
{
provide: LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN,
useFactory: (logger: Logger): ILeagueMembershipRepository => new InMemoryLeagueMembershipRepository(logger),
inject: ['Logger'],
},
{
provide: RACE_REGISTRATION_REPOSITORY_TOKEN,
useFactory: (logger: Logger): IRaceRegistrationRepository => new InMemoryRaceRegistrationRepository(logger),
inject: ['Logger'],
},
{
provide: TEAM_REPOSITORY_TOKEN,
useFactory: (logger: Logger): ITeamRepository => new InMemoryTeamRepository(logger),
inject: ['Logger'],
},
{
provide: TEAM_MEMBERSHIP_REPOSITORY_TOKEN,
useFactory: (logger: Logger): ITeamMembershipRepository => new InMemoryTeamMembershipRepository(logger),
inject: ['Logger'],
},
{
provide: FEED_REPOSITORY_TOKEN,
useFactory: (logger: Logger): IFeedRepository =>
new InMemoryFeedRepository(logger, { drivers: [], friendships: [], feedEvents: [] }),
inject: ['Logger'],
},
{
provide: SOCIAL_GRAPH_REPOSITORY_TOKEN,
useFactory: (logger: Logger): ISocialGraphRepository =>
new InMemorySocialGraphRepository(logger, { drivers: [], friendships: [], feedEvents: [] }),
inject: ['Logger'],
},
],
exports: [
DRIVER_REPOSITORY_TOKEN,
LEAGUE_REPOSITORY_TOKEN,
RACE_REPOSITORY_TOKEN,
RESULT_REPOSITORY_TOKEN,
STANDING_REPOSITORY_TOKEN,
LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN,
RACE_REGISTRATION_REPOSITORY_TOKEN,
TEAM_REPOSITORY_TOKEN,
TEAM_MEMBERSHIP_REPOSITORY_TOKEN,
FEED_REPOSITORY_TOKEN,
SOCIAL_GRAPH_REPOSITORY_TOKEN,
],
})
export class InMemoryPersistenceModule {}