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 d1cb9748e7d..90b3b71b570 100644 --- a/apps/server/src/modules/group/uc/group.uc.spec.ts +++ b/apps/server/src/modules/group/uc/group.uc.spec.ts @@ -522,7 +522,7 @@ describe('GroupUc', () => { }); describe('when accessing as a user with elevated permission', () => { - const setup = () => { + const setup = (generateClasses = false) => { const school: LegacySchoolDo = legacySchoolDoFactory.buildWithId(); const { studentUser } = UserAndAccountTestFactory.buildStudent(); const { teacherUser } = UserAndAccountTestFactory.buildTeacher(); @@ -551,6 +551,15 @@ describe('GroupUc', () => { roles: [{ id: studentUser.roles[0].id, name: studentUser.roles[0].name }], }); const schoolYear: SchoolYearEntity = schoolYearFactory.buildWithId(); + let clazzes: Class[] = []; + if (generateClasses) { + clazzes = classFactory.buildList(11, { + name: 'A', + teacherIds: [teacherUser.id], + source: 'LDAP', + year: schoolYear.id, + }); + } const clazz: Class = classFactory.build({ name: 'A', teacherIds: [teacherUser.id], @@ -579,7 +588,7 @@ describe('GroupUc', () => { schoolService.getSchoolById.mockResolvedValueOnce(school); authorizationService.getUserWithPermissions.mockResolvedValueOnce(adminUser); authorizationService.hasAllPermissions.mockReturnValueOnce(true); - classService.findClassesForSchool.mockResolvedValueOnce([clazz]); + classService.findClassesForSchool.mockResolvedValueOnce([...clazzes, clazz]); groupService.findGroupsBySchoolIdAndGroupTypes.mockResolvedValueOnce([group, groupWithSystem]); systemService.findById.mockResolvedValue(system); @@ -788,6 +797,28 @@ describe('GroupUc', () => { total: 3, }); }); + + it('should return classes with expected limit', async () => { + const { adminUser } = setup(true); + + const result: Page = await uc.findAllClasses( + adminUser.id, + adminUser.school.id, + undefined, + 0, + 5 + ); + + expect(result.data.length).toEqual(5); + }); + + it('should return all classes without limit', async () => { + const { adminUser } = setup(true); + + const result: Page = await uc.findAllClasses(adminUser.id, adminUser.school.id); + + expect(result.data.length).toEqual(14); + }); }); }); diff --git a/apps/server/src/modules/group/uc/group.uc.ts b/apps/server/src/modules/group/uc/group.uc.ts index 13e4741b289..272019c5e77 100644 --- a/apps/server/src/modules/group/uc/group.uc.ts +++ b/apps/server/src/modules/group/uc/group.uc.ts @@ -331,8 +331,14 @@ export class GroupUc { return resolvedGroupUsers; } - private applyPagination(combinedClassInfo: ClassInfoDto[], skip: number, limit: number | undefined) { - const page: ClassInfoDto[] = combinedClassInfo.slice(skip, limit ? skip + limit : combinedClassInfo.length); + private applyPagination(combinedClassInfo: ClassInfoDto[], skip: number, limit: number | undefined): ClassInfoDto[] { + let page: ClassInfoDto[]; + + if (limit === -1) { + page = combinedClassInfo.slice(skip); + } else { + page = combinedClassInfo.slice(skip, limit ? skip + limit : combinedClassInfo.length); + } return page; } diff --git a/apps/server/src/shared/controller/dto/pagination.params.ts b/apps/server/src/shared/controller/dto/pagination.params.ts index e44d4a438f8..5cc5434499f 100644 --- a/apps/server/src/shared/controller/dto/pagination.params.ts +++ b/apps/server/src/shared/controller/dto/pagination.params.ts @@ -1,5 +1,5 @@ -import { IsInt, Max, Min } from 'class-validator'; import { ApiPropertyOptional } from '@nestjs/swagger'; +import { IsInt, Min } from 'class-validator'; export class PaginationParams { @IsInt() @@ -8,8 +8,6 @@ export class PaginationParams { skip?: number = 0; @IsInt() - @Min(1) - @Max(100) - @ApiPropertyOptional({ description: 'Page limit, defaults to 10.', minimum: 1, maximum: 99 }) + @ApiPropertyOptional({ description: 'Page limit, defaults to 10.' }) limit?: number = 10; }