Description
PaginationService is declared as @Injectable() but has absolutely no methods. Both CoursesController and LessonsController call this.paginationService.findAll() and this.paginationService.findAllLessons() on it — these calls will throw TypeError: this.paginationService.findAll is not a function at runtime the moment either endpoint is hit.
There is also a misspelled duplicate: dto/paggination.dto.ts (double-g) which is completely empty and unused.
Proposed Actions
async paginate<T>(
repository: Repository<T>,
options: { page: number; limit: number },
): Promise<{
data: T[];
total: number;
page: number;
limit: number;
totalPages: number;
}> {
const [data, total] = await repository.findAndCount({
skip: (options.page - 1) * options.limit,
take: options.limit,
});
return {
data,
total,
page: options.page,
limit: options.limit,
totalPages: Math.ceil(total / options.limit),
};
}
Expected Outcome
PaginationService has a working paginate() method usable by any controller
GET /courses and GET /lessons support ?page=1&limit=10 query params
- No
TypeError is thrown when pagination endpoints are called
- The empty misspelled DTO file is gone
Complexity
Medium
Description
PaginationServiceis declared as@Injectable()but has absolutely no methods. BothCoursesControllerandLessonsControllercallthis.paginationService.findAll()andthis.paginationService.findAllLessons()on it — these calls will throwTypeError: this.paginationService.findAll is not a functionat runtime the moment either endpoint is hit.There is also a misspelled duplicate:
dto/paggination.dto.ts(double-g) which is completely empty and unused.Proposed Actions
PaginationServiceincommon/services/pagination.service.tswith apaginate<T>(repository, options)method:PaginationDtoincommon/dto/pagination.dto.tswith:@IsOptional() @IsInt() @Min(1) @Type(() => Number) page?: number = 1@IsOptional() @IsInt() @Min(1) @Max(100) @Type(() => Number) limit?: number = 10GET /courseshandler inCoursesController(see Issue Implement Role-Based Access Control (RBAC) for Students and Tutors #9) and add@Query()pagination params to the existingfindAll()insteadGET /lessonshandler inLessonsController(see Issue Implement JWT Token Generation for Tutor #10) and add@Query()pagination params to the appropriate handler insteaddto/paggination.dto.tsExpected Outcome
PaginationServicehas a workingpaginate()method usable by any controllerGET /coursesandGET /lessonssupport?page=1&limit=10query paramsTypeErroris thrown when pagination endpoints are calledComplexity
Medium