Skip to content

Commit

Permalink
add studentCount to class info response, tests adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorCapCoder committed Oct 24, 2023
1 parent 88c6f4e commit 4f594ed
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ describe('Group (API)', () => {
name: group.name,
externalSourceName: system.displayName,
teachers: [adminUser.lastName],
studentCount: 0,
},
{
id: clazz.id,
Expand All @@ -128,6 +129,7 @@ describe('Group (API)', () => {
teachers: [teacherUser.lastName],
schoolYear: schoolYear.name,
isUpgradable: false,
studentCount: 0,
},
],
skip: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export class ClassInfoResponse {
@ApiPropertyOptional()
isUpgradable?: boolean;

@ApiProperty()
studentCount: number;

constructor(props: ClassInfoResponse) {
this.id = props.id;
this.type = props.type;
Expand All @@ -31,5 +34,6 @@ export class ClassInfoResponse {
this.teachers = props.teachers;
this.schoolYear = props.schoolYear;
this.isUpgradable = props.isUpgradable;
this.studentCount = props.studentCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class GroupResponseMapper {
teachers: classInfo.teachers,
schoolYear: classInfo.schoolYear,
isUpgradable: classInfo.isUpgradable,
studentCount: classInfo.studentCount,
});

return mapped;
Expand Down
3 changes: 3 additions & 0 deletions apps/server/src/modules/group/uc/dto/class-info.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export class ClassInfoDto {

isUpgradable?: boolean;

studentCount: number;

constructor(props: ClassInfoDto) {
this.id = props.id;
this.type = props.type;
Expand All @@ -23,5 +25,6 @@ export class ClassInfoDto {
this.teachers = props.teachers;
this.schoolYear = props.schoolYear;
this.isUpgradable = props.isUpgradable;
this.studentCount = props.studentCount;
}
}
7 changes: 7 additions & 0 deletions apps/server/src/modules/group/uc/group.uc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,22 @@ describe('GroupUc', () => {
teachers: [teacherUser.lastName],
schoolYear: schoolYear.name,
isUpgradable: false,
studentCount: 2,
},
{
id: group.id,
name: group.name,
type: ClassRootType.GROUP,
teachers: [teacherUser.lastName],
studentCount: 0,
},
{
id: groupWithSystem.id,
name: groupWithSystem.name,
type: ClassRootType.GROUP,
externalSourceName: system.displayName,
teachers: [teacherUser.lastName],
studentCount: 1,
},
],
total: 3,
Expand Down Expand Up @@ -293,19 +296,22 @@ describe('GroupUc', () => {
teachers: [teacherUser.lastName],
schoolYear: schoolYear.name,
isUpgradable: false,
studentCount: 2,
},
{
id: groupWithSystem.id,
name: groupWithSystem.name,
type: ClassRootType.GROUP,
externalSourceName: system.displayName,
teachers: [teacherUser.lastName],
studentCount: 1,
},
{
id: group.id,
name: group.name,
type: ClassRootType.GROUP,
teachers: [teacherUser.lastName],
studentCount: 0,
},
],
total: 3,
Expand Down Expand Up @@ -333,6 +339,7 @@ describe('GroupUc', () => {
name: group.name,
type: ClassRootType.GROUP,
teachers: [teacherUser.lastName],
studentCount: 0,
},
],
total: 3,
Expand Down
3 changes: 3 additions & 0 deletions apps/server/src/modules/group/uc/mapper/group-uc.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export class GroupUcMapper {
teachers: resolvedUsers
.filter((groupUser: ResolvedGroupUser) => groupUser.role.name === RoleName.TEACHER)
.map((groupUser: ResolvedGroupUser) => groupUser.user.lastName),
studentCount: resolvedUsers.filter((groupUser: ResolvedGroupUser) => groupUser.role.name === RoleName.STUDENT)
.length,
});

return mapped;
Expand All @@ -36,6 +38,7 @@ export class GroupUcMapper {
teachers: teachers.map((user: UserDO) => user.lastName),
schoolYear: schoolYear?.name,
isUpgradable,
studentCount: clazz.userIds ? clazz.userIds.length : 0,
});

return mapped;
Expand Down

0 comments on commit 4f594ed

Please sign in to comment.