diff --git a/apps/server/src/modules/group/controller/api-test/group.api.spec.ts b/apps/server/src/modules/group/controller/api-test/group.api.spec.ts index 32a9740cd7d..592580b47c6 100644 --- a/apps/server/src/modules/group/controller/api-test/group.api.spec.ts +++ b/apps/server/src/modules/group/controller/api-test/group.api.spec.ts @@ -7,13 +7,13 @@ import { Test, TestingModule } from '@nestjs/testing'; import { Role, SchoolEntity, SchoolYearEntity, SystemEntity, User } from '@shared/domain/entity'; import { RoleName, SortOrder } from '@shared/domain/interface'; import { - TestApiClient, - UserAndAccountTestFactory, groupEntityFactory, roleFactory, schoolFactory, schoolYearFactory, systemEntityFactory, + TestApiClient, + UserAndAccountTestFactory, userFactory, } from '@shared/testing'; import { ObjectId } from 'bson'; @@ -104,7 +104,7 @@ describe('Group (API)', () => { }; it('should return the classes of his school', async () => { - const { adminClient, group, clazz, system, adminUser, teacherUser, schoolYear } = await setup(); + const { adminClient, group, clazz, system, schoolYear } = await setup(); const response = await adminClient.get(`/class`).query({ skip: 0, @@ -121,14 +121,14 @@ describe('Group (API)', () => { type: ClassRootType.GROUP, name: group.name, externalSourceName: system.displayName, - teachers: [adminUser.lastName], + teachers: [], studentCount: 0, }, { id: clazz.id, type: ClassRootType.CLASS, name: clazz.gradeLevel ? `${clazz.gradeLevel}${clazz.name}` : clazz.name, - teachers: [teacherUser.lastName], + teachers: [], schoolYear: schoolYear.name, isUpgradable: false, studentCount: 0, diff --git a/apps/server/src/modules/group/controller/group.controller.ts b/apps/server/src/modules/group/controller/group.controller.ts index e5df1dec514..4ed85bd2755 100644 --- a/apps/server/src/modules/group/controller/group.controller.ts +++ b/apps/server/src/modules/group/controller/group.controller.ts @@ -6,13 +6,13 @@ import { ErrorResponse } from '@src/core/error/dto'; import { GroupUc } from '../uc'; import { ClassInfoDto, ResolvedGroupDto } from '../uc/dto'; import { + ClassCallerParams, ClassFilterParams, ClassInfoSearchListResponse, ClassSortParams, GroupIdParams, - GroupResponse, GroupPaginationParams, - ClassCallerParams, + GroupResponse, } from './dto'; import { GroupResponseMapper } from './mapper'; diff --git a/apps/server/src/modules/group/uc/group.uc.spec.ts b/apps/server/src/modules/group/uc/group.uc.spec.ts index 3a53d6d2f80..96bbd9d15dc 100644 --- a/apps/server/src/modules/group/uc/group.uc.spec.ts +++ b/apps/server/src/modules/group/uc/group.uc.spec.ts @@ -7,11 +7,12 @@ import { classFactory } from '@modules/class/domain/testing/factory/class.factor import { SchoolYearService } from '@modules/legacy-school'; import { RoleService } from '@modules/role'; import { RoleDto } from '@modules/role/service/dto/role.dto'; +import { School, SchoolService } from '@modules/school/domain'; +import { schoolFactory } from '@modules/school/testing'; import { LegacySystemService, SystemDto } from '@modules/system'; import { UserService } from '@modules/user'; import { ForbiddenException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; -import { ReferencedEntityNotFoundLoggable } from '@shared/common/loggable'; import { NotFoundLoggableException } from '@shared/common/loggable-exception'; import { Page, UserDO } from '@shared/domain/domainobject'; import { SchoolYearEntity, User } from '@shared/domain/entity'; @@ -27,8 +28,6 @@ import { userFactory, } from '@shared/testing'; import { Logger } from '@src/core/logger'; -import { School, SchoolService } from '@modules/school/domain'; -import { schoolFactory } from '@modules/school/testing'; import { ClassRequestContext, SchoolYearQueryType } from '../controller/dto/interface'; import { Group, GroupTypes } from '../domain'; import { UnknownQueryTypeLoggableException } from '../loggable'; @@ -49,6 +48,7 @@ describe('GroupUc', () => { let schoolService: DeepMocked; let authorizationService: DeepMocked; let schoolYearService: DeepMocked; + // eslint-disable-next-line @typescript-eslint/no-unused-vars let logger: DeepMocked; beforeAll(async () => { @@ -336,7 +336,7 @@ describe('GroupUc', () => { name: clazz.gradeLevel ? `${clazz.gradeLevel}${clazz.name}` : clazz.name, type: ClassRootType.CLASS, externalSourceName: clazz.source, - teacherNames: [teacherUser.lastName], + teacherNames: [], schoolYear: schoolYear.name, isUpgradable: false, studentCount: 2, @@ -348,7 +348,7 @@ describe('GroupUc', () => { : successorClass.name, type: ClassRootType.CLASS, externalSourceName: successorClass.source, - teacherNames: [teacherUser.lastName], + teacherNames: [], schoolYear: nextSchoolYear.name, isUpgradable: false, studentCount: 2, @@ -360,7 +360,7 @@ describe('GroupUc', () => { : classWithoutSchoolYear.name, type: ClassRootType.CLASS, externalSourceName: classWithoutSchoolYear.source, - teacherNames: [teacherUser.lastName], + teacherNames: [], isUpgradable: false, studentCount: 2, }, @@ -368,7 +368,7 @@ describe('GroupUc', () => { id: group.id, name: group.name, type: ClassRootType.GROUP, - teacherNames: [teacherUser.lastName], + teacherNames: [], studentCount: 0, }, { @@ -376,8 +376,8 @@ describe('GroupUc', () => { name: groupWithSystem.name, type: ClassRootType.GROUP, externalSourceName: system.displayName, - teacherNames: [teacherUser.lastName], - studentCount: 1, + teacherNames: [], + studentCount: 0, }, ], total: 5, @@ -420,7 +420,7 @@ describe('GroupUc', () => { : classWithoutSchoolYear.name, type: ClassRootType.CLASS, externalSourceName: classWithoutSchoolYear.source, - teacherNames: [teacherUser.lastName], + teacherNames: [], isUpgradable: false, studentCount: 2, }, @@ -429,7 +429,7 @@ describe('GroupUc', () => { name: clazz.gradeLevel ? `${clazz.gradeLevel}${clazz.name}` : clazz.name, type: ClassRootType.CLASS, externalSourceName: clazz.source, - teacherNames: [teacherUser.lastName], + teacherNames: [], schoolYear: schoolYear.name, isUpgradable: false, studentCount: 2, @@ -439,14 +439,14 @@ describe('GroupUc', () => { name: groupWithSystem.name, type: ClassRootType.GROUP, externalSourceName: system.displayName, - teacherNames: [teacherUser.lastName], - studentCount: 1, + teacherNames: [], + studentCount: 0, }, { id: group.id, name: group.name, type: ClassRootType.GROUP, - teacherNames: [teacherUser.lastName], + teacherNames: [], studentCount: 0, }, ], @@ -476,7 +476,7 @@ describe('GroupUc', () => { id: group.id, name: group.name, type: ClassRootType.GROUP, - teacherNames: [teacherUser.lastName], + teacherNames: [], studentCount: 0, }, ], @@ -504,7 +504,7 @@ describe('GroupUc', () => { : successorClass.name, externalSourceName: successorClass.source, type: ClassRootType.CLASS, - teacherNames: [teacherUser.lastName], + teacherNames: [], schoolYear: nextSchoolYear.name, isUpgradable: false, studentCount: 2, @@ -698,7 +698,7 @@ describe('GroupUc', () => { describe('when no pagination is given', () => { it('should return all classes sorted by name', async () => { - const { adminUser, teacherUser, clazz, group, groupWithSystem, system, schoolYear } = setup(); + const { adminUser, clazz, group, groupWithSystem, system, schoolYear } = setup(); const result: Page = await uc.findAllClasses(adminUser.id, adminUser.school.id); @@ -709,7 +709,7 @@ describe('GroupUc', () => { name: clazz.gradeLevel ? `${clazz.gradeLevel}${clazz.name}` : clazz.name, type: ClassRootType.CLASS, externalSourceName: clazz.source, - teacherNames: [teacherUser.lastName], + teacherNames: [], schoolYear: schoolYear.name, isUpgradable: false, studentCount: 2, @@ -718,7 +718,7 @@ describe('GroupUc', () => { id: group.id, name: group.name, type: ClassRootType.GROUP, - teacherNames: [teacherUser.lastName], + teacherNames: [], studentCount: 0, }, { @@ -726,8 +726,8 @@ describe('GroupUc', () => { name: groupWithSystem.name, type: ClassRootType.GROUP, externalSourceName: system.displayName, - teacherNames: [teacherUser.lastName], - studentCount: 1, + teacherNames: [], + studentCount: 0, }, ], total: 3, @@ -748,7 +748,7 @@ describe('GroupUc', () => { describe('when sorting by external source name in descending order', () => { it('should return all classes sorted by external source name in descending order', async () => { - const { adminUser, teacherUser, clazz, group, groupWithSystem, system, schoolYear } = setup(); + const { adminUser, clazz, group, groupWithSystem, system, schoolYear } = setup(); const result: Page = await uc.findAllClasses( adminUser.id, @@ -768,7 +768,7 @@ describe('GroupUc', () => { name: clazz.gradeLevel ? `${clazz.gradeLevel}${clazz.name}` : clazz.name, type: ClassRootType.CLASS, externalSourceName: clazz.source, - teacherNames: [teacherUser.lastName], + teacherNames: [], schoolYear: schoolYear.name, isUpgradable: false, studentCount: 2, @@ -778,14 +778,14 @@ describe('GroupUc', () => { name: groupWithSystem.name, type: ClassRootType.GROUP, externalSourceName: system.displayName, - teacherNames: [teacherUser.lastName], - studentCount: 1, + teacherNames: [], + studentCount: 0, }, { id: group.id, name: group.name, type: ClassRootType.GROUP, - teacherNames: [teacherUser.lastName], + teacherNames: [], studentCount: 0, }, ], @@ -796,7 +796,7 @@ describe('GroupUc', () => { describe('when using pagination', () => { it('should return the selected page', async () => { - const { adminUser, teacherUser, group } = setup(); + const { adminUser, group } = setup(); const result: Page = await uc.findAllClasses( adminUser.id, @@ -815,7 +815,7 @@ describe('GroupUc', () => { id: group.id, name: group.name, type: ClassRootType.GROUP, - teacherNames: [teacherUser.lastName], + teacherNames: [], studentCount: 0, }, ], @@ -948,7 +948,7 @@ describe('GroupUc', () => { name: clazz.gradeLevel ? `${clazz.gradeLevel}${clazz.name}` : clazz.name, type: ClassRootType.CLASS, externalSourceName: clazz.source, - teacherNames: [teacherUser.lastName], + teacherNames: [], schoolYear: schoolYear.name, isUpgradable: false, studentCount: 2, @@ -957,26 +957,13 @@ describe('GroupUc', () => { id: group.id, name: group.name, type: ClassRootType.GROUP, - teacherNames: [teacherUser.lastName], + teacherNames: [], studentCount: 0, }, ], total: 2, }); }); - - it('should log the missing user', async () => { - const { teacherUser, clazz, group, notFoundReferenceId } = setup(); - - await uc.findAllClasses(teacherUser.id, teacherUser.school.id); - - expect(logger.warning).toHaveBeenCalledWith( - new ReferencedEntityNotFoundLoggable(Class.name, clazz.id, UserDO.name, notFoundReferenceId) - ); - expect(logger.warning).toHaveBeenCalledWith( - new ReferencedEntityNotFoundLoggable(Group.name, group.id, UserDO.name, notFoundReferenceId) - ); - }); }); }); diff --git a/apps/server/src/modules/group/uc/group.uc.ts b/apps/server/src/modules/group/uc/group.uc.ts index 18bb1c5e466..babed7387d2 100644 --- a/apps/server/src/modules/group/uc/group.uc.ts +++ b/apps/server/src/modules/group/uc/group.uc.ts @@ -3,18 +3,17 @@ import { ClassService } from '@modules/class'; import { Class } from '@modules/class/domain'; import { SchoolYearService } from '@modules/legacy-school'; import { RoleService } from '@modules/role'; -import { RoleDto } from '@modules/role/service/dto/role.dto'; +import { School, SchoolService } from '@modules/school/domain'; import { UserService } from '@modules/user'; import { Injectable } from '@nestjs/common'; import { SortHelper } from '@shared/common'; -import { ReferencedEntityNotFoundLoggable } from '@shared/common/loggable'; import { Page, UserDO } from '@shared/domain/domainobject'; import { SchoolYearEntity, User } from '@shared/domain/entity'; import { Permission, SortOrder } from '@shared/domain/interface'; import { EntityId } from '@shared/domain/types'; import { Logger } from '@src/core/logger'; import { LegacySystemService, SystemDto } from '@src/modules/system'; -import { School, SchoolService } from '@modules/school/domain'; +import { RoleDto } from '../../role/service/dto/role.dto'; import { ClassRequestContext, SchoolYearQueryType } from '../controller/dto/interface'; import { Group, GroupTypes, GroupUser } from '../domain'; import { UnknownQueryTypeLoggableException } from '../loggable'; @@ -153,7 +152,7 @@ export class GroupUc { this.isClassOfQueryType(currentYear, classWithSchoolYear.schoolYear, schoolYearQueryType) ); - const classInfosFromClasses: ClassInfoDto[] = await this.mapClassInfosFromClasses(filteredClassesForSchoolYear); + const classInfosFromClasses: ClassInfoDto[] = this.mapClassInfosFromClasses(filteredClassesForSchoolYear); return classInfosFromClasses; } @@ -201,13 +200,12 @@ export class GroupUc { } } - private async mapClassInfosFromClasses( + private mapClassInfosFromClasses( filteredClassesForSchoolYear: { clazz: Class; schoolYear?: SchoolYearEntity }[] - ): Promise { - const classInfosFromClasses: ClassInfoDto[] = await Promise.all( - filteredClassesForSchoolYear.map(async (classWithSchoolYear): Promise => { - const { teacherIds } = classWithSchoolYear.clazz; - const teachers: UserDO[] = await this.getTeachersByIds(teacherIds, classWithSchoolYear.clazz.id); + ): ClassInfoDto[] { + const classInfosFromClasses: ClassInfoDto[] = filteredClassesForSchoolYear.map( + (classWithSchoolYear): ClassInfoDto => { + const teachers: UserDO[] = []; const mapped: ClassInfoDto = GroupUcMapper.mapClassToClassInfoDto( classWithSchoolYear.clazz, @@ -216,28 +214,9 @@ export class GroupUc { ); return mapped; - }) - ); - - return classInfosFromClasses; - } - - private async getTeachersByIds(teacherIds: EntityId[], classId: EntityId): Promise { - const teacherPromises: Promise[] = teacherIds.map( - async (teacherId: EntityId): Promise => { - const teacher: UserDO | null = await this.userService.findByIdOrNull(teacherId); - if (!teacher) { - this.logger.warning(new ReferencedEntityNotFoundLoggable(Class.name, classId, UserDO.name, teacherId)); - } - return teacher; } ); - - const teachers: UserDO[] = (await Promise.all(teacherPromises)).filter( - (teacher: UserDO | null): teacher is UserDO => teacher !== null - ); - - return teachers; + return classInfosFromClasses; } private async findGroupsForSchool(schoolId: EntityId): Promise { @@ -248,10 +227,9 @@ export class GroupUc { const systemMap: Map = await this.findSystemNamesForGroups(groups); - const classInfosFromGroups: ClassInfoDto[] = await Promise.all( - groups.map(async (group: Group): Promise => this.getClassInfoFromGroup(group, systemMap)) + const classInfosFromGroups: ClassInfoDto[] = groups.map( + (group: Group): ClassInfoDto => this.getClassInfoFromGroup(group, systemMap) ); - return classInfosFromGroups; } @@ -265,20 +243,20 @@ export class GroupUc { const systemMap: Map = await this.findSystemNamesForGroups(groupsOfTypeClass); - const classInfosFromGroups: ClassInfoDto[] = await Promise.all( - groupsOfTypeClass.map(async (group: Group): Promise => this.getClassInfoFromGroup(group, systemMap)) + const classInfosFromGroups: ClassInfoDto[] = groupsOfTypeClass.map( + (group: Group): ClassInfoDto => this.getClassInfoFromGroup(group, systemMap) ); return classInfosFromGroups; } - private async getClassInfoFromGroup(group: Group, systemMap: Map): Promise { + private getClassInfoFromGroup(group: Group, systemMap: Map): ClassInfoDto { let system: SystemDto | undefined; if (group.externalSource) { system = systemMap.get(group.externalSource.systemId); } - const resolvedUsers: ResolvedGroupUser[] = await this.findUsersForGroup(group); + const resolvedUsers: ResolvedGroupUser[] = []; const mapped: ClassInfoDto = GroupUcMapper.mapGroupToClassInfoDto(group, resolvedUsers, system); @@ -311,11 +289,11 @@ export class GroupUc { const user: UserDO | null = await this.userService.findByIdOrNull(groupUser.userId); let resolvedGroup: ResolvedGroupUser | null = null; - if (!user) { - this.logger.warning( + /* TODO add this log back later + this.logger.warning( new ReferencedEntityNotFoundLoggable(Group.name, group.id, UserDO.name, groupUser.userId) - ); - } else { + ); */ + if (user) { const role: RoleDto = await this.roleService.findById(groupUser.roleId); resolvedGroup = new ResolvedGroupUser({