From fa4d9fe45192fe4f554555c0a826b7c88fcc94c8 Mon Sep 17 00:00:00 2001 From: dyedwiper Date: Thu, 21 Sep 2023 16:38:48 +0200 Subject: [PATCH 1/5] Rename system entity --- .../controllers/api-test/login.api.spec.ts | 4 +- .../services/ldap.service.spec.ts | 10 +-- .../authentication/services/ldap.service.ts | 6 +- .../strategy/ldap.strategy.spec.ts | 18 ++-- .../authentication/strategy/ldap.strategy.ts | 11 ++- .../fwu-learning-contents-test.module.ts | 4 +- .../fwu-learning-contents.module.ts | 4 +- .../modules/group/repo/group-domain.mapper.ts | 4 +- .../modules/h5p-editor/h5p-editor.module.ts | 4 +- .../modules/management/seed-data/schools.ts | 6 +- .../uc/database-management.uc.spec.ts | 22 ++--- .../management/uc/database-management.uc.ts | 12 +-- .../controller/api-test/oauth-sso.api.spec.ts | 22 ++--- .../oauth/service/oauth.service.spec.ts | 4 +- .../controller/api-test/system.api.spec.ts | 10 +-- .../system/mapper/system-oidc.mapper.spec.ts | 9 +- .../system/mapper/system-oidc.mapper.ts | 6 +- .../system/mapper/system.mapper.spec.ts | 6 +- .../modules/system/mapper/system.mapper.ts | 6 +- .../service/system-oidc.service.spec.ts | 4 +- .../system/service/system-oidc.service.ts | 4 +- .../system/service/system.service.spec.ts | 6 +- .../modules/system/service/system.service.ts | 16 ++-- .../src/modules/system/uc/system.uc.spec.ts | 6 +- .../server/src/modules/system/uc/system.uc.ts | 4 +- .../api-test/import-user.api.spec.ts | 14 +-- .../user-import/uc/user-import.uc.spec.ts | 10 ++- .../modules/user-import/uc/user-import.uc.ts | 6 +- .../api-test/user-login-migration.api.spec.ts | 88 +++++++++---------- .../uc/user-login-migration.uc.spec.ts | 10 +-- .../src/shared/domain/entity/all-entities.ts | 4 +- .../domain/entity/external-source.entity.ts | 8 +- .../domain/entity/import-user.entity.ts | 6 +- .../src/shared/domain/entity/school.entity.ts | 6 +- .../domain/entity/system.entity.spec.ts | 8 +- .../src/shared/domain/entity/system.entity.ts | 2 +- .../entity/user-login-migration.entity.ts | 10 +-- .../keycloak-configuration.service.spec.ts | 4 +- .../legacy-school.repo.integration.spec.ts | 14 +-- .../shared/repo/school/legacy-school.repo.ts | 13 ++- .../src/shared/repo/system/system-scope.ts | 4 +- .../system/system.repo.integration.spec.ts | 10 +-- .../src/shared/repo/system/system.repo.ts | 14 +-- .../user/user-do.repo.integration.spec.ts | 6 +- .../src/shared/repo/user/user-do.repo.ts | 4 +- .../repo/user/user.repo.integration.spec.ts | 4 +- ...r-login-migration.repo.integration.spec.ts | 6 +- .../user-login-migration.repo.ts | 6 +- .../shared/testing/factory/system.factory.ts | 6 +- 49 files changed, 244 insertions(+), 227 deletions(-) diff --git a/apps/server/src/modules/authentication/controllers/api-test/login.api.spec.ts b/apps/server/src/modules/authentication/controllers/api-test/login.api.spec.ts index 6bc8959e936..80fc43734bc 100644 --- a/apps/server/src/modules/authentication/controllers/api-test/login.api.spec.ts +++ b/apps/server/src/modules/authentication/controllers/api-test/login.api.spec.ts @@ -1,7 +1,7 @@ import { EntityManager } from '@mikro-orm/core'; import { HttpStatus, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; -import { Account, RoleName, SchoolEntity, System, User } from '@shared/domain'; +import { Account, RoleName, SchoolEntity, SystemEntity, User } from '@shared/domain'; import { accountFactory, roleFactory, schoolFactory, systemFactory, userFactory } from '@shared/testing'; import { SSOErrorCode } from '@src/modules/oauth/error/sso-error-code.enum'; import { OauthTokenResponse } from '@src/modules/oauth/service/dto'; @@ -147,7 +147,7 @@ describe('Login Controller (api)', () => { let account: Account; let user: User; let school: SchoolEntity; - let system: System; + let system: SystemEntity; beforeAll(async () => { const schoolExternalId = 'mockSchoolExternalId'; diff --git a/apps/server/src/modules/authentication/services/ldap.service.spec.ts b/apps/server/src/modules/authentication/services/ldap.service.spec.ts index 83e6a212d76..8b334ac195c 100644 --- a/apps/server/src/modules/authentication/services/ldap.service.spec.ts +++ b/apps/server/src/modules/authentication/services/ldap.service.spec.ts @@ -1,7 +1,7 @@ import { createMock } from '@golevelup/ts-jest'; import { UnauthorizedException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; -import { System } from '@shared/domain'; +import { SystemEntity } from '@shared/domain'; import { systemFactory } from '@shared/testing'; import { LegacyLogger } from '@src/core/logger'; import { LdapService } from './ldap.service'; @@ -59,7 +59,7 @@ describe('LdapService', () => { describe('checkLdapCredentials', () => { describe('when credentials are correct', () => { it('should login successfully', async () => { - const system: System = systemFactory.withLdapConfig().buildWithId(); + const system: SystemEntity = systemFactory.withLdapConfig().buildWithId(); await expect( ldapService.checkLdapCredentials(system, 'connectSucceeds', 'mockPassword') ).resolves.not.toThrow(); @@ -68,7 +68,7 @@ describe('LdapService', () => { describe('when no ldap config is provided', () => { it('should throw error', async () => { - const system: System = systemFactory.buildWithId(); + const system: SystemEntity = systemFactory.buildWithId(); await expect(ldapService.checkLdapCredentials(system, 'mockUsername', 'mockPassword')).rejects.toThrow( new Error(`no LDAP config found in system ${system.id}`) ); @@ -77,7 +77,7 @@ describe('LdapService', () => { describe('when user is not authorized', () => { it('should throw unauthorized error', async () => { - const system: System = systemFactory.withLdapConfig().buildWithId(); + const system: SystemEntity = systemFactory.withLdapConfig().buildWithId(); await expect(ldapService.checkLdapCredentials(system, 'mockUsername', 'mockPassword')).rejects.toThrow( new UnauthorizedException('User could not authenticate') ); @@ -86,7 +86,7 @@ describe('LdapService', () => { describe('when connected flag is not set', () => { it('should throw unauthorized error', async () => { - const system: System = systemFactory.withLdapConfig().buildWithId(); + const system: SystemEntity = systemFactory.withLdapConfig().buildWithId(); await expect(ldapService.checkLdapCredentials(system, 'connectWithoutFlag', 'mockPassword')).rejects.toThrow( new UnauthorizedException('User could not authenticate') ); diff --git a/apps/server/src/modules/authentication/services/ldap.service.ts b/apps/server/src/modules/authentication/services/ldap.service.ts index 4a875ce70a8..d47ee31c200 100644 --- a/apps/server/src/modules/authentication/services/ldap.service.ts +++ b/apps/server/src/modules/authentication/services/ldap.service.ts @@ -1,5 +1,5 @@ import { Injectable, UnauthorizedException } from '@nestjs/common'; -import { System } from '@shared/domain'; +import { SystemEntity } from '@shared/domain'; import { ErrorUtils } from '@src/core/error/utils'; import { LegacyLogger } from '@src/core/logger'; import { Client, createClient } from 'ldapjs'; @@ -11,7 +11,7 @@ export class LdapService { this.logger.setContext(LdapService.name); } - async checkLdapCredentials(system: System, username: string, password: string): Promise { + async checkLdapCredentials(system: SystemEntity, username: string, password: string): Promise { const connection = await this.connect(system, username, password); if (connection.connected) { connection.unbind(); @@ -20,7 +20,7 @@ export class LdapService { throw new UnauthorizedException('User could not authenticate'); } - private connect(system: System, username: string, password: string): Promise { + private connect(system: SystemEntity, username: string, password: string): Promise { const { ldapConfig } = system; if (!ldapConfig) { throw Error(`no LDAP config found in system ${system.id}`); diff --git a/apps/server/src/modules/authentication/strategy/ldap.strategy.spec.ts b/apps/server/src/modules/authentication/strategy/ldap.strategy.spec.ts index 4815921ca1b..db4a1a60878 100644 --- a/apps/server/src/modules/authentication/strategy/ldap.strategy.spec.ts +++ b/apps/server/src/modules/authentication/strategy/ldap.strategy.spec.ts @@ -2,7 +2,7 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { UnauthorizedException } from '@nestjs/common'; import { PassportModule } from '@nestjs/passport'; import { Test, TestingModule } from '@nestjs/testing'; -import { LegacySchoolDo, RoleName, System, User } from '@shared/domain'; +import { LegacySchoolDo, RoleName, SystemEntity, User } from '@shared/domain'; import { LegacySchoolRepo, SystemRepo, UserRepo } from '@shared/repo'; import { accountDtoFactory, @@ -87,7 +87,7 @@ describe('LdapStrategy', () => { const setup = () => { const username = 'mockUserName'; - const system: System = systemFactory.withLdapConfig({ rootPath: 'rootPath' }).buildWithId(); + const system: SystemEntity = systemFactory.withLdapConfig({ rootPath: 'rootPath' }).buildWithId(); const user: User = userFactory.withRoleByName(RoleName.STUDENT).buildWithId({ ldapDn: undefined }); @@ -134,7 +134,7 @@ describe('LdapStrategy', () => { const setup = () => { const username = 'mockUserName'; - const system: System = systemFactory.withLdapConfig({ rootPath: 'rootPath' }).buildWithId(); + const system: SystemEntity = systemFactory.withLdapConfig({ rootPath: 'rootPath' }).buildWithId(); const user: User = userFactory.withRoleByName(RoleName.STUDENT).buildWithId({ ldapDn: 'mockLdapDn' }); @@ -181,7 +181,7 @@ describe('LdapStrategy', () => { const setup = () => { const username = 'mockUserName'; - const system: System = systemFactory.withLdapConfig({ rootPath: 'rootPath' }).buildWithId(); + const system: SystemEntity = systemFactory.withLdapConfig({ rootPath: 'rootPath' }).buildWithId(); const user: User = userFactory.withRoleByName(RoleName.STUDENT).buildWithId({ ldapDn: 'mockLdapDn' }); @@ -228,7 +228,7 @@ describe('LdapStrategy', () => { const setup = () => { const username = 'mockUserName'; - const system: System = systemFactory.withLdapConfig({ rootPath: 'rootPath' }).buildWithId(); + const system: SystemEntity = systemFactory.withLdapConfig({ rootPath: 'rootPath' }).buildWithId(); const user: User = userFactory.withRoleByName(RoleName.STUDENT).buildWithId({ ldapDn: 'mockLdapDn' }); @@ -275,7 +275,7 @@ describe('LdapStrategy', () => { const setup = () => { const username = 'mockUserName'; - const system: System = systemFactory.withLdapConfig({ rootPath: 'rootPath' }).buildWithId(); + const system: SystemEntity = systemFactory.withLdapConfig({ rootPath: 'rootPath' }).buildWithId(); const user: User = userFactory.withRoleByName(RoleName.STUDENT).buildWithId({ ldapDn: 'mockLdapDn' }); @@ -327,7 +327,7 @@ describe('LdapStrategy', () => { const error = new Error('error'); const username = 'mockUserName'; - const system: System = systemFactory.withLdapConfig({ rootPath: 'rootPath' }).buildWithId(); + const system: SystemEntity = systemFactory.withLdapConfig({ rootPath: 'rootPath' }).buildWithId(); const user: User = userFactory.withRoleByName(RoleName.STUDENT).buildWithId({ ldapDn: 'mockLdapDn' }); @@ -382,7 +382,7 @@ describe('LdapStrategy', () => { const setup = () => { const username = 'mockUserName'; - const system: System = systemFactory.withLdapConfig().buildWithId(); + const system: SystemEntity = systemFactory.withLdapConfig().buildWithId(); const user: User = userFactory .withRoleByName(RoleName.STUDENT) @@ -444,7 +444,7 @@ describe('LdapStrategy', () => { const setup = () => { const username = 'mockUserName'; - const system: System = systemFactory.withLdapConfig().buildWithId(); + const system: SystemEntity = systemFactory.withLdapConfig().buildWithId(); const user: User = userFactory .withRoleByName(RoleName.STUDENT) diff --git a/apps/server/src/modules/authentication/strategy/ldap.strategy.ts b/apps/server/src/modules/authentication/strategy/ldap.strategy.ts index df823592378..5edc650ee9c 100644 --- a/apps/server/src/modules/authentication/strategy/ldap.strategy.ts +++ b/apps/server/src/modules/authentication/strategy/ldap.strategy.ts @@ -1,6 +1,6 @@ import { Injectable, UnauthorizedException } from '@nestjs/common'; import { PassportStrategy } from '@nestjs/passport'; -import { LegacySchoolDo, System, User } from '@shared/domain'; +import { LegacySchoolDo, SystemEntity, User } from '@shared/domain'; import { LegacySchoolRepo, SystemRepo, UserRepo } from '@shared/repo'; import { ErrorLoggable } from '@src/core/error/loggable/error.loggable'; import { Logger } from '@src/core/logger'; @@ -28,7 +28,7 @@ export class LdapStrategy extends PassportStrategy(Strategy, 'ldap') { async validate(request: { body: LdapAuthorizationBodyParams }): Promise { const { username, password, systemId, schoolId } = this.extractParamsFromRequest(request); - const system: System = await this.systemRepo.findById(systemId); + const system: SystemEntity = await this.systemRepo.findById(systemId); const school: LegacySchoolDo = await this.schoolRepo.findById(schoolId); @@ -72,7 +72,12 @@ export class LdapStrategy extends PassportStrategy(Strategy, 'ldap') { return value; } - private async checkCredentials(account: AccountDto, system: System, ldapDn: string, password: string): Promise { + private async checkCredentials( + account: AccountDto, + system: SystemEntity, + ldapDn: string, + password: string + ): Promise { try { await this.ldapService.checkLdapCredentials(system, ldapDn, password); } catch (error) { diff --git a/apps/server/src/modules/fwu-learning-contents/fwu-learning-contents-test.module.ts b/apps/server/src/modules/fwu-learning-contents/fwu-learning-contents-test.module.ts index c6fe6fc6d73..01993735a4f 100644 --- a/apps/server/src/modules/fwu-learning-contents/fwu-learning-contents-test.module.ts +++ b/apps/server/src/modules/fwu-learning-contents/fwu-learning-contents-test.module.ts @@ -1,7 +1,7 @@ import { HttpModule } from '@nestjs/axios'; import { DynamicModule, Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; -import { Account, Role, SchoolEntity, SchoolYear, System, User } from '@shared/domain'; +import { Account, Role, SchoolEntity, SchoolYear, SystemEntity, User } from '@shared/domain'; import { MongoMemoryDatabaseModule } from '@shared/infra/database'; import { MongoDatabaseModuleOptions } from '@shared/infra/database/mongo-memory-database/types'; import { RabbitMQWrapperTestModule } from '@shared/infra/rabbitmq'; @@ -16,7 +16,7 @@ import { config, s3Config } from './fwu-learning-contents.config'; import { FwuLearningContentsUc } from './uc/fwu-learning-contents.uc'; const imports = [ - MongoMemoryDatabaseModule.forRoot({ entities: [User, Account, Role, SchoolEntity, System, SchoolYear] }), + MongoMemoryDatabaseModule.forRoot({ entities: [User, Account, Role, SchoolEntity, SystemEntity, SchoolYear] }), AuthorizationModule, AuthenticationModule, ConfigModule.forRoot(createConfigModuleOptions(config)), diff --git a/apps/server/src/modules/fwu-learning-contents/fwu-learning-contents.module.ts b/apps/server/src/modules/fwu-learning-contents/fwu-learning-contents.module.ts index ddb8d04fb35..112f0f15d5b 100644 --- a/apps/server/src/modules/fwu-learning-contents/fwu-learning-contents.module.ts +++ b/apps/server/src/modules/fwu-learning-contents/fwu-learning-contents.module.ts @@ -3,7 +3,7 @@ import { MikroOrmModule, MikroOrmModuleSyncOptions } from '@mikro-orm/nestjs'; import { HttpModule } from '@nestjs/axios'; import { Module, NotFoundException } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; -import { Account, Role, SchoolEntity, SchoolYear, System, User } from '@shared/domain'; +import { Account, Role, SchoolEntity, SchoolYear, SystemEntity, User } from '@shared/domain'; import { RabbitMQWrapperModule } from '@shared/infra/rabbitmq'; import { S3ClientModule } from '@shared/infra/s3-client'; import { DB_PASSWORD, DB_URL, DB_USERNAME, createConfigModuleOptions } from '@src/config'; @@ -36,7 +36,7 @@ const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = { clientUrl: DB_URL, password: DB_PASSWORD, user: DB_USERNAME, - entities: [User, Account, Role, SchoolEntity, System, SchoolYear], + entities: [User, Account, Role, SchoolEntity, SystemEntity, SchoolYear], // debug: true, // use it for locally debugging of querys }), diff --git a/apps/server/src/modules/group/repo/group-domain.mapper.ts b/apps/server/src/modules/group/repo/group-domain.mapper.ts index e203f7a2d46..33cb26ab9ae 100644 --- a/apps/server/src/modules/group/repo/group-domain.mapper.ts +++ b/apps/server/src/modules/group/repo/group-domain.mapper.ts @@ -1,5 +1,5 @@ import { EntityManager } from '@mikro-orm/mongodb'; -import { ExternalSource, ExternalSourceEntity, Role, SchoolEntity, System, User } from '@shared/domain'; +import { ExternalSource, ExternalSourceEntity, Role, SchoolEntity, SystemEntity, User } from '@shared/domain'; import { Group, GroupProps, GroupTypes, GroupUser } from '../domain'; import { GroupEntity, GroupEntityProps, GroupEntityTypes, GroupUserEntity, GroupValidPeriodEntity } from '../entity'; @@ -63,7 +63,7 @@ export class GroupDomainMapper { ): ExternalSourceEntity { const mapped = new ExternalSourceEntity({ externalId: externalSource.externalId, - system: em.getReference(System, externalSource.systemId), + system: em.getReference(SystemEntity, externalSource.systemId), }); return mapped; diff --git a/apps/server/src/modules/h5p-editor/h5p-editor.module.ts b/apps/server/src/modules/h5p-editor/h5p-editor.module.ts index 12a1c09b477..96d19f5cb24 100644 --- a/apps/server/src/modules/h5p-editor/h5p-editor.module.ts +++ b/apps/server/src/modules/h5p-editor/h5p-editor.module.ts @@ -2,7 +2,7 @@ import { Dictionary, IPrimaryKey } from '@mikro-orm/core'; import { MikroOrmModule, MikroOrmModuleSyncOptions } from '@mikro-orm/nestjs'; import { Module, NotFoundException } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; -import { Account, Role, SchoolEntity, SchoolYear, System, User } from '@shared/domain'; +import { Account, Role, SchoolEntity, SchoolYear, SystemEntity, User } from '@shared/domain'; import { DB_PASSWORD, DB_URL, DB_USERNAME, createConfigModuleOptions } from '@src/config'; import { CoreModule } from '@src/core'; import { Logger } from '@src/core/logger'; @@ -28,7 +28,7 @@ const imports = [ clientUrl: DB_URL, password: DB_PASSWORD, user: DB_USERNAME, - entities: [User, Account, Role, SchoolEntity, System, SchoolYear], + entities: [User, Account, Role, SchoolEntity, SystemEntity, SchoolYear], // debug: true, // use it for locally debugging of querys }), diff --git a/apps/server/src/modules/management/seed-data/schools.ts b/apps/server/src/modules/management/seed-data/schools.ts index 0808a6318f0..67bd86567dd 100644 --- a/apps/server/src/modules/management/seed-data/schools.ts +++ b/apps/server/src/modules/management/seed-data/schools.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/dot-notation */ -import { FederalState, ISchoolProperties, SchoolFeatures, SchoolRoles, SchoolYear, System } from '@shared/domain'; +import { FederalState, ISchoolProperties, SchoolFeatures, SchoolRoles, SchoolYear, SystemEntity } from '@shared/domain'; import { federalStateFactory, schoolFactory } from '@shared/testing'; import { DeepPartial } from 'fishery'; import { EFederalState } from './federalstates'; @@ -264,7 +264,7 @@ const seedSchools: SeedSchoolProperties[] = [ ]; export function generateSchools(entities: { - systems: System[]; + systems: SystemEntity[]; schoolYears: SchoolYear[]; federalStates: FederalState[]; }) { @@ -272,7 +272,7 @@ export function generateSchools(entities: { const schoolYear = entities.schoolYears.find((sy) => partial.currentYear && sy.name === partial.currentYear); const systems = partial.systems ?.map((systemId) => entities.systems.find((s) => s.id === systemId)) - .filter((s) => s) as System[] | undefined; + .filter((s) => s) as SystemEntity[] | undefined; const federalState = entities.federalStates.find((fs) => partial.federalState && fs.name === partial.federalState) ?? diff --git a/apps/server/src/modules/management/uc/database-management.uc.spec.ts b/apps/server/src/modules/management/uc/database-management.uc.spec.ts index 713b97d2dcb..d74ecb0475e 100644 --- a/apps/server/src/modules/management/uc/database-management.uc.spec.ts +++ b/apps/server/src/modules/management/uc/database-management.uc.spec.ts @@ -3,7 +3,7 @@ import { Configuration } from '@hpi-schul-cloud/commons/lib'; import { EntityManager } from '@mikro-orm/mongodb'; import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; -import { StorageProviderEntity, System } from '@shared/domain'; +import { StorageProviderEntity, SystemEntity } from '@shared/domain'; import { DatabaseManagementService } from '@shared/infra/database'; import { DefaultEncryptionService, @@ -496,11 +496,11 @@ describe('DatabaseManagementService', () => { dbService.collectionExists.mockReturnValue(Promise.resolve(false)); await uc.seedDatabaseCollectionsFromFileSystem([systemsCollectionName]); const importedSystems = dbService.importCollection.mock.calls[0][1]; - expect((importedSystems[0] as System).oauthConfig).toMatchObject({ + expect((importedSystems[0] as SystemEntity).oauthConfig).toMatchObject({ clientId: 'SANIS_CLIENT_ID', clientSecret: 'SANIS_CLIENT_SECRET', }); - expect((importedSystems[1] as System).oidcConfig).toMatchObject({ + expect((importedSystems[1] as SystemEntity).oidcConfig).toMatchObject({ clientId: 'OIDC_CLIENT_ID', clientSecret: 'OIDC_CLIENT_SECRET', }); @@ -512,11 +512,11 @@ describe('DatabaseManagementService', () => { dbService.collectionExists.mockReturnValue(Promise.resolve(false)); await uc.seedDatabaseCollectionsFromFileSystem([systemsCollectionName]); const importedSystems = dbService.importCollection.mock.calls[0][1]; - expect((importedSystems[0] as System).oauthConfig).toMatchObject({ + expect((importedSystems[0] as SystemEntity).oauthConfig).toMatchObject({ clientId: 'SANIS_CLIENT_ID_env', clientSecret: 'SANIS_CLIENT_SECRET_env', }); - expect((importedSystems[1] as System).oidcConfig).toMatchObject({ + expect((importedSystems[1] as SystemEntity).oidcConfig).toMatchObject({ clientId: 'OIDC_CLIENT_ID_env', clientSecret: 'OIDC_CLIENT_SECRET_env', }); @@ -528,11 +528,11 @@ describe('DatabaseManagementService', () => { dbService.collectionExists.mockReturnValue(Promise.resolve(false)); await uc.seedDatabaseCollectionsFromFileSystem([systemsCollectionName]); const importedSystems = dbService.importCollection.mock.calls[0][1]; - expect((importedSystems[0] as System).oauthConfig).toMatchObject({ + expect((importedSystems[0] as SystemEntity).oauthConfig).toMatchObject({ clientId: '', clientSecret: '', }); - expect((importedSystems[1] as System).oidcConfig).toMatchObject({ + expect((importedSystems[1] as SystemEntity).oidcConfig).toMatchObject({ clientId: '', clientSecret: '', }); @@ -560,7 +560,7 @@ describe('DatabaseManagementService', () => { expect(dbService.createCollection).toBeCalledWith(systemsCollectionName); expect(dbService.clearCollection).not.toBeCalled(); const importedSystems = dbService.importCollection.mock.calls[0][1]; - expect((importedSystems[0] as System).oauthConfig).toMatchObject({ + expect((importedSystems[0] as SystemEntity).oauthConfig).toMatchObject({ clientId: configurationCompareValue, clientSecret: configurationCompareValue, }); @@ -589,11 +589,11 @@ describe('DatabaseManagementService', () => { expect(dbService.createCollection).toBeCalledWith(systemsCollectionName); expect(dbService.clearCollection).not.toBeCalled(); const importedSystems = dbService.importCollection.mock.calls[0][1]; - expect((importedSystems[0] as System).oauthConfig).toMatchObject({ + expect((importedSystems[0] as SystemEntity).oauthConfig).toMatchObject({ clientId: 'SANIS_CLIENT_ID', clientSecret: 'SANIS_CLIENT_SECRET_encrypted', }); - expect((importedSystems[1] as System).oidcConfig).toMatchObject({ + expect((importedSystems[1] as SystemEntity).oidcConfig).toMatchObject({ clientId: 'OIDC_CLIENT_ID', clientSecret: 'OIDC_CLIENT_SECRET_encrypted', }); @@ -609,7 +609,7 @@ describe('DatabaseManagementService', () => { expect(dbService.createCollection).toBeCalledWith(systemsCollectionName); expect(dbService.clearCollection).not.toBeCalled(); const importedSystems = dbService.importCollection.mock.calls[0][1]; - expect(importedSystems as System[]).toEqual( + expect(importedSystems as SystemEntity[]).toEqual( expect.arrayContaining([ expect.objectContaining({ ldapConfig: { diff --git a/apps/server/src/modules/management/uc/database-management.uc.ts b/apps/server/src/modules/management/uc/database-management.uc.ts index 8505f6b87d5..5a51d249de9 100644 --- a/apps/server/src/modules/management/uc/database-management.uc.ts +++ b/apps/server/src/modules/management/uc/database-management.uc.ts @@ -2,7 +2,7 @@ import { Configuration } from '@hpi-schul-cloud/commons'; import { EntityManager } from '@mikro-orm/mongodb'; import { Inject, Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; -import { StorageProviderEntity, System } from '@shared/domain'; +import { StorageProviderEntity, SystemEntity } from '@shared/domain'; import { DatabaseManagementService } from '@shared/infra/database'; import { DefaultEncryptionService, IEncryptionService, LdapEncryptionService } from '@shared/infra/encryption'; import { FileSystemAdapter } from '@shared/infra/file-system'; @@ -167,7 +167,7 @@ export class DatabaseManagementUc { }) .map(async ({ collectionName, data }) => { if (collectionName === systemsCollectionName) { - this.encryptSecretsInSystems(data as System[]); + this.encryptSecretsInSystems(data as SystemEntity[]); } await this.dropCollectionIfExists(collectionName); @@ -348,11 +348,11 @@ export class DatabaseManagementUc { private encryptSecrets(collectionName: string, jsonDocuments: unknown[]) { if (collectionName === systemsCollectionName) { - this.encryptSecretsInSystems(jsonDocuments as System[]); + this.encryptSecretsInSystems(jsonDocuments as SystemEntity[]); } } - private encryptSecretsInSystems(systems: System[]) { + private encryptSecretsInSystems(systems: SystemEntity[]) { systems.forEach((system) => { if (system.oauthConfig) { system.oauthConfig.clientSecret = this.defaultEncryptionService.encrypt(system.oauthConfig.clientSecret); @@ -376,7 +376,7 @@ export class DatabaseManagementUc { */ private removeSecrets(collectionName: string, jsonDocuments: unknown[]) { if (collectionName === systemsCollectionName) { - this.removeSecretsFromSystems(jsonDocuments as System[]); + this.removeSecretsFromSystems(jsonDocuments as SystemEntity[]); } if (collectionName === storageprovidersCollectionName) { this.removeSecretsFromStorageproviders(jsonDocuments as StorageProviderEntity[]); @@ -390,7 +390,7 @@ export class DatabaseManagementUc { }); } - private removeSecretsFromSystems(systems: System[]) { + private removeSecretsFromSystems(systems: SystemEntity[]) { systems.forEach((system) => { if (system.oauthConfig) { system.oauthConfig.clientSecret = defaultSecretReplacementHintText; diff --git a/apps/server/src/modules/oauth/controller/api-test/oauth-sso.api.spec.ts b/apps/server/src/modules/oauth/controller/api-test/oauth-sso.api.spec.ts index 3f72fea25f5..4cec17e545b 100644 --- a/apps/server/src/modules/oauth/controller/api-test/oauth-sso.api.spec.ts +++ b/apps/server/src/modules/oauth/controller/api-test/oauth-sso.api.spec.ts @@ -2,7 +2,7 @@ import { Configuration } from '@hpi-schul-cloud/commons/lib'; import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; -import { Account, EntityId, SchoolEntity, System, User } from '@shared/domain'; +import { Account, EntityId, SchoolEntity, SystemEntity, User } from '@shared/domain'; import { UserLoginMigration } from '@shared/domain/entity/user-login-migration.entity'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; import { KeycloakAdministrationService } from '@shared/infra/identity-management/keycloak-administration/service/keycloak-administration.service'; @@ -114,7 +114,7 @@ describe('OAuth SSO Controller (API)', () => { const setup = async () => { const externalUserId = 'externalUserId'; - const system: System = systemFactory.withOauthConfig().buildWithId(); + const system: SystemEntity = systemFactory.withOauthConfig().buildWithId(); const school: SchoolEntity = schoolFactory.buildWithId({ systems: [system] }); const user: User = userFactory.buildWithId({ externalId: externalUserId, school }); const account: Account = accountFactory.buildWithId({ systemId: system.id, userId: user.id }); @@ -266,7 +266,7 @@ describe('OAuth SSO Controller (API)', () => { describe('[GET] sso/oauth/migration', () => { const mockPostOauthTokenEndpoint = ( idToken: string, - targetSystem: System, + targetSystem: SystemEntity, targetUserId: string, schoolExternalId: string, officialSchoolNumber: string @@ -318,10 +318,10 @@ describe('OAuth SSO Controller (API)', () => { const setupMigration = async () => { const { externalUserId, query } = await setup(); - const targetSystem: System = systemFactory + const targetSystem: SystemEntity = systemFactory .withOauthConfig() .buildWithId({ provisioningStrategy: SystemProvisioningStrategy.SANIS }, new ObjectId().toHexString(), {}); - const sourceSystem: System = systemFactory + const sourceSystem: SystemEntity = systemFactory .withOauthConfig() .buildWithId({ provisioningStrategy: SystemProvisioningStrategy.ISERV }, new ObjectId().toHexString(), {}); @@ -397,10 +397,10 @@ describe('OAuth SSO Controller (API)', () => { const setupMigration = async () => { const { externalUserId, query } = await setup(); - const targetSystem: System = systemFactory + const targetSystem: SystemEntity = systemFactory .withOauthConfig() .buildWithId({ provisioningStrategy: SystemProvisioningStrategy.SANIS }, new ObjectId().toHexString(), {}); - const sourceSystem: System = systemFactory + const sourceSystem: SystemEntity = systemFactory .withOauthConfig() .buildWithId({ provisioningStrategy: SystemProvisioningStrategy.ISERV }, new ObjectId().toHexString(), {}); @@ -445,10 +445,10 @@ describe('OAuth SSO Controller (API)', () => { const setupMigration = async () => { const { externalUserId, query } = await setup(); - const targetSystem: System = systemFactory + const targetSystem: SystemEntity = systemFactory .withOauthConfig() .buildWithId({ provisioningStrategy: SystemProvisioningStrategy.SANIS }, new ObjectId().toHexString(), {}); - const sourceSystem: System = systemFactory + const sourceSystem: SystemEntity = systemFactory .withOauthConfig() .buildWithId({ provisioningStrategy: SystemProvisioningStrategy.ISERV }, new ObjectId().toHexString(), {}); @@ -501,10 +501,10 @@ describe('OAuth SSO Controller (API)', () => { const setupMigration = async () => { const { externalUserId, query } = await setup(); - const targetSystem: System = systemFactory + const targetSystem: SystemEntity = systemFactory .withOauthConfig() .buildWithId({ provisioningStrategy: SystemProvisioningStrategy.SANIS }, new ObjectId().toHexString(), {}); - const sourceSystem: System = systemFactory + const sourceSystem: SystemEntity = systemFactory .withOauthConfig() .buildWithId({ provisioningStrategy: SystemProvisioningStrategy.ISERV }, new ObjectId().toHexString(), {}); diff --git a/apps/server/src/modules/oauth/service/oauth.service.spec.ts b/apps/server/src/modules/oauth/service/oauth.service.spec.ts index ae54342887f..5394070d273 100644 --- a/apps/server/src/modules/oauth/service/oauth.service.spec.ts +++ b/apps/server/src/modules/oauth/service/oauth.service.spec.ts @@ -1,7 +1,7 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { Configuration } from '@hpi-schul-cloud/commons'; import { Test, TestingModule } from '@nestjs/testing'; -import { LegacySchoolDo, OauthConfig, SchoolFeatures, System } from '@shared/domain'; +import { LegacySchoolDo, OauthConfig, SchoolFeatures, SystemEntity } from '@shared/domain'; import { UserDO } from '@shared/domain/domainobject/user.do'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; import { DefaultEncryptionService, IEncryptionService, SymetricKeyEncryptionService } from '@shared/infra/encryption'; @@ -50,7 +50,7 @@ describe('OAuthService', () => { let migrationCheckService: DeepMocked; let schoolService: DeepMocked; - let testSystem: System; + let testSystem: SystemEntity; let testOauthConfig: OauthConfig; const hostUri = 'https://mock.de'; diff --git a/apps/server/src/modules/system/controller/api-test/system.api.spec.ts b/apps/server/src/modules/system/controller/api-test/system.api.spec.ts index 3db2e6b156f..823b0d82abf 100644 --- a/apps/server/src/modules/system/controller/api-test/system.api.spec.ts +++ b/apps/server/src/modules/system/controller/api-test/system.api.spec.ts @@ -1,7 +1,7 @@ import { EntityManager } from '@mikro-orm/mongodb'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; -import { OauthConfig, System } from '@shared/domain'; +import { OauthConfig, SystemEntity } from '@shared/domain'; import { cleanupCollections, systemFactory } from '@shared/testing'; import { ICurrentUser } from '@src/modules/authentication'; import { JwtAuthGuard } from '@src/modules/authentication/guard/jwt-auth.guard'; @@ -46,8 +46,8 @@ describe('System (API)', () => { describe('[GET] systems/public', () => { describe('when the endpoint is called', () => { const setup = async () => { - const system1: System = systemFactory.buildWithId(); - const system2: System = systemFactory.withOauthConfig().buildWithId(); + const system1: SystemEntity = systemFactory.buildWithId(); + const system2: SystemEntity = systemFactory.withOauthConfig().buildWithId(); const system2OauthConfig: OauthConfig = system2.oauthConfig as OauthConfig; await em.persistAndFlush([system1, system2]); @@ -98,8 +98,8 @@ describe('System (API)', () => { describe('[GET] systems/public/:systemId', () => { describe('when the endpoint is called with a known systemId', () => { const setup = async () => { - const system1: System = systemFactory.buildWithId(); - const system2: System = systemFactory.buildWithId(); + const system1: SystemEntity = systemFactory.buildWithId(); + const system2: SystemEntity = systemFactory.buildWithId(); await em.persistAndFlush([system1, system2]); em.clear(); diff --git a/apps/server/src/modules/system/mapper/system-oidc.mapper.spec.ts b/apps/server/src/modules/system/mapper/system-oidc.mapper.spec.ts index 68a06e8f116..5cc88f020ad 100644 --- a/apps/server/src/modules/system/mapper/system-oidc.mapper.spec.ts +++ b/apps/server/src/modules/system/mapper/system-oidc.mapper.spec.ts @@ -1,5 +1,5 @@ import { Test, TestingModule } from '@nestjs/testing'; -import { System } from '@shared/domain'; +import { SystemEntity } from '@shared/domain'; import { systemFactory } from '@shared/testing'; import { SystemOidcMapper } from '@src/modules/system/mapper/system-oidc.mapper'; @@ -42,7 +42,10 @@ describe('SystemOidcMapper', () => { describe('mapFromEntitiesToDtos', () => { it('should map all given entities', () => { - const systemEntities: System[] = [systemFactory.withOidcConfig().build(), systemFactory.withOidcConfig().build()]; + const systemEntities: SystemEntity[] = [ + systemFactory.withOidcConfig().build(), + systemFactory.withOidcConfig().build(), + ]; const result = SystemOidcMapper.mapFromEntitiesToDtos(systemEntities); @@ -51,7 +54,7 @@ describe('SystemOidcMapper', () => { it('should map oidc config only config if exists', () => { const systemEntity = systemFactory.withOidcConfig().build(); - const systemEntities: System[] = [systemEntity, systemFactory.withOauthConfig().build()]; + const systemEntities: SystemEntity[] = [systemEntity, systemFactory.withOauthConfig().build()]; const results = SystemOidcMapper.mapFromEntitiesToDtos(systemEntities); diff --git a/apps/server/src/modules/system/mapper/system-oidc.mapper.ts b/apps/server/src/modules/system/mapper/system-oidc.mapper.ts index 65b1f9c444e..f62a2e022c9 100644 --- a/apps/server/src/modules/system/mapper/system-oidc.mapper.ts +++ b/apps/server/src/modules/system/mapper/system-oidc.mapper.ts @@ -1,8 +1,8 @@ -import { OidcConfig, System } from '@shared/domain'; +import { OidcConfig, SystemEntity } from '@shared/domain'; import { OidcConfigDto } from '@src/modules/system/service/dto/oidc-config.dto'; export class SystemOidcMapper { - static mapFromEntityToDto(entity: System): OidcConfigDto | undefined { + static mapFromEntityToDto(entity: SystemEntity): OidcConfigDto | undefined { if (entity.oidcConfig) { return SystemOidcMapper.mapFromOidcConfigEntityToDto(entity.id, entity.oidcConfig); } @@ -23,7 +23,7 @@ export class SystemOidcMapper { }); } - static mapFromEntitiesToDtos(entities: System[]): OidcConfigDto[] { + static mapFromEntitiesToDtos(entities: SystemEntity[]): OidcConfigDto[] { return entities .map((entity) => this.mapFromEntityToDto(entity)) .filter((entity): entity is OidcConfigDto => entity !== undefined); diff --git a/apps/server/src/modules/system/mapper/system.mapper.spec.ts b/apps/server/src/modules/system/mapper/system.mapper.spec.ts index 17382e34bad..21e9cf5f9b3 100644 --- a/apps/server/src/modules/system/mapper/system.mapper.spec.ts +++ b/apps/server/src/modules/system/mapper/system.mapper.spec.ts @@ -1,5 +1,5 @@ import { Test, TestingModule } from '@nestjs/testing'; -import { System } from '@shared/domain'; +import { SystemEntity } from '@shared/domain'; import { systemFactory } from '@shared/testing'; import { SystemMapper } from '@src/modules/system/mapper/system.mapper'; @@ -46,7 +46,7 @@ describe('SystemMapper', () => { describe('mapFromEntitiesToDtos', () => { it('should map all given entities', () => { - const systemEntities: System[] = [ + const systemEntities: SystemEntity[] = [ systemFactory.withOauthConfig().build(), systemFactory.build({ oauthConfig: undefined }), ]; @@ -57,7 +57,7 @@ describe('SystemMapper', () => { }); it('should map oauth config if exists', () => { - const systemEntities: System[] = [ + const systemEntities: SystemEntity[] = [ systemFactory.withOauthConfig().build(), systemFactory.build({ oauthConfig: undefined }), ]; diff --git a/apps/server/src/modules/system/mapper/system.mapper.ts b/apps/server/src/modules/system/mapper/system.mapper.ts index 85d969c981f..b464e54f263 100644 --- a/apps/server/src/modules/system/mapper/system.mapper.ts +++ b/apps/server/src/modules/system/mapper/system.mapper.ts @@ -1,9 +1,9 @@ -import { OauthConfig, System } from '@shared/domain'; +import { OauthConfig, SystemEntity } from '@shared/domain'; import { OauthConfigDto } from '@src/modules/system/service/dto/oauth-config.dto'; import { SystemDto } from '@src/modules/system/service/dto/system.dto'; export class SystemMapper { - static mapFromEntityToDto(entity: System): SystemDto { + static mapFromEntityToDto(entity: SystemEntity): SystemDto { return new SystemDto({ id: entity.id, type: entity.type, @@ -36,7 +36,7 @@ export class SystemMapper { }); } - static mapFromEntitiesToDtos(entities: System[]): SystemDto[] { + static mapFromEntitiesToDtos(entities: SystemEntity[]): SystemDto[] { return entities.map((entity) => this.mapFromEntityToDto(entity)); } } diff --git a/apps/server/src/modules/system/service/system-oidc.service.spec.ts b/apps/server/src/modules/system/service/system-oidc.service.spec.ts index f620f1a675e..6d85d5fb730 100644 --- a/apps/server/src/modules/system/service/system-oidc.service.spec.ts +++ b/apps/server/src/modules/system/service/system-oidc.service.spec.ts @@ -1,7 +1,7 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { Test, TestingModule } from '@nestjs/testing'; import { EntityNotFoundError } from '@shared/common'; -import { System } from '@shared/domain'; +import { SystemEntity } from '@shared/domain'; import { SystemRepo } from '@shared/repo'; import { systemFactory } from '@shared/testing'; import { SystemOidcMapper } from '../mapper/system-oidc.mapper'; @@ -37,7 +37,7 @@ describe('SystemService', () => { describe('findById', () => { const oidcSystem = systemFactory.withOidcConfig().buildWithId({ alias: 'oidcSystem' }); const standaloneSystem = systemFactory.buildWithId({ alias: 'standaloneSystem' }); - const setup = (system: System) => { + const setup = (system: SystemEntity) => { systemRepoMock.findById.mockResolvedValue(system); }; diff --git a/apps/server/src/modules/system/service/system-oidc.service.ts b/apps/server/src/modules/system/service/system-oidc.service.ts index a1efa4ae472..a4987ff47d8 100644 --- a/apps/server/src/modules/system/service/system-oidc.service.ts +++ b/apps/server/src/modules/system/service/system-oidc.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; import { EntityNotFoundError } from '@shared/common'; -import { EntityId, System, SystemTypeEnum } from '@shared/domain'; +import { EntityId, SystemEntity, SystemTypeEnum } from '@shared/domain'; import { SystemRepo } from '@shared/repo'; import { SystemOidcMapper } from '@src/modules/system/mapper/system-oidc.mapper'; import { OidcConfigDto } from './dto'; @@ -13,7 +13,7 @@ export class SystemOidcService { const system = await this.systemRepo.findById(id); const mappedEntity = SystemOidcMapper.mapFromEntityToDto(system); if (!mappedEntity) { - throw new EntityNotFoundError(System.name, { id }); + throw new EntityNotFoundError(SystemEntity.name, { id }); } return mappedEntity; } diff --git a/apps/server/src/modules/system/service/system.service.spec.ts b/apps/server/src/modules/system/service/system.service.spec.ts index d451a2d762b..ead44bf6133 100644 --- a/apps/server/src/modules/system/service/system.service.spec.ts +++ b/apps/server/src/modules/system/service/system.service.spec.ts @@ -1,7 +1,7 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { Test, TestingModule } from '@nestjs/testing'; import { EntityNotFoundError } from '@shared/common'; -import { OauthConfig, System, SystemTypeEnum } from '@shared/domain'; +import { OauthConfig, SystemEntity, SystemTypeEnum } from '@shared/domain'; import { IdentityManagementOauthService } from '@shared/infra/identity-management'; import { SystemRepo } from '@shared/repo'; import { systemFactory } from '@shared/testing'; @@ -46,7 +46,7 @@ describe('SystemService', () => { const standaloneSystem = systemFactory.buildWithId({ alias: 'standaloneSystem' }); const oidcSystem = systemFactory.withOidcConfig().buildWithId({ alias: 'oidcSystem' }); const oauthSystem = systemFactory.withOauthConfig().buildWithId({ alias: 'oauthSystem' }); - const setup = (system: System) => { + const setup = (system: SystemEntity) => { systemRepoMock.findById.mockResolvedValue(system); kcIdmOauthServiceMock.isOauthConfigAvailable.mockResolvedValue(true); kcIdmOauthServiceMock.getOauthConfig.mockResolvedValue(oauthSystem.oauthConfig as OauthConfig); @@ -97,7 +97,7 @@ describe('SystemService', () => { describe('when identity management is not available', () => { const standaloneSystem = systemFactory.buildWithId(); const oidcSystem = systemFactory.withOidcConfig().buildWithId(); - const setup = (system: System) => { + const setup = (system: SystemEntity) => { systemRepoMock.findById.mockResolvedValue(system); kcIdmOauthServiceMock.isOauthConfigAvailable.mockResolvedValue(false); }; diff --git a/apps/server/src/modules/system/service/system.service.ts b/apps/server/src/modules/system/service/system.service.ts index 5edcbf4f538..ec15c7d8bb3 100644 --- a/apps/server/src/modules/system/service/system.service.ts +++ b/apps/server/src/modules/system/service/system.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; import { EntityNotFoundError } from '@shared/common'; -import { EntityId, System, SystemTypeEnum } from '@shared/domain'; +import { EntityId, SystemEntity, SystemTypeEnum } from '@shared/domain'; import { IdentityManagementOauthService } from '@shared/infra/identity-management/identity-management-oauth.service'; import { SystemRepo } from '@shared/repo'; import { SystemMapper } from '@src/modules/system/mapper/system.mapper'; @@ -17,13 +17,13 @@ export class SystemService { let system = await this.systemRepo.findById(id); [system] = await this.generateBrokerSystems([system]); if (!system) { - throw new EntityNotFoundError(System.name, { id }); + throw new EntityNotFoundError(SystemEntity.name, { id }); } return SystemMapper.mapFromEntityToDto(system); } async findByType(type?: SystemTypeEnum): Promise { - let systems: System[]; + let systems: SystemEntity[]; if (type && type === SystemTypeEnum.OAUTH) { const oauthSystems = await this.systemRepo.findByFilter(SystemTypeEnum.OAUTH); const oidcSystems = await this.systemRepo.findByFilter(SystemTypeEnum.OIDC); @@ -38,7 +38,7 @@ export class SystemService { } async save(systemDto: SystemDto): Promise { - let system: System; + let system: SystemEntity; if (systemDto.id) { system = await this.systemRepo.findById(systemDto.id); system.type = systemDto.type; @@ -49,7 +49,7 @@ export class SystemService { system.provisioningUrl = systemDto.provisioningUrl; system.url = systemDto.url; } else { - system = new System({ + system = new SystemEntity({ type: systemDto.type, alias: systemDto.alias, displayName: systemDto.displayName, @@ -63,15 +63,15 @@ export class SystemService { return SystemMapper.mapFromEntityToDto(system); } - private async generateBrokerSystems(systems: System[]): Promise<[] | System[]> { + private async generateBrokerSystems(systems: SystemEntity[]): Promise<[] | SystemEntity[]> { if (!(await this.idmOauthService.isOauthConfigAvailable())) { return systems.filter((system) => !(system.oidcConfig && !system.oauthConfig)); } const brokerConfig = await this.idmOauthService.getOauthConfig(); - let generatedSystem: System; + let generatedSystem: SystemEntity; return systems.map((system) => { if (system.oidcConfig && !system.oauthConfig) { - generatedSystem = new System({ + generatedSystem = new SystemEntity({ type: SystemTypeEnum.OAUTH, alias: system.alias, displayName: system.displayName ? system.displayName : system.alias, diff --git a/apps/server/src/modules/system/uc/system.uc.spec.ts b/apps/server/src/modules/system/uc/system.uc.spec.ts index aa8b644f65d..21fc452c134 100644 --- a/apps/server/src/modules/system/uc/system.uc.spec.ts +++ b/apps/server/src/modules/system/uc/system.uc.spec.ts @@ -1,7 +1,7 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { Test, TestingModule } from '@nestjs/testing'; import { EntityNotFoundError } from '@shared/common'; -import { EntityId, System, SystemTypeEnum } from '@shared/domain'; +import { EntityId, SystemEntity, SystemTypeEnum } from '@shared/domain'; import { systemFactory } from '@shared/testing'; import { SystemMapper } from '@src/modules/system/mapper/system.mapper'; import { SystemDto } from '@src/modules/system/service/dto/system.dto'; @@ -14,8 +14,8 @@ describe('SystemUc', () => { let mockSystem1: SystemDto; let mockSystem2: SystemDto; let mockSystems: SystemDto[]; - let system1: System; - let system2: System; + let system1: SystemEntity; + let system2: SystemEntity; let systemService: DeepMocked; diff --git a/apps/server/src/modules/system/uc/system.uc.ts b/apps/server/src/modules/system/uc/system.uc.ts index b9bcc5acb07..89953cd29dc 100644 --- a/apps/server/src/modules/system/uc/system.uc.ts +++ b/apps/server/src/modules/system/uc/system.uc.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; import { EntityNotFoundError } from '@shared/common'; -import { EntityId, System, SystemType, SystemTypeEnum } from '@shared/domain'; +import { EntityId, SystemEntity, SystemType, SystemTypeEnum } from '@shared/domain'; import { SystemDto } from '@src/modules/system/service/dto/system.dto'; import { SystemService } from '@src/modules/system/service/system.service'; @@ -26,7 +26,7 @@ export class SystemUc { const system: SystemDto = await this.systemService.findById(id); if (system.ldapActive === false) { - throw new EntityNotFoundError(System.name, { id }); + throw new EntityNotFoundError(SystemEntity.name, { id }); } return system; diff --git a/apps/server/src/modules/user-import/controller/api-test/import-user.api.spec.ts b/apps/server/src/modules/user-import/controller/api-test/import-user.api.spec.ts index 215bc5acdba..0315d40ee26 100644 --- a/apps/server/src/modules/user-import/controller/api-test/import-user.api.spec.ts +++ b/apps/server/src/modules/user-import/controller/api-test/import-user.api.spec.ts @@ -11,7 +11,7 @@ import { SchoolEntity, SchoolFeatures, SortOrder, - System, + SystemEntity, User, } from '@shared/domain'; import { ICurrentUser } from '@src/modules/authentication'; @@ -161,7 +161,7 @@ describe('ImportUser Controller (API)', () => { }); describe('When authorization is missing', () => { let user: User; - let system: System; + let system: SystemEntity; beforeEach(async () => { ({ user, system } = await authenticatedUser()); currentUser = mapUserToCurrentUser(user); @@ -201,7 +201,7 @@ describe('ImportUser Controller (API)', () => { describe('When school is LDAP Migration Pilot School', () => { let user: User; let school: SchoolEntity; - let system: System; + let system: SystemEntity; beforeEach(async () => { ({ school, system, user } = await authenticatedUser( [Permission.SCHOOL_IMPORT_USERS_VIEW], @@ -222,7 +222,7 @@ describe('ImportUser Controller (API)', () => { describe('When current user has permission Permission.SCHOOL_IMPORT_USERS_VIEW', () => { let user: User; let school: SchoolEntity; - let system: System; + let system: SystemEntity; beforeEach(async () => { ({ school, system, user } = await authenticatedUser([Permission.SCHOOL_IMPORT_USERS_VIEW])); currentUser = mapUserToCurrentUser(user); @@ -265,7 +265,7 @@ describe('ImportUser Controller (API)', () => { describe('When current user has permission Permission.SCHOOL_IMPORT_USERS_UPDATE', () => { let user: User; let school: SchoolEntity; - let system: System; + let system: SystemEntity; beforeEach(async () => { ({ user, school, system } = await authenticatedUser([Permission.SCHOOL_IMPORT_USERS_UPDATE])); currentUser = mapUserToCurrentUser(user); @@ -315,7 +315,7 @@ describe('ImportUser Controller (API)', () => { }); describe('When current user has permissions Permission.SCHOOL_IMPORT_USERS_MIGRATE', () => { let user: User; - let system: System; + let system: SystemEntity; beforeEach(async () => { ({ user, system } = await authenticatedUser()); currentUser = mapUserToCurrentUser(user); @@ -952,7 +952,7 @@ describe('ImportUser Controller (API)', () => { describe('[startUserMigration]', () => { let user: User; - let system: System; + let system: SystemEntity; describe('POST user/import/startUserMigration', () => { it('should set in user migration mode', async () => { ({ user, system } = await authenticatedUser([Permission.SCHOOL_IMPORT_USERS_MIGRATE])); diff --git a/apps/server/src/modules/user-import/uc/user-import.uc.spec.ts b/apps/server/src/modules/user-import/uc/user-import.uc.spec.ts index 5e718058d37..3617b5c4e3d 100644 --- a/apps/server/src/modules/user-import/uc/user-import.uc.spec.ts +++ b/apps/server/src/modules/user-import/uc/user-import.uc.spec.ts @@ -13,7 +13,7 @@ import { Permission, SchoolEntity, SchoolFeatures, - System, + SystemEntity, User, } from '@shared/domain'; import { MongoMemoryDatabaseModule } from '@shared/infra/database'; @@ -123,7 +123,9 @@ describe('[ImportUserModule]', () => { const inMaintenanceSince = school ? school.inMaintenanceSince : undefined; const inUserMigration = school ? school.inUserMigration : undefined; const systems = - school && school.systems.isInitialized() ? school.systems.getItems().map((system: System) => system.id) : []; + school && school.systems.isInitialized() + ? school.systems.getItems().map((system: SystemEntity) => system.id) + : []; const federalState = school ? school.federalState : federalStateFactory.build(); return new LegacySchoolDo({ @@ -452,7 +454,7 @@ describe('[ImportUserModule]', () => { }); describe('[saveAllUsersMatches]', () => { - let system: System; + let system: SystemEntity; let school: SchoolEntity; let currentUser: User; let userMatch1: User; @@ -589,7 +591,7 @@ describe('[ImportUserModule]', () => { }); describe('[startSchoolInUserMigration]', () => { - let system: System; + let system: SystemEntity; let school: SchoolEntity; let currentUser: User; let userRepoByIdSpy: jest.SpyInstance; diff --git a/apps/server/src/modules/user-import/uc/user-import.uc.ts b/apps/server/src/modules/user-import/uc/user-import.uc.ts index ef0664c9ed7..3812b945cc6 100644 --- a/apps/server/src/modules/user-import/uc/user-import.uc.ts +++ b/apps/server/src/modules/user-import/uc/user-import.uc.ts @@ -14,7 +14,7 @@ import { MatchCreatorScope, Permission, SchoolFeatures, - System, + SystemEntity, User, } from '@shared/domain'; import { ImportUserRepo, SystemRepo, UserRepo } from '@shared/repo'; @@ -292,7 +292,7 @@ export class UserImportUc { await this.importUserRepo.delete(importUser); } - private async getMigrationSystem(): Promise { + private async getMigrationSystem(): Promise { const systemId = Configuration.get('FEATURE_USER_MIGRATION_SYSTEM_ID') as string; const system = await this.systemRepo.findById(systemId); return system; @@ -303,7 +303,7 @@ export class UserImportUc { for (const systemId of school.systems) { // very unusual to have more than 1 system // eslint-disable-next-line no-await-in-loop - const system: System = await this.systemRepo.findById(systemId); + const system: SystemEntity = await this.systemRepo.findById(systemId); if (system.ldapConfig) { throw new LdapAlreadyPersistedException(); } diff --git a/apps/server/src/modules/user-login-migration/controller/api-test/user-login-migration.api.spec.ts b/apps/server/src/modules/user-login-migration/controller/api-test/user-login-migration.api.spec.ts index 9f19a3ae71b..cc6fc43dcbf 100644 --- a/apps/server/src/modules/user-login-migration/controller/api-test/user-login-migration.api.spec.ts +++ b/apps/server/src/modules/user-login-migration/controller/api-test/user-login-migration.api.spec.ts @@ -2,7 +2,7 @@ import { Configuration } from '@hpi-schul-cloud/commons/lib'; import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; import { HttpStatus, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; -import { Permission, SchoolEntity, System, User } from '@shared/domain'; +import { Permission, SchoolEntity, SystemEntity, User } from '@shared/domain'; import { UserLoginMigration } from '@shared/domain/entity/user-login-migration.entity'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; import { @@ -69,8 +69,8 @@ describe('UserLoginMigrationController (API)', () => { describe('when data is given', () => { const setup = async () => { const date: Date = new Date(2023, 5, 4); - const sourceSystem: System = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); - const targetSystem: System = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); + const sourceSystem: SystemEntity = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); + const targetSystem: SystemEntity = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); const school: SchoolEntity = schoolFactory.buildWithId({ systems: [sourceSystem], }); @@ -133,8 +133,8 @@ describe('UserLoginMigrationController (API)', () => { describe('when a user login migration is found', () => { const setup = async () => { const date: Date = new Date(2023, 5, 4); - const sourceSystem: System = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); - const targetSystem: System = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); + const sourceSystem: SystemEntity = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); + const targetSystem: SystemEntity = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); const school: SchoolEntity = schoolFactory.buildWithId({ systems: [sourceSystem], }); @@ -219,8 +219,8 @@ describe('UserLoginMigrationController (API)', () => { describe('[POST] /start', () => { describe('when current User start the migration successfully', () => { const setup = async () => { - const sourceSystem: System = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); - const targetSystem: System = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); + const sourceSystem: SystemEntity = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); + const targetSystem: SystemEntity = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); const school: SchoolEntity = schoolFactory.buildWithId({ systems: [sourceSystem], officialSchoolNumber: '12345', @@ -281,8 +281,8 @@ describe('UserLoginMigrationController (API)', () => { describe('when migration already started', () => { const setup = async () => { const date: Date = new Date(2023, 5, 4); - const sourceSystem: System = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); - const targetSystem: System = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); + const sourceSystem: SystemEntity = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); + const targetSystem: SystemEntity = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); const school: SchoolEntity = schoolFactory.buildWithId({ systems: [sourceSystem], officialSchoolNumber: '12345', @@ -322,8 +322,8 @@ describe('UserLoginMigrationController (API)', () => { describe('when migration already closed', () => { const setup = async () => { const date: Date = new Date(2023, 5, 4); - const sourceSystem: System = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); - const targetSystem: System = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); + const sourceSystem: SystemEntity = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); + const targetSystem: SystemEntity = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); const school: SchoolEntity = schoolFactory.buildWithId({ systems: [sourceSystem], officialSchoolNumber: '12345', @@ -364,8 +364,8 @@ describe('UserLoginMigrationController (API)', () => { describe('when official school number is not set', () => { const setup = async () => { - const sourceSystem: System = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); - const targetSystem: System = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); + const sourceSystem: SystemEntity = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); + const targetSystem: SystemEntity = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); const school: SchoolEntity = schoolFactory.buildWithId({ systems: [sourceSystem], }); @@ -397,7 +397,7 @@ describe('UserLoginMigrationController (API)', () => { describe('[GET] /user-login-migrations/migrate-to-oauth2', () => { const mockPostOauthTokenEndpoint = ( idToken: string, - targetSystem: System, + targetSystem: SystemEntity, targetUserId: string, schoolExternalId: string, officialSchoolNumber: string @@ -439,7 +439,7 @@ describe('UserLoginMigrationController (API)', () => { describe('when providing a code and being eligible to migrate', () => { const setup = async () => { - const targetSystem: System = systemFactory + const targetSystem: SystemEntity = systemFactory .withOauthConfig() .buildWithId({ provisioningStrategy: SystemProvisioningStrategy.SANIS }); @@ -449,7 +449,7 @@ describe('UserLoginMigrationController (API)', () => { query.systemId = targetSystem.id; query.redirectUri = 'redirectUri'; - const sourceSystem: System = systemFactory.buildWithId(); + const sourceSystem: SystemEntity = systemFactory.buildWithId(); const officialSchoolNumber = '12345'; const externalId = 'aef1f4fd-c323-466e-962b-a84354c0e713'; @@ -507,7 +507,7 @@ describe('UserLoginMigrationController (API)', () => { describe('when migration failed, because of schoolnumbers mismatch', () => { const setup = async () => { - const targetSystem: System = systemFactory + const targetSystem: SystemEntity = systemFactory .withOauthConfig() .buildWithId({ provisioningStrategy: SystemProvisioningStrategy.SANIS }); @@ -516,7 +516,7 @@ describe('UserLoginMigrationController (API)', () => { query.systemId = targetSystem.id; query.redirectUri = 'redirectUri'; - const sourceSystem: System = systemFactory.buildWithId(); + const sourceSystem: SystemEntity = systemFactory.buildWithId(); const officialSchoolNumber = '12345'; const externalId = 'aef1f4fd-c323-466e-962b-a84354c0e713'; @@ -593,8 +593,8 @@ describe('UserLoginMigrationController (API)', () => { describe('[POST] /restart', () => { describe('when current User restart the migration successfully', () => { const setup = async () => { - const sourceSystem: System = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); - const targetSystem: System = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); + const sourceSystem: SystemEntity = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); + const targetSystem: SystemEntity = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); const school: SchoolEntity = schoolFactory.buildWithId({ systems: [sourceSystem], officialSchoolNumber: '12345', @@ -677,8 +677,8 @@ describe('UserLoginMigrationController (API)', () => { describe('when migration is already started', () => { const setup = async () => { - const sourceSystem: System = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); - const targetSystem: System = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); + const sourceSystem: SystemEntity = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); + const targetSystem: SystemEntity = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); const school: SchoolEntity = schoolFactory.buildWithId({ systems: [sourceSystem], officialSchoolNumber: '12345', @@ -717,8 +717,8 @@ describe('UserLoginMigrationController (API)', () => { describe('when migration is finally finished', () => { const setup = async () => { - const sourceSystem: System = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); - const targetSystem: System = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); + const sourceSystem: SystemEntity = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); + const targetSystem: SystemEntity = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); const school: SchoolEntity = schoolFactory.buildWithId({ systems: [sourceSystem], officialSchoolNumber: '12345', @@ -762,8 +762,8 @@ describe('UserLoginMigrationController (API)', () => { describe('[PUT] /mandatory', () => { describe('when migration is set from optional to mandatory', () => { const setup = async () => { - const sourceSystem: System = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); - const targetSystem: System = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); + const sourceSystem: SystemEntity = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); + const targetSystem: SystemEntity = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); const school: SchoolEntity = schoolFactory.buildWithId({ systems: [sourceSystem], officialSchoolNumber: '12345', @@ -805,8 +805,8 @@ describe('UserLoginMigrationController (API)', () => { describe('when migration is set from mandatory to optional', () => { const setup = async () => { - const sourceSystem: System = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); - const targetSystem: System = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); + const sourceSystem: SystemEntity = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); + const targetSystem: SystemEntity = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); const school: SchoolEntity = schoolFactory.buildWithId({ systems: [sourceSystem], officialSchoolNumber: '12345', @@ -849,8 +849,8 @@ describe('UserLoginMigrationController (API)', () => { describe('when migration is not started', () => { const setup = async () => { - const sourceSystem: System = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); - const targetSystem: System = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); + const sourceSystem: SystemEntity = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); + const targetSystem: SystemEntity = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); const school: SchoolEntity = schoolFactory.buildWithId({ systems: [sourceSystem], officialSchoolNumber: '12345', @@ -881,8 +881,8 @@ describe('UserLoginMigrationController (API)', () => { describe('when the migration is closed', () => { const setup = async () => { - const sourceSystem: System = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); - const targetSystem: System = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); + const sourceSystem: SystemEntity = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); + const targetSystem: SystemEntity = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); const school: SchoolEntity = schoolFactory.buildWithId({ systems: [sourceSystem], officialSchoolNumber: '12345', @@ -931,8 +931,8 @@ describe('UserLoginMigrationController (API)', () => { describe('when user has not the required permission', () => { const setup = async () => { - const sourceSystem: System = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); - const targetSystem: System = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); + const sourceSystem: SystemEntity = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); + const targetSystem: SystemEntity = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); const school: SchoolEntity = schoolFactory.buildWithId({ systems: [sourceSystem], officialSchoolNumber: '12345', @@ -973,8 +973,8 @@ describe('UserLoginMigrationController (API)', () => { describe('[POST] /close', () => { describe('when the user login migration is running', () => { const setup = async () => { - const sourceSystem: System = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); - const targetSystem: System = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); + const sourceSystem: SystemEntity = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); + const targetSystem: SystemEntity = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); const school: SchoolEntity = schoolFactory.buildWithId({ systems: [sourceSystem], officialSchoolNumber: '12345', @@ -1038,8 +1038,8 @@ describe('UserLoginMigrationController (API)', () => { describe('when migration is not started', () => { const setup = async () => { - const sourceSystem: System = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); - const targetSystem: System = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); + const sourceSystem: SystemEntity = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); + const targetSystem: SystemEntity = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); const school: SchoolEntity = schoolFactory.buildWithId({ systems: [sourceSystem], officialSchoolNumber: '12345', @@ -1070,8 +1070,8 @@ describe('UserLoginMigrationController (API)', () => { describe('when the migration is already closed', () => { const setup = async () => { - const sourceSystem: System = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); - const targetSystem: System = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); + const sourceSystem: SystemEntity = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); + const targetSystem: SystemEntity = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); const school: SchoolEntity = schoolFactory.buildWithId({ systems: [sourceSystem], officialSchoolNumber: '12345', @@ -1116,8 +1116,8 @@ describe('UserLoginMigrationController (API)', () => { describe('when the migration is finished', () => { const setup = async () => { - const sourceSystem: System = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); - const targetSystem: System = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); + const sourceSystem: SystemEntity = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); + const targetSystem: SystemEntity = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); const school: SchoolEntity = schoolFactory.buildWithId({ systems: [sourceSystem], officialSchoolNumber: '12345', @@ -1166,8 +1166,8 @@ describe('UserLoginMigrationController (API)', () => { describe('when user has not the required permission', () => { const setup = async () => { - const sourceSystem: System = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); - const targetSystem: System = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); + const sourceSystem: SystemEntity = systemFactory.withLdapConfig().buildWithId({ alias: 'SourceSystem' }); + const targetSystem: SystemEntity = systemFactory.withOauthConfig().buildWithId({ alias: 'SANIS' }); const school: SchoolEntity = schoolFactory.buildWithId({ systems: [sourceSystem], officialSchoolNumber: '12345', diff --git a/apps/server/src/modules/user-login-migration/uc/user-login-migration.uc.spec.ts b/apps/server/src/modules/user-login-migration/uc/user-login-migration.uc.spec.ts index 3ac2aec3b4e..e9fc294f2ce 100644 --- a/apps/server/src/modules/user-login-migration/uc/user-login-migration.uc.spec.ts +++ b/apps/server/src/modules/user-login-migration/uc/user-login-migration.uc.spec.ts @@ -2,7 +2,7 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { ForbiddenException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { NotFoundLoggableException } from '@shared/common/loggable-exception'; -import { Page, Permission, LegacySchoolDo, System, User, UserLoginMigrationDO } from '@shared/domain'; +import { Page, Permission, LegacySchoolDo, SystemEntity, User, UserLoginMigrationDO } from '@shared/domain'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; import { legacySchoolDoFactory, @@ -300,7 +300,7 @@ describe('UserLoginMigrationUc', () => { query.systemId = 'systemId'; query.redirectUri = 'redirectUri'; - const sourceSystem: System = systemFactory + const sourceSystem: SystemEntity = systemFactory .withOauthConfig() .buildWithId({ provisioningStrategy: SystemProvisioningStrategy.SANIS }); @@ -415,7 +415,7 @@ describe('UserLoginMigrationUc', () => { query.systemId = 'systemId'; query.redirectUri = 'redirectUri'; - const sourceSystem: System = systemFactory + const sourceSystem: SystemEntity = systemFactory .withOauthConfig() .buildWithId({ provisioningStrategy: SystemProvisioningStrategy.SANIS }); @@ -479,7 +479,7 @@ describe('UserLoginMigrationUc', () => { query.systemId = 'systemId'; query.redirectUri = 'redirectUri'; - const sourceSystem: System = systemFactory + const sourceSystem: SystemEntity = systemFactory .withOauthConfig() .buildWithId({ provisioningStrategy: SystemProvisioningStrategy.SANIS }); @@ -615,7 +615,7 @@ describe('UserLoginMigrationUc', () => { query.systemId = 'systemId'; query.redirectUri = 'redirectUri'; - const sourceSystem: System = systemFactory + const sourceSystem: SystemEntity = systemFactory .withOauthConfig() .buildWithId({ provisioningStrategy: SystemProvisioningStrategy.SANIS }); diff --git a/apps/server/src/shared/domain/entity/all-entities.ts b/apps/server/src/shared/domain/entity/all-entities.ts index 2b136fea610..4fce6735548 100644 --- a/apps/server/src/shared/domain/entity/all-entities.ts +++ b/apps/server/src/shared/domain/entity/all-entities.ts @@ -38,7 +38,7 @@ import { SchoolEntity, SchoolRolePermission, SchoolRoles } from './school.entity import { SchoolYear } from './schoolyear.entity'; import { StorageProviderEntity } from './storageprovider.entity'; import { Submission } from './submission.entity'; -import { System } from './system.entity'; +import { SystemEntity } from './system.entity'; import { Task } from './task.entity'; import { TeamEntity, TeamUserEntity } from './team.entity'; import { UserLoginMigration } from './user-login-migration.entity'; @@ -86,7 +86,7 @@ export const ALL_ENTITIES = [ ShareToken, StorageProviderEntity, Submission, - System, + SystemEntity, Task, TaskBoardElement, TeamEntity, diff --git a/apps/server/src/shared/domain/entity/external-source.entity.ts b/apps/server/src/shared/domain/entity/external-source.entity.ts index fabe2f03d83..916ae4f02b7 100644 --- a/apps/server/src/shared/domain/entity/external-source.entity.ts +++ b/apps/server/src/shared/domain/entity/external-source.entity.ts @@ -1,10 +1,10 @@ import { Embeddable, ManyToOne, Property } from '@mikro-orm/core'; -import { System } from './system.entity'; +import { SystemEntity } from './system.entity'; export interface ExternalSourceEntityProps { externalId: string; - system: System; + system: SystemEntity; } @Embeddable() @@ -12,8 +12,8 @@ export class ExternalSourceEntity { @Property() externalId: string; - @ManyToOne(() => System) - system: System; + @ManyToOne(() => SystemEntity) + system: SystemEntity; constructor(props: ExternalSourceEntityProps) { this.externalId = props.externalId; diff --git a/apps/server/src/shared/domain/entity/import-user.entity.ts b/apps/server/src/shared/domain/entity/import-user.entity.ts index 6ff9eb22938..430efdb9652 100644 --- a/apps/server/src/shared/domain/entity/import-user.entity.ts +++ b/apps/server/src/shared/domain/entity/import-user.entity.ts @@ -2,7 +2,7 @@ import { Entity, Enum, IdentifiedReference, ManyToOne, Property, Unique, wrap } import { IEntityWithSchool, RoleName } from '../interface'; import { BaseEntityReference, BaseEntityWithTimestamps } from './base.entity'; import { SchoolEntity } from './school.entity'; -import { System } from './system.entity'; +import { SystemEntity } from './system.entity'; import type { User } from './user.entity'; export type IImportUserRoleName = RoleName.ADMINISTRATOR | RoleName.TEACHER | RoleName.STUDENT; @@ -10,7 +10,7 @@ export type IImportUserRoleName = RoleName.ADMINISTRATOR | RoleName.TEACHER | Ro export interface IImportUserProperties { // references school: SchoolEntity; - system: System; + system: SystemEntity; // external identifiers ldapDn: string; externalId: string; @@ -54,7 +54,7 @@ export class ImportUser extends BaseEntityWithTimestamps implements IEntityWithS school: IdentifiedReference; @ManyToOne(() => 'System', { wrappedReference: true }) - system: IdentifiedReference; + system: IdentifiedReference; @Property() ldapDn: string; diff --git a/apps/server/src/shared/domain/entity/school.entity.ts b/apps/server/src/shared/domain/entity/school.entity.ts index eb746bfeafb..7069279526c 100644 --- a/apps/server/src/shared/domain/entity/school.entity.ts +++ b/apps/server/src/shared/domain/entity/school.entity.ts @@ -12,7 +12,7 @@ import { import { UserLoginMigration } from '@shared/domain/entity/user-login-migration.entity'; import { BaseEntity } from './base.entity'; import { SchoolYear } from './schoolyear.entity'; -import { System } from './system.entity'; +import { SystemEntity } from './system.entity'; import { FederalState } from './federal-state.entity'; export enum SchoolFeatures { @@ -34,7 +34,7 @@ export interface ISchoolProperties { previousExternalId?: string; name: string; officialSchoolNumber?: string; - systems?: System[]; + systems?: SystemEntity[]; features?: SchoolFeatures[]; schoolYear?: SchoolYear; userLoginMigration?: UserLoginMigration; @@ -84,7 +84,7 @@ export class SchoolEntity extends BaseEntity { officialSchoolNumber?: string; @ManyToMany('System', undefined, { fieldName: 'systems' }) - systems = new Collection(this); + systems = new Collection(this); @Embedded(() => SchoolRoles, { object: true, nullable: true, prefix: false }) permissions?: SchoolRoles; diff --git a/apps/server/src/shared/domain/entity/system.entity.spec.ts b/apps/server/src/shared/domain/entity/system.entity.spec.ts index 2135d91c4b1..9b1c538673f 100644 --- a/apps/server/src/shared/domain/entity/system.entity.spec.ts +++ b/apps/server/src/shared/domain/entity/system.entity.spec.ts @@ -1,7 +1,7 @@ import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; import { setupEntities } from '@shared/testing'; import { systemFactory } from '@shared/testing/factory/system.factory'; -import { System } from './system.entity'; +import { SystemEntity } from './system.entity'; describe('System Entity', () => { beforeAll(async () => { @@ -11,14 +11,14 @@ describe('System Entity', () => { describe('constructor', () => { it('should throw an error by empty constructor', () => { // @ts-expect-error: Test case - const test = () => new System(); + const test = () => new SystemEntity(); expect(test).toThrow(); }); it('should create a system by passing required properties', () => { const system = systemFactory.build(); - expect(system instanceof System).toEqual(true); + expect(system instanceof SystemEntity).toEqual(true); }); it('should create a system by passing required and optional properties', () => { @@ -26,7 +26,7 @@ describe('System Entity', () => { .withOauthConfig() .build({ url: 'SAMPLE_URL', alias: 'SAMPLE_ALIAS', displayName: 'SAMPLE_NAME' }); - expect(system instanceof System).toEqual(true); + expect(system instanceof SystemEntity).toEqual(true); expect(system).toEqual( expect.objectContaining({ type: 'oauth', diff --git a/apps/server/src/shared/domain/entity/system.entity.ts b/apps/server/src/shared/domain/entity/system.entity.ts index 8fc4d130be4..8f1b5821fbd 100644 --- a/apps/server/src/shared/domain/entity/system.entity.ts +++ b/apps/server/src/shared/domain/entity/system.entity.ts @@ -188,7 +188,7 @@ export class OidcConfig { } @Entity({ tableName: 'systems' }) -export class System extends BaseEntityWithTimestamps { +export class SystemEntity extends BaseEntityWithTimestamps { constructor(props: ISystemProperties) { super(); this.type = props.type; diff --git a/apps/server/src/shared/domain/entity/user-login-migration.entity.ts b/apps/server/src/shared/domain/entity/user-login-migration.entity.ts index 15703688aff..3093f85bc44 100644 --- a/apps/server/src/shared/domain/entity/user-login-migration.entity.ts +++ b/apps/server/src/shared/domain/entity/user-login-migration.entity.ts @@ -1,6 +1,6 @@ import { Entity, ManyToOne, OneToOne, Property } from '@mikro-orm/core'; import { SchoolEntity } from '@shared/domain/entity/school.entity'; -import { System } from '@shared/domain/entity/system.entity'; +import { SystemEntity } from '@shared/domain/entity/system.entity'; import { BaseEntityWithTimestamps } from './base.entity'; export type IUserLoginMigration = Readonly>; @@ -11,11 +11,11 @@ export class UserLoginMigration extends BaseEntityWithTimestamps { school: SchoolEntity; // undefined, if migrating from 'local' - @ManyToOne(() => System, { nullable: true }) - sourceSystem?: System; + @ManyToOne(() => SystemEntity, { nullable: true }) + sourceSystem?: SystemEntity; - @ManyToOne(() => System) - targetSystem: System; + @ManyToOne(() => SystemEntity) + targetSystem: SystemEntity; @Property({ nullable: true }) mandatorySince?: Date; diff --git a/apps/server/src/shared/infra/identity-management/keycloak-configuration/service/keycloak-configuration.service.spec.ts b/apps/server/src/shared/infra/identity-management/keycloak-configuration/service/keycloak-configuration.service.spec.ts index 6df642bcb00..012d63d18c2 100644 --- a/apps/server/src/shared/infra/identity-management/keycloak-configuration/service/keycloak-configuration.service.spec.ts +++ b/apps/server/src/shared/infra/identity-management/keycloak-configuration/service/keycloak-configuration.service.spec.ts @@ -9,7 +9,7 @@ import { Realms } from '@keycloak/keycloak-admin-client/lib/resources/realms'; import { HttpService } from '@nestjs/axios'; import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; -import { System, SystemTypeEnum } from '@shared/domain'; +import { SystemEntity, SystemTypeEnum } from '@shared/domain'; import { SymetricKeyEncryptionService } from '@shared/infra/encryption'; import { systemFactory } from '@shared/testing'; import { SystemOidcMapper } from '@src/modules/system/mapper/system-oidc.mapper'; @@ -63,7 +63,7 @@ describe('KeycloakConfigurationService Unit', () => { }; }; - const systems: System[] = systemFactory.withOidcConfig().buildListWithId(1, { type: SystemTypeEnum.OIDC }); + const systems: SystemEntity[] = systemFactory.withOidcConfig().buildListWithId(1, { type: SystemTypeEnum.OIDC }); const oidcSystems = SystemOidcMapper.mapFromEntitiesToDtos(systems); const idps: IdentityProviderRepresentation[] = [ { diff --git a/apps/server/src/shared/repo/school/legacy-school.repo.integration.spec.ts b/apps/server/src/shared/repo/school/legacy-school.repo.integration.spec.ts index 09c00d14171..74254379507 100644 --- a/apps/server/src/shared/repo/school/legacy-school.repo.integration.spec.ts +++ b/apps/server/src/shared/repo/school/legacy-school.repo.integration.spec.ts @@ -10,7 +10,7 @@ import { SchoolRolePermission, SchoolRoles, SchoolYear, - System, + SystemEntity, UserLoginMigration, } from '@shared/domain'; import { MongoMemoryDatabaseModule } from '@shared/infra/database'; @@ -114,7 +114,7 @@ describe('LegacySchoolRepo', () => { describe('findByExternalId', () => { it('should find school by external ID', async () => { - const system: System = systemFactory.buildWithId(); + const system: SystemEntity = systemFactory.buildWithId(); const schoolEntity: SchoolEntity = schoolFactory.build({ externalId: 'externalId' }); schoolEntity.systems.add(system); @@ -182,7 +182,7 @@ describe('LegacySchoolRepo', () => { describe('mapEntityToDO is called', () => { it('should map school entity to school domain object', () => { - const system: System = systemFactory.buildWithId(); + const system: SystemEntity = systemFactory.buildWithId(); const schoolYear: SchoolYear = schoolYearFactory.buildWithId(); const schoolEntity: SchoolEntity = schoolFactory.buildWithId({ systems: [system], features: [], schoolYear }); const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.build({ school: schoolEntity }); @@ -219,8 +219,8 @@ describe('LegacySchoolRepo', () => { describe('mapDOToEntityProperties is called', () => { const setup = async () => { - const system1: System = systemFactory.buildWithId(); - const system2: System = systemFactory.buildWithId(); + const system1: SystemEntity = systemFactory.buildWithId(); + const system2: SystemEntity = systemFactory.buildWithId(); const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId(); @@ -258,8 +258,8 @@ describe('LegacySchoolRepo', () => { expect(result.federalState).toEqual(entityDO.federalState); expect(emGetReferenceSpy).toHaveBeenCalledTimes(3); - expect(emGetReferenceSpy).toHaveBeenNthCalledWith(1, System, system1.id); - expect(emGetReferenceSpy).toHaveBeenNthCalledWith(2, System, system2.id); + expect(emGetReferenceSpy).toHaveBeenNthCalledWith(1, SystemEntity, system1.id); + expect(emGetReferenceSpy).toHaveBeenNthCalledWith(2, SystemEntity, system2.id); expect(emGetReferenceSpy).toHaveBeenNthCalledWith(3, UserLoginMigration, userLoginMigration.id); }); diff --git a/apps/server/src/shared/repo/school/legacy-school.repo.ts b/apps/server/src/shared/repo/school/legacy-school.repo.ts index 3c8018c63aa..335b5286214 100644 --- a/apps/server/src/shared/repo/school/legacy-school.repo.ts +++ b/apps/server/src/shared/repo/school/legacy-school.repo.ts @@ -1,7 +1,14 @@ import { EntityName } from '@mikro-orm/core'; import { EntityManager } from '@mikro-orm/mongodb'; import { Injectable, InternalServerErrorException } from '@nestjs/common'; -import { EntityId, ISchoolProperties, LegacySchoolDo, SchoolEntity, System, UserLoginMigration } from '@shared/domain'; +import { + EntityId, + ISchoolProperties, + LegacySchoolDo, + SchoolEntity, + SystemEntity, + UserLoginMigration, +} from '@shared/domain'; import { LegacyLogger } from '@src/core/logger'; import { BaseDORepo } from '../base.do.repo'; @@ -50,7 +57,7 @@ export class LegacySchoolRepo extends BaseDORepo system.id) : [], + systems: entity.systems.isInitialized() ? entity.systems.getItems().map((system: SystemEntity) => system.id) : [], userLoginMigrationId: entity.userLoginMigration?.id, federalState: entity.federalState, }); @@ -67,7 +74,7 @@ export class LegacySchoolRepo extends BaseDORepo this._em.getReference(System, systemId)) + ? entityDO.systems.map((systemId: EntityId) => this._em.getReference(SystemEntity, systemId)) : [], userLoginMigration: entityDO.userLoginMigrationId ? this._em.getReference(UserLoginMigration, entityDO.userLoginMigrationId) diff --git a/apps/server/src/shared/repo/system/system-scope.ts b/apps/server/src/shared/repo/system/system-scope.ts index 580a78e14bf..2fea3720e19 100644 --- a/apps/server/src/shared/repo/system/system-scope.ts +++ b/apps/server/src/shared/repo/system/system-scope.ts @@ -1,7 +1,7 @@ -import { System } from '@shared/domain'; +import { SystemEntity } from '@shared/domain'; import { Scope } from '../scope'; -export class SystemScope extends Scope { +export class SystemScope extends Scope { withLdapConfig(): SystemScope { this.addQuery({ ldapConfig: { $ne: null } }); return this; diff --git a/apps/server/src/shared/repo/system/system.repo.integration.spec.ts b/apps/server/src/shared/repo/system/system.repo.integration.spec.ts index 56141ad4007..7c3c10a2fab 100644 --- a/apps/server/src/shared/repo/system/system.repo.integration.spec.ts +++ b/apps/server/src/shared/repo/system/system.repo.integration.spec.ts @@ -1,7 +1,7 @@ import { NotFoundError } from '@mikro-orm/core'; import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; import { Test, TestingModule } from '@nestjs/testing'; -import { System, SystemTypeEnum } from '@shared/domain'; +import { SystemEntity, SystemTypeEnum } from '@shared/domain'; import { MongoMemoryDatabaseModule } from '@shared/infra/database'; import { SystemRepo } from '@shared/repo'; import { systemFactory } from '@shared/testing/factory/system.factory'; @@ -30,12 +30,12 @@ describe('system repo', () => { }); it('should implement entityName getter', () => { - expect(repo.entityName).toBe(System); + expect(repo.entityName).toBe(SystemEntity); }); describe('findById', () => { afterEach(async () => { - await em.nativeDelete(System, {}); + await em.nativeDelete(SystemEntity, {}); }); it('should return right keys', async () => { @@ -76,7 +76,7 @@ describe('system repo', () => { describe('findAll', () => { afterEach(async () => { - await em.nativeDelete(System, {}); + await em.nativeDelete(SystemEntity, {}); }); it('should return all systems', async () => { @@ -100,7 +100,7 @@ describe('system repo', () => { }); afterAll(async () => { - await em.nativeDelete(System, {}); + await em.nativeDelete(SystemEntity, {}); }); describe('when searching for a system type', () => { diff --git a/apps/server/src/shared/repo/system/system.repo.ts b/apps/server/src/shared/repo/system/system.repo.ts index 67333f8c17a..65fd257cc24 100644 --- a/apps/server/src/shared/repo/system/system.repo.ts +++ b/apps/server/src/shared/repo/system/system.repo.ts @@ -1,15 +1,15 @@ import { Injectable } from '@nestjs/common'; -import { System, SystemTypeEnum } from '@shared/domain'; +import { SystemEntity, SystemTypeEnum } from '@shared/domain'; import { BaseRepo } from '@shared/repo/base.repo'; import { SystemScope } from '@shared/repo/system/system-scope'; @Injectable() -export class SystemRepo extends BaseRepo { +export class SystemRepo extends BaseRepo { get entityName() { - return System; + return SystemEntity; } - async findByFilter(type: SystemTypeEnum): Promise { + async findByFilter(type: SystemTypeEnum): Promise { const scope = new SystemScope(); switch (type) { case SystemTypeEnum.LDAP: @@ -25,10 +25,10 @@ export class SystemRepo extends BaseRepo { // eslint-disable-next-line @typescript-eslint/restrict-template-expressions throw new Error(`system type ${type} unknown`); } - return this._em.find(System, scope.query); + return this._em.find(SystemEntity, scope.query); } - async findAll(): Promise { - return this._em.find(System, {}); + async findAll(): Promise { + return this._em.find(SystemEntity, {}); } } diff --git a/apps/server/src/shared/repo/user/user-do.repo.integration.spec.ts b/apps/server/src/shared/repo/user/user-do.repo.integration.spec.ts index c6eff493b85..0d273283ec2 100644 --- a/apps/server/src/shared/repo/user/user-do.repo.integration.spec.ts +++ b/apps/server/src/shared/repo/user/user-do.repo.integration.spec.ts @@ -11,7 +11,7 @@ import { RoleName, SchoolEntity, SortOrder, - System, + SystemEntity, User, } from '@shared/domain'; import { Page } from '@shared/domain/domainobject/page'; @@ -141,7 +141,7 @@ describe('UserRepo', () => { describe('findByExternalId', () => { const externalId = 'externalId'; - let system: System; + let system: SystemEntity; let school: SchoolEntity; let user: User; @@ -185,7 +185,7 @@ describe('UserRepo', () => { describe('findByExternalIdOrFail', () => { const externalId = 'externalId'; - let system: System; + let system: SystemEntity; let school: SchoolEntity; let user: User; diff --git a/apps/server/src/shared/repo/user/user-do.repo.ts b/apps/server/src/shared/repo/user/user-do.repo.ts index f220195f46c..1856befc18b 100644 --- a/apps/server/src/shared/repo/user/user-do.repo.ts +++ b/apps/server/src/shared/repo/user/user-do.repo.ts @@ -10,7 +10,7 @@ import { SchoolEntity, SortOrder, SortOrderMap, - System, + SystemEntity, User, } from '@shared/domain'; import { RoleReference } from '@shared/domain/domainobject'; @@ -80,7 +80,7 @@ export class UserDORepo extends BaseDORepo { const userEntitys: User[] = await this._em.find(User, { externalId }, { populate: ['school.systems'] }); const userEntity: User | undefined = userEntitys.find((user: User): boolean => { const { systems } = user.school; - return systems && !!systems.getItems().find((system: System): boolean => system.id === systemId); + return systems && !!systems.getItems().find((system: SystemEntity): boolean => system.id === systemId); }); const userDo: UserDO | null = userEntity ? this.mapEntityToDO(userEntity) : null; diff --git a/apps/server/src/shared/repo/user/user.repo.integration.spec.ts b/apps/server/src/shared/repo/user/user.repo.integration.spec.ts index b20522a0629..04e19284040 100644 --- a/apps/server/src/shared/repo/user/user.repo.integration.spec.ts +++ b/apps/server/src/shared/repo/user/user.repo.integration.spec.ts @@ -1,7 +1,7 @@ import { NotFoundError } from '@mikro-orm/core'; import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; import { Test, TestingModule } from '@nestjs/testing'; -import { MatchCreator, SortOrder, System, User } from '@shared/domain'; +import { MatchCreator, SortOrder, SystemEntity, User } from '@shared/domain'; import { MongoMemoryDatabaseModule } from '@shared/infra/database'; import { cleanupCollections, importUserFactory, roleFactory, schoolFactory, userFactory } from '@shared/testing'; import { systemFactory } from '@shared/testing/factory/system.factory'; @@ -119,7 +119,7 @@ describe('user repo', () => { }); describe('findByExternalIdorFail', () => { - let sys: System; + let sys: SystemEntity; let userA: User; let userB: User; beforeEach(async () => { diff --git a/apps/server/src/shared/repo/userloginmigration/user-login-migration.repo.integration.spec.ts b/apps/server/src/shared/repo/userloginmigration/user-login-migration.repo.integration.spec.ts index be24029a942..ed4984dffe4 100644 --- a/apps/server/src/shared/repo/userloginmigration/user-login-migration.repo.integration.spec.ts +++ b/apps/server/src/shared/repo/userloginmigration/user-login-migration.repo.integration.spec.ts @@ -1,7 +1,7 @@ import { createMock } from '@golevelup/ts-jest'; import { EntityManager } from '@mikro-orm/mongodb'; import { Test, TestingModule } from '@nestjs/testing'; -import { SchoolEntity, System, UserLoginMigrationDO } from '@shared/domain'; +import { SchoolEntity, SystemEntity, UserLoginMigrationDO } from '@shared/domain'; import { UserLoginMigration } from '@shared/domain/entity/user-login-migration.entity'; import { MongoMemoryDatabaseModule } from '@shared/infra/database'; import { cleanupCollections, schoolFactory, systemFactory } from '@shared/testing'; @@ -42,8 +42,8 @@ describe('UserLoginMigrationRepo', () => { describe('when saving a UserLoginMigrationDO', () => { const setup = async () => { const school: SchoolEntity = schoolFactory.buildWithId(); - const sourceSystem: System = systemFactory.buildWithId(); - const targetSystem: System = systemFactory.buildWithId(); + const sourceSystem: SystemEntity = systemFactory.buildWithId(); + const targetSystem: SystemEntity = systemFactory.buildWithId(); const domainObject: UserLoginMigrationDO = new UserLoginMigrationDO({ schoolId: school.id, diff --git a/apps/server/src/shared/repo/userloginmigration/user-login-migration.repo.ts b/apps/server/src/shared/repo/userloginmigration/user-login-migration.repo.ts index f404a7b7209..346b3c3dced 100644 --- a/apps/server/src/shared/repo/userloginmigration/user-login-migration.repo.ts +++ b/apps/server/src/shared/repo/userloginmigration/user-login-migration.repo.ts @@ -1,7 +1,7 @@ import { EntityName } from '@mikro-orm/core'; import { EntityManager } from '@mikro-orm/mongodb'; import { Injectable } from '@nestjs/common'; -import { EntityId, SchoolEntity, System, UserLoginMigrationDO } from '@shared/domain'; +import { EntityId, SchoolEntity, SystemEntity, UserLoginMigrationDO } from '@shared/domain'; import { IUserLoginMigration, UserLoginMigration } from '@shared/domain/entity/user-login-migration.entity'; import { LegacyLogger } from '@src/core/logger'; import { BaseDORepo } from '../base.do.repo'; @@ -51,8 +51,8 @@ export class UserLoginMigrationRepo extends BaseDORepo { +export class SystemFactory extends BaseFactory { withOauthConfig(): this { const params: DeepPartial = { oauthConfig: new OauthConfig({ @@ -54,7 +54,7 @@ export class SystemFactory extends BaseFactory { } } -export const systemFactory = SystemFactory.define(System, ({ sequence }) => { +export const systemFactory = SystemFactory.define(SystemEntity, ({ sequence }) => { return { type: 'oauth', url: 'http://mock.de', From b3b536e57e9302bb68a3dc9ac786fa4068f12f7c Mon Sep 17 00:00:00 2001 From: dyedwiper Date: Thu, 21 Sep 2023 16:39:20 +0200 Subject: [PATCH 2/5] Rename school year entity --- .../fwu-learning-contents-test.module.ts | 4 ++-- .../fwu-learning-contents.module.ts | 4 ++-- .../src/modules/h5p-editor/h5p-editor-test.module.ts | 4 ++-- .../src/modules/h5p-editor/h5p-editor.module.ts | 4 ++-- .../repo/schoolyear.repo.integration.spec.ts | 10 +++++----- .../src/modules/legacy-school/repo/schoolyear.repo.ts | 10 +++++----- .../legacy-school/service/school-year.service.spec.ts | 6 +++--- .../legacy-school/service/school-year.service.ts | 6 +++--- .../src/modules/management/seed-data/schools.ts | 11 +++++++++-- .../oidc/service/oidc-provisioning.service.ts | 4 ++-- .../shared/domain/domainobject/legacy-school.do.ts | 4 ++-- apps/server/src/shared/domain/entity/all-entities.ts | 4 ++-- apps/server/src/shared/domain/entity/school.entity.ts | 6 +++--- .../shared/domain/entity/schoolyear.entity.spec.ts | 4 ++-- .../src/shared/domain/entity/schoolyear.entity.ts | 2 +- .../school/legacy-school.repo.integration.spec.ts | 8 ++++---- .../src/shared/testing/factory/schoolyear.factory.ts | 4 ++-- 17 files changed, 51 insertions(+), 44 deletions(-) diff --git a/apps/server/src/modules/fwu-learning-contents/fwu-learning-contents-test.module.ts b/apps/server/src/modules/fwu-learning-contents/fwu-learning-contents-test.module.ts index 01993735a4f..5b6efa3bbb1 100644 --- a/apps/server/src/modules/fwu-learning-contents/fwu-learning-contents-test.module.ts +++ b/apps/server/src/modules/fwu-learning-contents/fwu-learning-contents-test.module.ts @@ -1,7 +1,7 @@ import { HttpModule } from '@nestjs/axios'; import { DynamicModule, Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; -import { Account, Role, SchoolEntity, SchoolYear, SystemEntity, User } from '@shared/domain'; +import { Account, Role, SchoolEntity, SchoolYearEntity, SystemEntity, User } from '@shared/domain'; import { MongoMemoryDatabaseModule } from '@shared/infra/database'; import { MongoDatabaseModuleOptions } from '@shared/infra/database/mongo-memory-database/types'; import { RabbitMQWrapperTestModule } from '@shared/infra/rabbitmq'; @@ -16,7 +16,7 @@ import { config, s3Config } from './fwu-learning-contents.config'; import { FwuLearningContentsUc } from './uc/fwu-learning-contents.uc'; const imports = [ - MongoMemoryDatabaseModule.forRoot({ entities: [User, Account, Role, SchoolEntity, SystemEntity, SchoolYear] }), + MongoMemoryDatabaseModule.forRoot({ entities: [User, Account, Role, SchoolEntity, SystemEntity, SchoolYearEntity] }), AuthorizationModule, AuthenticationModule, ConfigModule.forRoot(createConfigModuleOptions(config)), diff --git a/apps/server/src/modules/fwu-learning-contents/fwu-learning-contents.module.ts b/apps/server/src/modules/fwu-learning-contents/fwu-learning-contents.module.ts index 112f0f15d5b..2f4cd148d1b 100644 --- a/apps/server/src/modules/fwu-learning-contents/fwu-learning-contents.module.ts +++ b/apps/server/src/modules/fwu-learning-contents/fwu-learning-contents.module.ts @@ -3,7 +3,7 @@ import { MikroOrmModule, MikroOrmModuleSyncOptions } from '@mikro-orm/nestjs'; import { HttpModule } from '@nestjs/axios'; import { Module, NotFoundException } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; -import { Account, Role, SchoolEntity, SchoolYear, SystemEntity, User } from '@shared/domain'; +import { Account, Role, SchoolEntity, SchoolYearEntity, SystemEntity, User } from '@shared/domain'; import { RabbitMQWrapperModule } from '@shared/infra/rabbitmq'; import { S3ClientModule } from '@shared/infra/s3-client'; import { DB_PASSWORD, DB_URL, DB_USERNAME, createConfigModuleOptions } from '@src/config'; @@ -36,7 +36,7 @@ const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = { clientUrl: DB_URL, password: DB_PASSWORD, user: DB_USERNAME, - entities: [User, Account, Role, SchoolEntity, SystemEntity, SchoolYear], + entities: [User, Account, Role, SchoolEntity, SystemEntity, SchoolYearEntity], // debug: true, // use it for locally debugging of querys }), diff --git a/apps/server/src/modules/h5p-editor/h5p-editor-test.module.ts b/apps/server/src/modules/h5p-editor/h5p-editor-test.module.ts index e33f5484b8a..dfe1b1ec846 100644 --- a/apps/server/src/modules/h5p-editor/h5p-editor-test.module.ts +++ b/apps/server/src/modules/h5p-editor/h5p-editor-test.module.ts @@ -1,5 +1,5 @@ import { DynamicModule, Module } from '@nestjs/common'; -import { Account, Role, SchoolEntity, SchoolYear, User } from '@shared/domain'; +import { Account, Role, SchoolEntity, SchoolYearEntity, User } from '@shared/domain'; import { MongoMemoryDatabaseModule } from '@shared/infra/database'; import { MongoDatabaseModuleOptions } from '@shared/infra/database/mongo-memory-database/types'; import { RabbitMQWrapperTestModule } from '@shared/infra/rabbitmq'; @@ -12,7 +12,7 @@ import { H5PEditorModule } from './h5p-editor.module'; const imports = [ H5PEditorModule, - MongoMemoryDatabaseModule.forRoot({ entities: [Account, Role, SchoolEntity, SchoolYear, User] }), + MongoMemoryDatabaseModule.forRoot({ entities: [Account, Role, SchoolEntity, SchoolYearEntity, User] }), AuthenticationApiModule, AuthorizationModule, AuthenticationModule, diff --git a/apps/server/src/modules/h5p-editor/h5p-editor.module.ts b/apps/server/src/modules/h5p-editor/h5p-editor.module.ts index 96d19f5cb24..869f76d3a86 100644 --- a/apps/server/src/modules/h5p-editor/h5p-editor.module.ts +++ b/apps/server/src/modules/h5p-editor/h5p-editor.module.ts @@ -2,7 +2,7 @@ import { Dictionary, IPrimaryKey } from '@mikro-orm/core'; import { MikroOrmModule, MikroOrmModuleSyncOptions } from '@mikro-orm/nestjs'; import { Module, NotFoundException } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; -import { Account, Role, SchoolEntity, SchoolYear, SystemEntity, User } from '@shared/domain'; +import { Account, Role, SchoolEntity, SchoolYearEntity, SystemEntity, User } from '@shared/domain'; import { DB_PASSWORD, DB_URL, DB_USERNAME, createConfigModuleOptions } from '@src/config'; import { CoreModule } from '@src/core'; import { Logger } from '@src/core/logger'; @@ -28,7 +28,7 @@ const imports = [ clientUrl: DB_URL, password: DB_PASSWORD, user: DB_USERNAME, - entities: [User, Account, Role, SchoolEntity, SystemEntity, SchoolYear], + entities: [User, Account, Role, SchoolEntity, SystemEntity, SchoolYearEntity], // debug: true, // use it for locally debugging of querys }), diff --git a/apps/server/src/modules/legacy-school/repo/schoolyear.repo.integration.spec.ts b/apps/server/src/modules/legacy-school/repo/schoolyear.repo.integration.spec.ts index 1c37470f4b7..5439fdef9f6 100644 --- a/apps/server/src/modules/legacy-school/repo/schoolyear.repo.integration.spec.ts +++ b/apps/server/src/modules/legacy-school/repo/schoolyear.repo.integration.spec.ts @@ -1,6 +1,6 @@ import { EntityManager } from '@mikro-orm/mongodb'; import { Test, TestingModule } from '@nestjs/testing'; -import { SchoolYear } from '@shared/domain'; +import { SchoolYearEntity } from '@shared/domain'; import { MongoMemoryDatabaseModule } from '@shared/infra/database'; import { cleanupCollections } from '@shared/testing'; import { schoolYearFactory } from '@shared/testing/factory/schoolyear.factory'; @@ -29,14 +29,14 @@ describe('schoolyear repo', () => { }); it('should implement entityName getter', () => { - expect(repo.entityName).toBe(SchoolYear); + expect(repo.entityName).toBe(SchoolYearEntity); }); it('should create a schoolyear', async () => { const schoolYear = schoolYearFactory.build(); await repo.save(schoolYear); em.clear(); - const storedSchoolYears = await em.find(SchoolYear, {}); + const storedSchoolYears = await em.find(SchoolYearEntity, {}); expect(storedSchoolYears).toHaveLength(1); const storedSchoolYear = storedSchoolYears[0]; expect(storedSchoolYear).toEqual(schoolYear); @@ -48,7 +48,7 @@ describe('schoolyear repo', () => { describe('findCurrentYear', () => { describe('when date is between schoolyears start and end date', () => { const setup = async () => { - const schoolYear: SchoolYear = schoolYearFactory.build({ + const schoolYear: SchoolYearEntity = schoolYearFactory.build({ startDate: new Date('2020-08-01'), endDate: new Date('9999-07-31'), }); @@ -70,7 +70,7 @@ describe('schoolyear repo', () => { describe('when date is not between schoolyears start and end date', () => { const setup = async () => { - const schoolYear: SchoolYear = schoolYearFactory.build({ + const schoolYear: SchoolYearEntity = schoolYearFactory.build({ startDate: new Date('2020-08-01'), endDate: new Date('2021-07-31'), }); diff --git a/apps/server/src/modules/legacy-school/repo/schoolyear.repo.ts b/apps/server/src/modules/legacy-school/repo/schoolyear.repo.ts index 57417afb69c..b4e79cdc283 100644 --- a/apps/server/src/modules/legacy-school/repo/schoolyear.repo.ts +++ b/apps/server/src/modules/legacy-school/repo/schoolyear.repo.ts @@ -1,16 +1,16 @@ import { Injectable } from '@nestjs/common'; -import { SchoolYear } from '@shared/domain'; +import { SchoolYearEntity } from '@shared/domain'; import { BaseRepo } from '@shared/repo/base.repo'; @Injectable() -export class SchoolYearRepo extends BaseRepo { +export class SchoolYearRepo extends BaseRepo { get entityName() { - return SchoolYear; + return SchoolYearEntity; } - async findCurrentYear(): Promise { + async findCurrentYear(): Promise { const currentDate = new Date(); - const year: SchoolYear | null = await this._em.findOneOrFail(SchoolYear, { + const year: SchoolYearEntity | null = await this._em.findOneOrFail(SchoolYearEntity, { $and: [{ startDate: { $lte: currentDate } }, { endDate: { $gte: currentDate } }], }); return year; diff --git a/apps/server/src/modules/legacy-school/service/school-year.service.spec.ts b/apps/server/src/modules/legacy-school/service/school-year.service.spec.ts index 9542e639a62..00e47a6360f 100644 --- a/apps/server/src/modules/legacy-school/service/school-year.service.spec.ts +++ b/apps/server/src/modules/legacy-school/service/school-year.service.spec.ts @@ -2,7 +2,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { setupEntities } from '@shared/testing'; import { schoolYearFactory } from '@shared/testing/factory/schoolyear.factory'; -import { SchoolYear } from '@shared/domain'; +import { SchoolYearEntity } from '@shared/domain'; import { SchoolYearService } from './school-year.service'; import { SchoolYearRepo } from '../repo'; @@ -36,7 +36,7 @@ describe('SchoolYearService', () => { describe('getCurrentSchoolYear', () => { const setup = () => { jest.setSystemTime(new Date('2022-06-01').getTime()); - const schoolYear: SchoolYear = schoolYearFactory.build({ + const schoolYear: SchoolYearEntity = schoolYearFactory.build({ startDate: new Date('2021-09-01'), endDate: new Date('2022-12-31'), }); @@ -51,7 +51,7 @@ describe('SchoolYearService', () => { it('should return the current school year', async () => { const { schoolYear } = setup(); - const currentSchoolYear: SchoolYear = await service.getCurrentSchoolYear(); + const currentSchoolYear: SchoolYearEntity = await service.getCurrentSchoolYear(); expect(currentSchoolYear).toEqual(schoolYear); }); diff --git a/apps/server/src/modules/legacy-school/service/school-year.service.ts b/apps/server/src/modules/legacy-school/service/school-year.service.ts index 61941c8f22e..16cae1c1cff 100644 --- a/apps/server/src/modules/legacy-school/service/school-year.service.ts +++ b/apps/server/src/modules/legacy-school/service/school-year.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@nestjs/common'; -import { SchoolYear } from '@shared/domain'; +import { SchoolYearEntity } from '@shared/domain'; import { SchoolYearRepo } from '../repo'; @Injectable() @@ -7,8 +7,8 @@ export class SchoolYearService { constructor(private readonly schoolYearRepo: SchoolYearRepo) {} // TODO: N21-990 Refactoring: Create domain objects for schoolYear and federalState - async getCurrentSchoolYear(): Promise { - const current: SchoolYear = await this.schoolYearRepo.findCurrentYear(); + async getCurrentSchoolYear(): Promise { + const current: SchoolYearEntity = await this.schoolYearRepo.findCurrentYear(); return current; } diff --git a/apps/server/src/modules/management/seed-data/schools.ts b/apps/server/src/modules/management/seed-data/schools.ts index 67bd86567dd..83f6311a2f2 100644 --- a/apps/server/src/modules/management/seed-data/schools.ts +++ b/apps/server/src/modules/management/seed-data/schools.ts @@ -1,5 +1,12 @@ /* eslint-disable @typescript-eslint/dot-notation */ -import { FederalState, ISchoolProperties, SchoolFeatures, SchoolRoles, SchoolYear, SystemEntity } from '@shared/domain'; +import { + FederalState, + ISchoolProperties, + SchoolFeatures, + SchoolRoles, + SchoolYearEntity, + SystemEntity, +} from '@shared/domain'; import { federalStateFactory, schoolFactory } from '@shared/testing'; import { DeepPartial } from 'fishery'; import { EFederalState } from './federalstates'; @@ -265,7 +272,7 @@ const seedSchools: SeedSchoolProperties[] = [ export function generateSchools(entities: { systems: SystemEntity[]; - schoolYears: SchoolYear[]; + schoolYears: SchoolYearEntity[]; federalStates: FederalState[]; }) { return seedSchools.map((partial) => { diff --git a/apps/server/src/modules/provisioning/strategy/oidc/service/oidc-provisioning.service.ts b/apps/server/src/modules/provisioning/strategy/oidc/service/oidc-provisioning.service.ts index d32fa5a9b06..fe2702a63a3 100644 --- a/apps/server/src/modules/provisioning/strategy/oidc/service/oidc-provisioning.service.ts +++ b/apps/server/src/modules/provisioning/strategy/oidc/service/oidc-provisioning.service.ts @@ -1,5 +1,5 @@ import { Injectable, UnprocessableEntityException } from '@nestjs/common'; -import { EntityId, ExternalSource, FederalState, SchoolFeatures, SchoolYear } from '@shared/domain'; +import { EntityId, ExternalSource, FederalState, SchoolFeatures, SchoolYearEntity } from '@shared/domain'; import { LegacySchoolDo, RoleReference, UserDO } from '@shared/domain/domainobject'; import { Logger } from '@src/core/logger'; import { AccountService } from '@src/modules/account/services/account.service'; @@ -44,7 +44,7 @@ export class OidcProvisioningService { school.systems.push(systemId); } } else { - const schoolYear: SchoolYear = await this.schoolYearService.getCurrentSchoolYear(); + const schoolYear: SchoolYearEntity = await this.schoolYearService.getCurrentSchoolYear(); const federalState: FederalState = await this.federalStateService.findFederalStateByName( FederalStateNames.NIEDERSACHEN ); diff --git a/apps/server/src/shared/domain/domainobject/legacy-school.do.ts b/apps/server/src/shared/domain/domainobject/legacy-school.do.ts index 5ac496a04c4..c7f40e899f4 100644 --- a/apps/server/src/shared/domain/domainobject/legacy-school.do.ts +++ b/apps/server/src/shared/domain/domainobject/legacy-school.do.ts @@ -1,4 +1,4 @@ -import { FederalState, SchoolFeatures, SchoolYear } from '@shared/domain/entity'; +import { FederalState, SchoolFeatures, SchoolYearEntity } from '@shared/domain/entity'; import { EntityId } from '@shared/domain/types'; import { BaseDO } from './base.do'; @@ -23,7 +23,7 @@ export class LegacySchoolDo extends BaseDO { features?: SchoolFeatures[]; // TODO: N21-990 Refactoring: Create domain objects for schoolYear and federalState - schoolYear?: SchoolYear; + schoolYear?: SchoolYearEntity; userLoginMigrationId?: EntityId; diff --git a/apps/server/src/shared/domain/entity/all-entities.ts b/apps/server/src/shared/domain/entity/all-entities.ts index 4fce6735548..7b11b48a9e8 100644 --- a/apps/server/src/shared/domain/entity/all-entities.ts +++ b/apps/server/src/shared/domain/entity/all-entities.ts @@ -35,7 +35,7 @@ import { Material } from './materials.entity'; import { CourseNews, News, SchoolNews, TeamNews } from './news.entity'; import { Role } from './role.entity'; import { SchoolEntity, SchoolRolePermission, SchoolRoles } from './school.entity'; -import { SchoolYear } from './schoolyear.entity'; +import { SchoolYearEntity } from './schoolyear.entity'; import { StorageProviderEntity } from './storageprovider.entity'; import { Submission } from './submission.entity'; import { SystemEntity } from './system.entity'; @@ -82,7 +82,7 @@ export const ALL_ENTITIES = [ SchoolNews, SchoolRolePermission, SchoolRoles, - SchoolYear, + SchoolYearEntity, ShareToken, StorageProviderEntity, Submission, diff --git a/apps/server/src/shared/domain/entity/school.entity.ts b/apps/server/src/shared/domain/entity/school.entity.ts index 7069279526c..0de5bc8e62e 100644 --- a/apps/server/src/shared/domain/entity/school.entity.ts +++ b/apps/server/src/shared/domain/entity/school.entity.ts @@ -11,7 +11,7 @@ import { } from '@mikro-orm/core'; import { UserLoginMigration } from '@shared/domain/entity/user-login-migration.entity'; import { BaseEntity } from './base.entity'; -import { SchoolYear } from './schoolyear.entity'; +import { SchoolYearEntity } from './schoolyear.entity'; import { SystemEntity } from './system.entity'; import { FederalState } from './federal-state.entity'; @@ -36,7 +36,7 @@ export interface ISchoolProperties { officialSchoolNumber?: string; systems?: SystemEntity[]; features?: SchoolFeatures[]; - schoolYear?: SchoolYear; + schoolYear?: SchoolYearEntity; userLoginMigration?: UserLoginMigration; federalState: FederalState; } @@ -90,7 +90,7 @@ export class SchoolEntity extends BaseEntity { permissions?: SchoolRoles; @ManyToOne('SchoolYear', { fieldName: 'currentYear', nullable: true }) - schoolYear?: SchoolYear; + schoolYear?: SchoolYearEntity; @OneToOne(() => UserLoginMigration, (userLoginMigration: UserLoginMigration) => userLoginMigration.school, { orphanRemoval: true, diff --git a/apps/server/src/shared/domain/entity/schoolyear.entity.spec.ts b/apps/server/src/shared/domain/entity/schoolyear.entity.spec.ts index 11dc31c8105..f4677727a2d 100644 --- a/apps/server/src/shared/domain/entity/schoolyear.entity.spec.ts +++ b/apps/server/src/shared/domain/entity/schoolyear.entity.spec.ts @@ -1,6 +1,6 @@ import { setupEntities } from '@shared/testing'; import { schoolYearFactory } from '@shared/testing/factory/schoolyear.factory'; -import { SchoolYear } from './schoolyear.entity'; +import { SchoolYearEntity } from './schoolyear.entity'; describe('schoolyear entity', () => { beforeAll(async () => { @@ -13,7 +13,7 @@ describe('schoolyear entity', () => { const schoolYear = schoolYearFactory.build(); expect(/^\d{4}\/\d{2}$/.test(schoolYear.name)).toBeTruthy(); - expect(schoolYear).toBeInstanceOf(SchoolYear); + expect(schoolYear).toBeInstanceOf(SchoolYearEntity); }); }); }); diff --git a/apps/server/src/shared/domain/entity/schoolyear.entity.ts b/apps/server/src/shared/domain/entity/schoolyear.entity.ts index bc5b3edb970..e1d2c1c9895 100644 --- a/apps/server/src/shared/domain/entity/schoolyear.entity.ts +++ b/apps/server/src/shared/domain/entity/schoolyear.entity.ts @@ -8,7 +8,7 @@ export interface ISchoolYearProperties { } @Entity({ tableName: 'years' }) -export class SchoolYear extends BaseEntity implements ISchoolYearProperties { +export class SchoolYearEntity extends BaseEntity implements ISchoolYearProperties { @Property() name: string; diff --git a/apps/server/src/shared/repo/school/legacy-school.repo.integration.spec.ts b/apps/server/src/shared/repo/school/legacy-school.repo.integration.spec.ts index 74254379507..fed53682552 100644 --- a/apps/server/src/shared/repo/school/legacy-school.repo.integration.spec.ts +++ b/apps/server/src/shared/repo/school/legacy-school.repo.integration.spec.ts @@ -9,7 +9,7 @@ import { SchoolEntity, SchoolRolePermission, SchoolRoles, - SchoolYear, + SchoolYearEntity, SystemEntity, UserLoginMigration, } from '@shared/domain'; @@ -46,7 +46,7 @@ describe('LegacySchoolRepo', () => { beforeEach(async () => { await em.nativeDelete(SchoolEntity, {}); - await em.nativeDelete(SchoolYear, {}); + await em.nativeDelete(SchoolYearEntity, {}); em.clear(); jest.resetAllMocks(); }); @@ -95,7 +95,7 @@ describe('LegacySchoolRepo', () => { await em.persistAndFlush([school]); - const storedSchoolYears = await em.find(SchoolYear, {}); + const storedSchoolYears = await em.find(SchoolYearEntity, {}); expect(storedSchoolYears).toHaveLength(1); expect(storedSchoolYears[0]).toEqual(schoolYear); @@ -183,7 +183,7 @@ describe('LegacySchoolRepo', () => { describe('mapEntityToDO is called', () => { it('should map school entity to school domain object', () => { const system: SystemEntity = systemFactory.buildWithId(); - const schoolYear: SchoolYear = schoolYearFactory.buildWithId(); + const schoolYear: SchoolYearEntity = schoolYearFactory.buildWithId(); const schoolEntity: SchoolEntity = schoolFactory.buildWithId({ systems: [system], features: [], schoolYear }); const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.build({ school: schoolEntity }); schoolEntity.userLoginMigration = userLoginMigration; diff --git a/apps/server/src/shared/testing/factory/schoolyear.factory.ts b/apps/server/src/shared/testing/factory/schoolyear.factory.ts index 8fcc256f588..a1184ed66d3 100644 --- a/apps/server/src/shared/testing/factory/schoolyear.factory.ts +++ b/apps/server/src/shared/testing/factory/schoolyear.factory.ts @@ -1,7 +1,7 @@ -import { ISchoolYearProperties, SchoolYear } from '@shared/domain/entity/schoolyear.entity'; +import { ISchoolYearProperties, SchoolYearEntity } from '@shared/domain/entity/schoolyear.entity'; import { BaseFactory } from './base.factory'; -export const schoolYearFactory = BaseFactory.define(SchoolYear, () => { +export const schoolYearFactory = BaseFactory.define(SchoolYearEntity, () => { const year = new Date().getFullYear(); const nextYear = (year + 1).toString().substr(-2); const name = `${year}/${nextYear}`; From e261653906d83bb942097db1e44de673df94e641 Mon Sep 17 00:00:00 2001 From: dyedwiper Date: Thu, 21 Sep 2023 16:40:03 +0200 Subject: [PATCH 3/5] Rename UserLoginMigration entity --- .../controller/api-test/oauth-sso.api.spec.ts | 10 +++--- .../api-test/user-login-migration.api.spec.ts | 36 +++++++++---------- .../src/shared/domain/entity/all-entities.ts | 4 +-- .../src/shared/domain/entity/school.entity.ts | 20 ++++++----- .../entity/user-login-migration.entity.ts | 4 +-- .../legacy-school.repo.integration.spec.ts | 8 ++--- .../shared/repo/school/legacy-school.repo.ts | 4 +-- ...r-login-migration.repo.integration.spec.ts | 6 ++-- .../user-login-migration.repo.ts | 20 ++++++----- .../factory/user-login-migration.factory.ts | 6 ++-- 10 files changed, 63 insertions(+), 55 deletions(-) diff --git a/apps/server/src/modules/oauth/controller/api-test/oauth-sso.api.spec.ts b/apps/server/src/modules/oauth/controller/api-test/oauth-sso.api.spec.ts index 4cec17e545b..7ddecbbaa54 100644 --- a/apps/server/src/modules/oauth/controller/api-test/oauth-sso.api.spec.ts +++ b/apps/server/src/modules/oauth/controller/api-test/oauth-sso.api.spec.ts @@ -3,7 +3,7 @@ import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { Account, EntityId, SchoolEntity, SystemEntity, User } from '@shared/domain'; -import { UserLoginMigration } from '@shared/domain/entity/user-login-migration.entity'; +import { UserLoginMigrationEntity } from '@shared/domain/entity/user-login-migration.entity'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; import { KeycloakAdministrationService } from '@shared/infra/identity-management/keycloak-administration/service/keycloak-administration.service'; import { @@ -330,7 +330,7 @@ describe('OAuth SSO Controller (API)', () => { officialSchoolNumber: '11111', externalId: 'aef1f4fd-c323-466e-962b-a84354c0e713', }); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId({ + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId({ school: sourceSchool, targetSystem, sourceSystem, @@ -410,7 +410,7 @@ describe('OAuth SSO Controller (API)', () => { externalId: 'aef1f4fd-c323-466e-962b-a84354c0e713', }); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId({ + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId({ school: sourceSchool, targetSystem, sourceSystem, @@ -458,7 +458,7 @@ describe('OAuth SSO Controller (API)', () => { externalId: 'aef1f4fd-c323-466e-962b-a84354c0e713', }); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId({ + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId({ school: sourceSchool, targetSystem, sourceSystem, @@ -514,7 +514,7 @@ describe('OAuth SSO Controller (API)', () => { externalId: 'aef1f4fd-c323-466e-962b-a84354c0e713', }); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId({ + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId({ school: sourceSchool, targetSystem, sourceSystem, diff --git a/apps/server/src/modules/user-login-migration/controller/api-test/user-login-migration.api.spec.ts b/apps/server/src/modules/user-login-migration/controller/api-test/user-login-migration.api.spec.ts index cc6fc43dcbf..95cb8fdde5e 100644 --- a/apps/server/src/modules/user-login-migration/controller/api-test/user-login-migration.api.spec.ts +++ b/apps/server/src/modules/user-login-migration/controller/api-test/user-login-migration.api.spec.ts @@ -3,7 +3,7 @@ import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; import { HttpStatus, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { Permission, SchoolEntity, SystemEntity, User } from '@shared/domain'; -import { UserLoginMigration } from '@shared/domain/entity/user-login-migration.entity'; +import { UserLoginMigrationEntity } from '@shared/domain/entity/user-login-migration.entity'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; import { cleanupCollections, @@ -74,7 +74,7 @@ describe('UserLoginMigrationController (API)', () => { const school: SchoolEntity = schoolFactory.buildWithId({ systems: [sourceSystem], }); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId({ + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId({ school, targetSystem, sourceSystem, @@ -138,7 +138,7 @@ describe('UserLoginMigrationController (API)', () => { const school: SchoolEntity = schoolFactory.buildWithId({ systems: [sourceSystem], }); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId({ + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId({ school, targetSystem, sourceSystem, @@ -288,7 +288,7 @@ describe('UserLoginMigrationController (API)', () => { officialSchoolNumber: '12345', }); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId({ + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId({ school, targetSystem, sourceSystem, @@ -329,7 +329,7 @@ describe('UserLoginMigrationController (API)', () => { officialSchoolNumber: '12345', }); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId({ + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId({ school, targetSystem, sourceSystem, @@ -459,7 +459,7 @@ describe('UserLoginMigrationController (API)', () => { externalId, }); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId({ + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId({ school, targetSystem, sourceSystem, @@ -526,7 +526,7 @@ describe('UserLoginMigrationController (API)', () => { externalId, }); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId({ + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId({ school, targetSystem, sourceSystem, @@ -600,7 +600,7 @@ describe('UserLoginMigrationController (API)', () => { officialSchoolNumber: '12345', }); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId({ + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId({ school, targetSystem, sourceSystem, @@ -684,7 +684,7 @@ describe('UserLoginMigrationController (API)', () => { officialSchoolNumber: '12345', }); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId({ + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId({ school, targetSystem, sourceSystem, @@ -724,7 +724,7 @@ describe('UserLoginMigrationController (API)', () => { officialSchoolNumber: '12345', }); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId({ + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId({ school, targetSystem, sourceSystem, @@ -769,7 +769,7 @@ describe('UserLoginMigrationController (API)', () => { officialSchoolNumber: '12345', }); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId({ + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId({ school, targetSystem, sourceSystem, @@ -812,7 +812,7 @@ describe('UserLoginMigrationController (API)', () => { officialSchoolNumber: '12345', }); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId({ + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId({ school, targetSystem, sourceSystem, @@ -888,7 +888,7 @@ describe('UserLoginMigrationController (API)', () => { officialSchoolNumber: '12345', }); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId({ + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId({ school, targetSystem, sourceSystem, @@ -938,7 +938,7 @@ describe('UserLoginMigrationController (API)', () => { officialSchoolNumber: '12345', }); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId({ + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId({ school, targetSystem, sourceSystem, @@ -979,7 +979,7 @@ describe('UserLoginMigrationController (API)', () => { systems: [sourceSystem], officialSchoolNumber: '12345', }); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId({ + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId({ school, targetSystem, sourceSystem, @@ -1077,7 +1077,7 @@ describe('UserLoginMigrationController (API)', () => { officialSchoolNumber: '12345', }); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId({ + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId({ school, targetSystem, sourceSystem, @@ -1123,7 +1123,7 @@ describe('UserLoginMigrationController (API)', () => { officialSchoolNumber: '12345', }); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId({ + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId({ school, targetSystem, sourceSystem, @@ -1173,7 +1173,7 @@ describe('UserLoginMigrationController (API)', () => { officialSchoolNumber: '12345', }); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId({ + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId({ school, targetSystem, sourceSystem, diff --git a/apps/server/src/shared/domain/entity/all-entities.ts b/apps/server/src/shared/domain/entity/all-entities.ts index 7b11b48a9e8..0f6ee049c4f 100644 --- a/apps/server/src/shared/domain/entity/all-entities.ts +++ b/apps/server/src/shared/domain/entity/all-entities.ts @@ -41,7 +41,7 @@ import { Submission } from './submission.entity'; import { SystemEntity } from './system.entity'; import { Task } from './task.entity'; import { TeamEntity, TeamUserEntity } from './team.entity'; -import { UserLoginMigration } from './user-login-migration.entity'; +import { UserLoginMigrationEntity } from './user-login-migration.entity'; import { User } from './user.entity'; import { VideoConference } from './video-conference.entity'; @@ -93,7 +93,7 @@ export const ALL_ENTITIES = [ TeamNews, TeamUserEntity, User, - UserLoginMigration, + UserLoginMigrationEntity, VideoConference, GroupEntity, ]; diff --git a/apps/server/src/shared/domain/entity/school.entity.ts b/apps/server/src/shared/domain/entity/school.entity.ts index 0de5bc8e62e..b16dfb0b601 100644 --- a/apps/server/src/shared/domain/entity/school.entity.ts +++ b/apps/server/src/shared/domain/entity/school.entity.ts @@ -9,7 +9,7 @@ import { OneToOne, Property, } from '@mikro-orm/core'; -import { UserLoginMigration } from '@shared/domain/entity/user-login-migration.entity'; +import { UserLoginMigrationEntity } from '@shared/domain/entity/user-login-migration.entity'; import { BaseEntity } from './base.entity'; import { SchoolYearEntity } from './schoolyear.entity'; import { SystemEntity } from './system.entity'; @@ -37,7 +37,7 @@ export interface ISchoolProperties { systems?: SystemEntity[]; features?: SchoolFeatures[]; schoolYear?: SchoolYearEntity; - userLoginMigration?: UserLoginMigration; + userLoginMigration?: UserLoginMigrationEntity; federalState: FederalState; } @@ -92,12 +92,16 @@ export class SchoolEntity extends BaseEntity { @ManyToOne('SchoolYear', { fieldName: 'currentYear', nullable: true }) schoolYear?: SchoolYearEntity; - @OneToOne(() => UserLoginMigration, (userLoginMigration: UserLoginMigration) => userLoginMigration.school, { - orphanRemoval: true, - nullable: true, - fieldName: 'userLoginMigrationId', - }) - userLoginMigration?: UserLoginMigration; + @OneToOne( + () => UserLoginMigrationEntity, + (userLoginMigration: UserLoginMigrationEntity) => userLoginMigration.school, + { + orphanRemoval: true, + nullable: true, + fieldName: 'userLoginMigrationId', + } + ) + userLoginMigration?: UserLoginMigrationEntity; @ManyToOne(() => FederalState, { fieldName: 'federalState', nullable: false }) federalState: FederalState; diff --git a/apps/server/src/shared/domain/entity/user-login-migration.entity.ts b/apps/server/src/shared/domain/entity/user-login-migration.entity.ts index 3093f85bc44..2daf9707f3c 100644 --- a/apps/server/src/shared/domain/entity/user-login-migration.entity.ts +++ b/apps/server/src/shared/domain/entity/user-login-migration.entity.ts @@ -3,10 +3,10 @@ import { SchoolEntity } from '@shared/domain/entity/school.entity'; import { SystemEntity } from '@shared/domain/entity/system.entity'; import { BaseEntityWithTimestamps } from './base.entity'; -export type IUserLoginMigration = Readonly>; +export type IUserLoginMigration = Readonly>; @Entity({ tableName: 'user_login_migrations' }) -export class UserLoginMigration extends BaseEntityWithTimestamps { +export class UserLoginMigrationEntity extends BaseEntityWithTimestamps { @OneToOne(() => SchoolEntity, undefined, { nullable: false }) school: SchoolEntity; diff --git a/apps/server/src/shared/repo/school/legacy-school.repo.integration.spec.ts b/apps/server/src/shared/repo/school/legacy-school.repo.integration.spec.ts index fed53682552..e9f14ba3315 100644 --- a/apps/server/src/shared/repo/school/legacy-school.repo.integration.spec.ts +++ b/apps/server/src/shared/repo/school/legacy-school.repo.integration.spec.ts @@ -11,7 +11,7 @@ import { SchoolRoles, SchoolYearEntity, SystemEntity, - UserLoginMigration, + UserLoginMigrationEntity, } from '@shared/domain'; import { MongoMemoryDatabaseModule } from '@shared/infra/database'; import { @@ -185,7 +185,7 @@ describe('LegacySchoolRepo', () => { const system: SystemEntity = systemFactory.buildWithId(); const schoolYear: SchoolYearEntity = schoolYearFactory.buildWithId(); const schoolEntity: SchoolEntity = schoolFactory.buildWithId({ systems: [system], features: [], schoolYear }); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.build({ school: schoolEntity }); + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.build({ school: schoolEntity }); schoolEntity.userLoginMigration = userLoginMigration; const schoolDO: LegacySchoolDo = repo.mapEntityToDO(schoolEntity); @@ -222,7 +222,7 @@ describe('LegacySchoolRepo', () => { const system1: SystemEntity = systemFactory.buildWithId(); const system2: SystemEntity = systemFactory.buildWithId(); - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId(); + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId(); await em.persistAndFlush([userLoginMigration, system1, system2]); @@ -260,7 +260,7 @@ describe('LegacySchoolRepo', () => { expect(emGetReferenceSpy).toHaveBeenCalledTimes(3); expect(emGetReferenceSpy).toHaveBeenNthCalledWith(1, SystemEntity, system1.id); expect(emGetReferenceSpy).toHaveBeenNthCalledWith(2, SystemEntity, system2.id); - expect(emGetReferenceSpy).toHaveBeenNthCalledWith(3, UserLoginMigration, userLoginMigration.id); + expect(emGetReferenceSpy).toHaveBeenNthCalledWith(3, UserLoginMigrationEntity, userLoginMigration.id); }); describe('when there are no systems', () => { diff --git a/apps/server/src/shared/repo/school/legacy-school.repo.ts b/apps/server/src/shared/repo/school/legacy-school.repo.ts index 335b5286214..711eaea27d9 100644 --- a/apps/server/src/shared/repo/school/legacy-school.repo.ts +++ b/apps/server/src/shared/repo/school/legacy-school.repo.ts @@ -7,7 +7,7 @@ import { LegacySchoolDo, SchoolEntity, SystemEntity, - UserLoginMigration, + UserLoginMigrationEntity, } from '@shared/domain'; import { LegacyLogger } from '@src/core/logger'; import { BaseDORepo } from '../base.do.repo'; @@ -77,7 +77,7 @@ export class LegacySchoolRepo extends BaseDORepo this._em.getReference(SystemEntity, systemId)) : [], userLoginMigration: entityDO.userLoginMigrationId - ? this._em.getReference(UserLoginMigration, entityDO.userLoginMigrationId) + ? this._em.getReference(UserLoginMigrationEntity, entityDO.userLoginMigrationId) : undefined, federalState: entityDO.federalState, }; diff --git a/apps/server/src/shared/repo/userloginmigration/user-login-migration.repo.integration.spec.ts b/apps/server/src/shared/repo/userloginmigration/user-login-migration.repo.integration.spec.ts index ed4984dffe4..230e715307a 100644 --- a/apps/server/src/shared/repo/userloginmigration/user-login-migration.repo.integration.spec.ts +++ b/apps/server/src/shared/repo/userloginmigration/user-login-migration.repo.integration.spec.ts @@ -2,7 +2,7 @@ import { createMock } from '@golevelup/ts-jest'; import { EntityManager } from '@mikro-orm/mongodb'; import { Test, TestingModule } from '@nestjs/testing'; import { SchoolEntity, SystemEntity, UserLoginMigrationDO } from '@shared/domain'; -import { UserLoginMigration } from '@shared/domain/entity/user-login-migration.entity'; +import { UserLoginMigrationEntity } from '@shared/domain/entity/user-login-migration.entity'; import { MongoMemoryDatabaseModule } from '@shared/infra/database'; import { cleanupCollections, schoolFactory, systemFactory } from '@shared/testing'; import { LegacyLogger } from '@src/core/logger'; @@ -78,7 +78,7 @@ describe('UserLoginMigrationRepo', () => { describe('delete', () => { describe('when saving a UserLoginMigrationDO', () => { const setup = async () => { - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId(); + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId(); await em.persistAndFlush(userLoginMigration); em.clear(); @@ -105,7 +105,7 @@ describe('UserLoginMigrationRepo', () => { describe('findBySchoolId', () => { describe('when searching for a UserLoginMigration by its school id', () => { const setup = async () => { - const userLoginMigration: UserLoginMigration = userLoginMigrationFactory.buildWithId(); + const userLoginMigration: UserLoginMigrationEntity = userLoginMigrationFactory.buildWithId(); await em.persistAndFlush(userLoginMigration); em.clear(); diff --git a/apps/server/src/shared/repo/userloginmigration/user-login-migration.repo.ts b/apps/server/src/shared/repo/userloginmigration/user-login-migration.repo.ts index 346b3c3dced..8c2af1f866f 100644 --- a/apps/server/src/shared/repo/userloginmigration/user-login-migration.repo.ts +++ b/apps/server/src/shared/repo/userloginmigration/user-login-migration.repo.ts @@ -2,26 +2,30 @@ import { EntityName } from '@mikro-orm/core'; import { EntityManager } from '@mikro-orm/mongodb'; import { Injectable } from '@nestjs/common'; import { EntityId, SchoolEntity, SystemEntity, UserLoginMigrationDO } from '@shared/domain'; -import { IUserLoginMigration, UserLoginMigration } from '@shared/domain/entity/user-login-migration.entity'; +import { IUserLoginMigration, UserLoginMigrationEntity } from '@shared/domain/entity/user-login-migration.entity'; import { LegacyLogger } from '@src/core/logger'; import { BaseDORepo } from '../base.do.repo'; @Injectable() -export class UserLoginMigrationRepo extends BaseDORepo { +export class UserLoginMigrationRepo extends BaseDORepo< + UserLoginMigrationDO, + UserLoginMigrationEntity, + IUserLoginMigration +> { constructor(protected readonly _em: EntityManager, protected readonly logger: LegacyLogger) { super(_em, logger); } - get entityName(): EntityName { - return UserLoginMigration; + get entityName(): EntityName { + return UserLoginMigrationEntity; } - entityFactory(props: IUserLoginMigration): UserLoginMigration { - return new UserLoginMigration(props); + entityFactory(props: IUserLoginMigration): UserLoginMigrationEntity { + return new UserLoginMigrationEntity(props); } async findBySchoolId(schoolId: EntityId): Promise { - const userLoginMigration: UserLoginMigration | null = await this._em.findOne(UserLoginMigration, { + const userLoginMigration: UserLoginMigrationEntity | null = await this._em.findOne(UserLoginMigrationEntity, { school: schoolId, }); @@ -33,7 +37,7 @@ export class UserLoginMigrationRepo extends BaseDORepo( - UserLoginMigration, +export const userLoginMigrationFactory = BaseFactory.define( + UserLoginMigrationEntity, () => { return { school: schoolFactory.buildWithId(), From 6696c828f1e75969cb6c608f26abef0f6120ccf9 Mon Sep 17 00:00:00 2001 From: dyedwiper Date: Thu, 21 Sep 2023 16:41:12 +0200 Subject: [PATCH 4/5] Rename FederalState entity --- .../service/federal-state.service.spec.ts | 6 +-- .../service/federal-state.service.ts | 6 +-- .../modules/management/seed-data/schools.ts | 4 +- .../oidc/service/oidc-provisioning.service.ts | 4 +- .../domain/domainobject/legacy-school.do.ts | 4 +- .../src/shared/domain/entity/all-entities.ts | 4 +- .../domain/entity/federal-state.entity.ts | 2 +- .../src/shared/domain/entity/school.entity.ts | 8 +-- .../federalstate/federal-state.repo.spec.ts | 8 +-- .../repo/federalstate/federal-state.repo.ts | 12 ++--- .../testing/factory/federal-state.factory.ts | 49 ++++++++++--------- 11 files changed, 55 insertions(+), 52 deletions(-) diff --git a/apps/server/src/modules/legacy-school/service/federal-state.service.spec.ts b/apps/server/src/modules/legacy-school/service/federal-state.service.spec.ts index af491dd7574..1ca06d22d59 100644 --- a/apps/server/src/modules/legacy-school/service/federal-state.service.spec.ts +++ b/apps/server/src/modules/legacy-school/service/federal-state.service.spec.ts @@ -1,7 +1,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import { FederalStateRepo } from '@shared/repo'; import { federalStateFactory, setupEntities } from '@shared/testing'; -import { FederalState } from '@shared/domain'; +import { FederalStateEntity } from '@shared/domain'; import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { FederalStateService } from './federal-state.service'; import { FederalStateNames } from '../types/federal-state-names.enum'; @@ -34,7 +34,7 @@ describe('FederalStateService', () => { describe('findFederalStateByName', () => { const setup = () => { - const federalState: FederalState = federalStateFactory.build({ name: FederalStateNames.NIEDERSACHEN }); + const federalState: FederalStateEntity = federalStateFactory.build({ name: FederalStateNames.NIEDERSACHEN }); federalStateRepo.findByName.mockResolvedValue(federalState); return { @@ -45,7 +45,7 @@ describe('FederalStateService', () => { it('should return a federal state', async () => { const { federalState } = setup(); - const result: FederalState = await service.findFederalStateByName(federalState.name); + const result: FederalStateEntity = await service.findFederalStateByName(federalState.name); expect(result).toBeDefined(); }); diff --git a/apps/server/src/modules/legacy-school/service/federal-state.service.ts b/apps/server/src/modules/legacy-school/service/federal-state.service.ts index 96eaa7c6a2e..480fcabe988 100644 --- a/apps/server/src/modules/legacy-school/service/federal-state.service.ts +++ b/apps/server/src/modules/legacy-school/service/federal-state.service.ts @@ -1,14 +1,14 @@ import { Injectable } from '@nestjs/common'; import { FederalStateRepo } from '@shared/repo'; -import { FederalState } from '@shared/domain'; +import { FederalStateEntity } from '@shared/domain'; @Injectable() export class FederalStateService { constructor(private readonly federalStateRepo: FederalStateRepo) {} // TODO: N21-990 Refactoring: Create domain objects for schoolYear and federalState - async findFederalStateByName(name: string): Promise { - const federalState: FederalState = await this.federalStateRepo.findByName(name); + async findFederalStateByName(name: string): Promise { + const federalState: FederalStateEntity = await this.federalStateRepo.findByName(name); return federalState; } diff --git a/apps/server/src/modules/management/seed-data/schools.ts b/apps/server/src/modules/management/seed-data/schools.ts index 83f6311a2f2..a4d9e538594 100644 --- a/apps/server/src/modules/management/seed-data/schools.ts +++ b/apps/server/src/modules/management/seed-data/schools.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/dot-notation */ import { - FederalState, + FederalStateEntity, ISchoolProperties, SchoolFeatures, SchoolRoles, @@ -273,7 +273,7 @@ const seedSchools: SeedSchoolProperties[] = [ export function generateSchools(entities: { systems: SystemEntity[]; schoolYears: SchoolYearEntity[]; - federalStates: FederalState[]; + federalStates: FederalStateEntity[]; }) { return seedSchools.map((partial) => { const schoolYear = entities.schoolYears.find((sy) => partial.currentYear && sy.name === partial.currentYear); diff --git a/apps/server/src/modules/provisioning/strategy/oidc/service/oidc-provisioning.service.ts b/apps/server/src/modules/provisioning/strategy/oidc/service/oidc-provisioning.service.ts index fe2702a63a3..1a16b8578c9 100644 --- a/apps/server/src/modules/provisioning/strategy/oidc/service/oidc-provisioning.service.ts +++ b/apps/server/src/modules/provisioning/strategy/oidc/service/oidc-provisioning.service.ts @@ -1,5 +1,5 @@ import { Injectable, UnprocessableEntityException } from '@nestjs/common'; -import { EntityId, ExternalSource, FederalState, SchoolFeatures, SchoolYearEntity } from '@shared/domain'; +import { EntityId, ExternalSource, FederalStateEntity, SchoolFeatures, SchoolYearEntity } from '@shared/domain'; import { LegacySchoolDo, RoleReference, UserDO } from '@shared/domain/domainobject'; import { Logger } from '@src/core/logger'; import { AccountService } from '@src/modules/account/services/account.service'; @@ -45,7 +45,7 @@ export class OidcProvisioningService { } } else { const schoolYear: SchoolYearEntity = await this.schoolYearService.getCurrentSchoolYear(); - const federalState: FederalState = await this.federalStateService.findFederalStateByName( + const federalState: FederalStateEntity = await this.federalStateService.findFederalStateByName( FederalStateNames.NIEDERSACHEN ); diff --git a/apps/server/src/shared/domain/domainobject/legacy-school.do.ts b/apps/server/src/shared/domain/domainobject/legacy-school.do.ts index c7f40e899f4..d83941e6dae 100644 --- a/apps/server/src/shared/domain/domainobject/legacy-school.do.ts +++ b/apps/server/src/shared/domain/domainobject/legacy-school.do.ts @@ -1,4 +1,4 @@ -import { FederalState, SchoolFeatures, SchoolYearEntity } from '@shared/domain/entity'; +import { FederalStateEntity, SchoolFeatures, SchoolYearEntity } from '@shared/domain/entity'; import { EntityId } from '@shared/domain/types'; import { BaseDO } from './base.do'; @@ -28,7 +28,7 @@ export class LegacySchoolDo extends BaseDO { userLoginMigrationId?: EntityId; // TODO: N21-990 Refactoring: Create domain objects for schoolYear and federalState - federalState: FederalState; + federalState: FederalStateEntity; constructor(params: LegacySchoolDo) { super(); diff --git a/apps/server/src/shared/domain/entity/all-entities.ts b/apps/server/src/shared/domain/entity/all-entities.ts index 0f6ee049c4f..59726b31f25 100644 --- a/apps/server/src/shared/domain/entity/all-entities.ts +++ b/apps/server/src/shared/domain/entity/all-entities.ts @@ -19,7 +19,7 @@ import { BoardNode } from './boardnode/boardnode.entity'; import { Course } from './course.entity'; import { CourseGroup } from './coursegroup.entity'; import { DashboardGridElementModel, DashboardModelEntity } from './dashboard.model.entity'; -import { FederalState } from './federal-state.entity'; +import { FederalStateEntity } from './federal-state.entity'; import { ImportUser } from './import-user.entity'; import { Board, @@ -67,7 +67,7 @@ export const ALL_ENTITIES = [ DashboardGridElementModel, DashboardModelEntity, ExternalToolEntity, - FederalState, + FederalStateEntity, ImportUser, Lesson, LessonBoardElement, diff --git a/apps/server/src/shared/domain/entity/federal-state.entity.ts b/apps/server/src/shared/domain/entity/federal-state.entity.ts index 269a4a4cd0b..d65b36c9826 100644 --- a/apps/server/src/shared/domain/entity/federal-state.entity.ts +++ b/apps/server/src/shared/domain/entity/federal-state.entity.ts @@ -26,7 +26,7 @@ export class County { } @Entity({ tableName: 'federalstates' }) -export class FederalState extends BaseEntityWithTimestamps { +export class FederalStateEntity extends BaseEntityWithTimestamps { @Property({ nullable: false }) name: string; diff --git a/apps/server/src/shared/domain/entity/school.entity.ts b/apps/server/src/shared/domain/entity/school.entity.ts index b16dfb0b601..67780eb4584 100644 --- a/apps/server/src/shared/domain/entity/school.entity.ts +++ b/apps/server/src/shared/domain/entity/school.entity.ts @@ -13,7 +13,7 @@ import { UserLoginMigrationEntity } from '@shared/domain/entity/user-login-migra import { BaseEntity } from './base.entity'; import { SchoolYearEntity } from './schoolyear.entity'; import { SystemEntity } from './system.entity'; -import { FederalState } from './federal-state.entity'; +import { FederalStateEntity } from './federal-state.entity'; export enum SchoolFeatures { ROCKET_CHAT = 'rocketChat', @@ -38,7 +38,7 @@ export interface ISchoolProperties { features?: SchoolFeatures[]; schoolYear?: SchoolYearEntity; userLoginMigration?: UserLoginMigrationEntity; - federalState: FederalState; + federalState: FederalStateEntity; } @Embeddable() @@ -103,8 +103,8 @@ export class SchoolEntity extends BaseEntity { ) userLoginMigration?: UserLoginMigrationEntity; - @ManyToOne(() => FederalState, { fieldName: 'federalState', nullable: false }) - federalState: FederalState; + @ManyToOne(() => FederalStateEntity, { fieldName: 'federalState', nullable: false }) + federalState: FederalStateEntity; constructor(props: ISchoolProperties) { super(); diff --git a/apps/server/src/shared/repo/federalstate/federal-state.repo.spec.ts b/apps/server/src/shared/repo/federalstate/federal-state.repo.spec.ts index f8ff15cbf5a..bfd6b6e358e 100644 --- a/apps/server/src/shared/repo/federalstate/federal-state.repo.spec.ts +++ b/apps/server/src/shared/repo/federalstate/federal-state.repo.spec.ts @@ -1,6 +1,6 @@ import { Test, TestingModule } from '@nestjs/testing'; import { EntityManager } from '@mikro-orm/mongodb'; -import { FederalState } from '@shared/domain'; +import { FederalStateEntity } from '@shared/domain'; import { cleanupCollections, federalStateFactory } from '@shared/testing'; import { MongoMemoryDatabaseModule } from '@shared/infra/database'; import { FederalStateRepo } from './federal-state.repo'; @@ -25,16 +25,16 @@ describe('FederalStateRepo', () => { afterEach(async () => { await cleanupCollections(em); - await em.nativeDelete(FederalState, {}); + await em.nativeDelete(FederalStateEntity, {}); }); it('should implement entityName getter', () => { - expect(repo.entityName).toBe(FederalState); + expect(repo.entityName).toBe(FederalStateEntity); }); describe('findByName', () => { const setup = async () => { - const federalState: FederalState = federalStateFactory.build(); + const federalState: FederalStateEntity = federalStateFactory.build(); await em.persistAndFlush(federalState); em.clear(); diff --git a/apps/server/src/shared/repo/federalstate/federal-state.repo.ts b/apps/server/src/shared/repo/federalstate/federal-state.repo.ts index 115ead8d7db..5f831990e7e 100644 --- a/apps/server/src/shared/repo/federalstate/federal-state.repo.ts +++ b/apps/server/src/shared/repo/federalstate/federal-state.repo.ts @@ -1,15 +1,15 @@ import { Injectable } from '@nestjs/common'; -import { FederalState } from '@shared/domain'; +import { FederalStateEntity } from '@shared/domain'; import { EntityName } from '@mikro-orm/core'; import { BaseRepo } from '../base.repo'; @Injectable() -export class FederalStateRepo extends BaseRepo { - get entityName(): EntityName { - return FederalState; +export class FederalStateRepo extends BaseRepo { + get entityName(): EntityName { + return FederalStateEntity; } - findByName(name: string): Promise { - return this._em.findOneOrFail(FederalState, { name }); + findByName(name: string): Promise { + return this._em.findOneOrFail(FederalStateEntity, { name }); } } diff --git a/apps/server/src/shared/testing/factory/federal-state.factory.ts b/apps/server/src/shared/testing/factory/federal-state.factory.ts index 48295065a90..71290151668 100644 --- a/apps/server/src/shared/testing/factory/federal-state.factory.ts +++ b/apps/server/src/shared/testing/factory/federal-state.factory.ts @@ -1,25 +1,28 @@ -import { County, FederalState, IFederalStateProperties } from '@shared/domain'; +import { County, FederalStateEntity, IFederalStateProperties } from '@shared/domain'; import { BaseFactory } from './base.factory'; -export const federalStateFactory = BaseFactory.define(FederalState, () => { - return { - name: 'Hamburg', - abbreviation: 'HH', - logoUrl: - 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/6b/Coat_of_arms_of_Hamburg.svg/1200px-Coat_of_arms_of_Hamburg.svg.png', - counties: [ - new County({ - name: 'Hamburg-Mitte', - countyId: 2000, - antaresKey: '02000', - }), - new County({ - name: 'Altona', - countyId: 2002, - antaresKey: '02002', - }), - ], - createdAt: new Date(2020, 1), - updatedAt: new Date(2020, 1), - }; -}); +export const federalStateFactory = BaseFactory.define( + FederalStateEntity, + () => { + return { + name: 'Hamburg', + abbreviation: 'HH', + logoUrl: + 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/6b/Coat_of_arms_of_Hamburg.svg/1200px-Coat_of_arms_of_Hamburg.svg.png', + counties: [ + new County({ + name: 'Hamburg-Mitte', + countyId: 2000, + antaresKey: '02000', + }), + new County({ + name: 'Altona', + countyId: 2002, + antaresKey: '02002', + }), + ], + createdAt: new Date(2020, 1), + updatedAt: new Date(2020, 1), + }; + } +); From b96c5fd4852d6e31a2bd42b654b89bb4c108b08a Mon Sep 17 00:00:00 2001 From: dyedwiper Date: Thu, 21 Sep 2023 16:58:00 +0200 Subject: [PATCH 5/5] Fix references --- apps/server/src/shared/domain/entity/import-user.entity.ts | 2 +- apps/server/src/shared/domain/entity/school.entity.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/server/src/shared/domain/entity/import-user.entity.ts b/apps/server/src/shared/domain/entity/import-user.entity.ts index 430efdb9652..09a10179e3d 100644 --- a/apps/server/src/shared/domain/entity/import-user.entity.ts +++ b/apps/server/src/shared/domain/entity/import-user.entity.ts @@ -53,7 +53,7 @@ export class ImportUser extends BaseEntityWithTimestamps implements IEntityWithS @ManyToOne(() => SchoolEntity, { fieldName: 'schoolId', wrappedReference: true, eager: true }) school: IdentifiedReference; - @ManyToOne(() => 'System', { wrappedReference: true }) + @ManyToOne(() => SystemEntity, { wrappedReference: true }) system: IdentifiedReference; @Property() diff --git a/apps/server/src/shared/domain/entity/school.entity.ts b/apps/server/src/shared/domain/entity/school.entity.ts index 67780eb4584..98502a127eb 100644 --- a/apps/server/src/shared/domain/entity/school.entity.ts +++ b/apps/server/src/shared/domain/entity/school.entity.ts @@ -83,13 +83,13 @@ export class SchoolEntity extends BaseEntity { @Property({ nullable: true }) officialSchoolNumber?: string; - @ManyToMany('System', undefined, { fieldName: 'systems' }) + @ManyToMany(() => SystemEntity, undefined, { fieldName: 'systems' }) systems = new Collection(this); @Embedded(() => SchoolRoles, { object: true, nullable: true, prefix: false }) permissions?: SchoolRoles; - @ManyToOne('SchoolYear', { fieldName: 'currentYear', nullable: true }) + @ManyToOne(() => SchoolYearEntity, { fieldName: 'currentYear', nullable: true }) schoolYear?: SchoolYearEntity; @OneToOne(