Skip to content

Commit

Permalink
N21-1318 adjust classInfoResponse for new class page (#4496)
Browse files Browse the repository at this point in the history
* add studentCount
* add classFilter
  • Loading branch information
IgorCapCoder authored Nov 5, 2023
1 parent a3fd43f commit 84ececb
Show file tree
Hide file tree
Showing 17 changed files with 357 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
import { ObjectId } from 'bson';
import { GroupEntity, GroupEntityTypes } from '../../entity';
import { ClassRootType } from '../../uc/dto/class-root-type';
import { ClassInfoSearchListResponse, ClassSortBy } from '../dto';
import { ClassInfoSearchListResponse } from '../dto';
import { ClassSortBy } from '../dto/interface';

const baseRouteName = '/groups';

Expand Down Expand Up @@ -120,6 +121,7 @@ describe('Group (API)', () => {
name: group.name,
externalSourceName: system.displayName,
teachers: [adminUser.lastName],
studentCount: 0,
},
{
id: clazz.id,
Expand All @@ -128,6 +130,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
@@ -0,0 +1,4 @@
export enum ClassSortBy {
NAME = 'name',
EXTERNAL_SOURCE_NAME = 'externalSourceName',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './class-sort-by.enum';
export * from './school-year-query-type.enum';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum SchoolYearQueryType {
NEXT_YEAR = 'nextYear',
CURRENT_YEAR = 'currentYear',
PREVIOUS_YEARS = 'previousYears',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsEnum, IsOptional } from 'class-validator';
import { SchoolYearQueryType } from '../interface';

export class ClassFilterParams {
@IsOptional()
@IsEnum(SchoolYearQueryType)
@ApiPropertyOptional({ enum: SchoolYearQueryType, enumName: 'SchoolYearQueryType' })
type?: SchoolYearQueryType;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { ApiPropertyOptional } from '@nestjs/swagger';
import { SortingParams } from '@shared/controller';
import { IsEnum, IsOptional } from 'class-validator';

export enum ClassSortBy {
NAME = 'name',
EXTERNAL_SOURCE_NAME = 'externalSourceName',
}
import { ClassSortBy } from '../interface';

export class ClassSortParams extends SortingParams<ClassSortBy> {
@IsOptional()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './class-sort-params';
export * from './group-id-params';
export * from './class-filter-params';
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;
}
}
4 changes: 3 additions & 1 deletion apps/server/src/modules/group/controller/group.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Page } from '@shared/domain';
import { ErrorResponse } from '@src/core/error/dto';
import { GroupUc } from '../uc';
import { ClassInfoDto, ResolvedGroupDto } from '../uc/dto';
import { ClassInfoSearchListResponse, ClassSortParams, GroupIdParams, GroupResponse } from './dto';
import { ClassInfoSearchListResponse, ClassSortParams, GroupIdParams, GroupResponse, ClassFilterParams } from './dto';
import { GroupResponseMapper } from './mapper';

@ApiTags('Group')
Expand All @@ -23,11 +23,13 @@ export class GroupController {
public async findClasses(
@Query() pagination: PaginationParams,
@Query() sortingQuery: ClassSortParams,
@Query() filterParams: ClassFilterParams,
@CurrentUser() currentUser: ICurrentUser
): Promise<ClassInfoSearchListResponse> {
const board: Page<ClassInfoDto> = await this.groupUc.findAllClasses(
currentUser.userId,
currentUser.schoolId,
filterParams.type,
pagination.skip,
pagination.limit,
sortingQuery.sortBy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class GroupResponseMapper {
teachers: classInfo.teacherNames,
schoolYear: classInfo.schoolYear,
isUpgradable: classInfo.isUpgradable,
studentCount: classInfo.studentCount,
});

return mapped;
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/modules/group/loggable/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './unknown-query-type-loggable-exception';
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { UnknownQueryTypeLoggableException } from './unknown-query-type-loggable-exception';

describe('UnknownQueryTypeLoggableException', () => {
describe('getLogMessage', () => {
const setup = () => {
const unknownQueryType = 'unknwon';

const exception = new UnknownQueryTypeLoggableException(unknownQueryType);

return {
exception,
unknownQueryType,
};
};

it('should log the correct message', () => {
const { exception, unknownQueryType } = setup();

const result = exception.getLogMessage();

expect(result).toEqual({
type: 'INTERNAL_SERVER_ERROR',
stack: expect.any(String),
message: 'Unable to process unknown query type for class years.',
data: {
unknownQueryType,
},
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ErrorLogMessage, Loggable, LogMessage, ValidationErrorLogMessage } from '@src/core/logger';
import { InternalServerErrorException } from '@nestjs/common';

export class UnknownQueryTypeLoggableException extends InternalServerErrorException implements Loggable {
constructor(private readonly unknownQueryType: string) {
super();
}

getLogMessage(): LogMessage | ErrorLogMessage | ValidationErrorLogMessage {
return {
type: 'INTERNAL_SERVER_ERROR',
stack: this.stack,
message: 'Unable to process unknown query type for class years.',
data: {
unknownQueryType: this.unknownQueryType,
},
};
}
}
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.teacherNames = props.teacherNames;
this.schoolYear = props.schoolYear;
this.isUpgradable = props.isUpgradable;
this.studentCount = props.studentCount;
}
}
Loading

0 comments on commit 84ececb

Please sign in to comment.