From a04d22dcb44f9ddea59c2011d925d0684bbf39aa Mon Sep 17 00:00:00 2001 From: Maximilian Kreuzkam Date: Mon, 16 Dec 2024 13:16:17 +0100 Subject: [PATCH] Use configService directly and don't read values in constructor. --- .../src/infra/sync/tsp/tsp-sync.strategy.ts | 43 ++++++------------- 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/apps/server/src/infra/sync/tsp/tsp-sync.strategy.ts b/apps/server/src/infra/sync/tsp/tsp-sync.strategy.ts index b5374a24c2..05beef3866 100644 --- a/apps/server/src/infra/sync/tsp/tsp-sync.strategy.ts +++ b/apps/server/src/infra/sync/tsp/tsp-sync.strategy.ts @@ -25,40 +25,19 @@ import { TspSyncService } from './tsp-sync.service'; @Injectable() export class TspSyncStrategy extends SyncStrategy { - private readonly schoolLimit: number; - - private readonly dataLimit: number; - - private readonly migrationLimit: number; - - private readonly schoolDaysToFetch: number; - - private readonly schoolDataDaysToFetch: number; - - private readonly migrationEnabled: boolean; - constructor( private readonly logger: Logger, private readonly tspSyncService: TspSyncService, private readonly tspFetchService: TspFetchService, private readonly tspOauthDataMapper: TspOauthDataMapper, private readonly tspLegacyMigrationService: TspLegacyMigrationService, - configService: ConfigService, + private readonly configService: ConfigService, private readonly provisioningService: ProvisioningService, private readonly userService: UserService, private readonly accountService: AccountService ) { super(); this.logger.setContext(TspSyncStrategy.name); - - this.schoolLimit = configService.getOrThrow('TSP_SYNC_SCHOOL_LIMIT'); - this.schoolDaysToFetch = configService.get('TSP_SYNC_SCHOOL_DAYS_TO_FETCH', 1); - - this.dataLimit = configService.getOrThrow('TSP_SYNC_DATA_LIMIT'); - this.schoolDataDaysToFetch = configService.get('TSP_SYNC_DATA_DAYS_TO_FETCH', 1); - - this.migrationLimit = configService.getOrThrow('TSP_SYNC_MIGRATION_LIMIT'); - this.migrationEnabled = configService.get('FEATURE_TSP_MIGRATION_ENABLED', false); } public override getType(): SyncStrategyTarget { @@ -74,7 +53,7 @@ export class TspSyncStrategy extends SyncStrategy { const schools = await this.tspSyncService.findSchoolsForSystem(system); - if (this.migrationEnabled) { + if (this.configService.get('FEATURE_TSP_MIGRATION_ENABLED', false)) { await this.runMigration(system); } @@ -82,8 +61,9 @@ export class TspSyncStrategy extends SyncStrategy { } private async syncSchools(system: System): Promise { - const tspSchools = await this.tspFetchService.fetchTspSchools(system, this.schoolDaysToFetch); - this.logger.info(new TspSchoolsFetchedLoggable(tspSchools.length, this.schoolDaysToFetch)); + const schoolDaysToFetch = this.configService.get('TSP_SYNC_SCHOOL_LIMIT', 1); + const tspSchools = await this.tspFetchService.fetchTspSchools(system, schoolDaysToFetch); + this.logger.info(new TspSchoolsFetchedLoggable(tspSchools.length, schoolDaysToFetch)); const schoolPromises = tspSchools.map(async (tspSchool) => { if (!tspSchool.schuleNummer) { @@ -118,11 +98,12 @@ export class TspSyncStrategy extends SyncStrategy { } private async syncData(system: System, schools: School[]): Promise { - const tspTeachers = await this.tspFetchService.fetchTspTeachers(system, this.schoolDataDaysToFetch); - const tspStudents = await this.tspFetchService.fetchTspStudents(system, this.schoolDataDaysToFetch); - const tspClasses = await this.tspFetchService.fetchTspClasses(system, this.schoolDataDaysToFetch); + const schoolDataDaysToFetch = this.configService.get('TSP_SYNC_SCHOOL_DAYS_TO_FETCH', 1); + const tspTeachers = await this.tspFetchService.fetchTspTeachers(system, schoolDataDaysToFetch); + const tspStudents = await this.tspFetchService.fetchTspStudents(system, schoolDataDaysToFetch); + const tspClasses = await this.tspFetchService.fetchTspClasses(system, schoolDataDaysToFetch); this.logger.info( - new TspDataFetchedLoggable(tspTeachers.length, tspStudents.length, tspClasses.length, this.schoolDataDaysToFetch) + new TspDataFetchedLoggable(tspTeachers.length, tspStudents.length, tspClasses.length, schoolDataDaysToFetch) ); const oauthDataDtos = this.tspOauthDataMapper.mapTspDataToOauthData( @@ -145,7 +126,9 @@ export class TspSyncStrategy extends SyncStrategy { private async migrateTspTeachersBatch(system: System, oldToNewMappings: Map): Promise { this.logger.info(new TspTeachersFetchedLoggable(oldToNewMappings.size)); - const users = await this.userService.findByTspUids(Array.from(oldToNewMappings.keys())); + const migrationIds = Array.from(oldToNewMappings.keys()); + + const users = await this.userService.findByTspUids(migrationIds); this.logger.info(this.logForMsg(`Users fetched: ${users.length}`)); const userIds = users.map((user) => user.id ?? '');