Skip to content

Commit

Permalink
Merge pull request #51 from DevKor-github/feature/course
Browse files Browse the repository at this point in the history
Feature/course
  • Loading branch information
Devheun authored Jul 25, 2024
2 parents 518dc67 + c8f3141 commit dc190ca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
28 changes: 14 additions & 14 deletions src/course/course.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ export class CourseService {
id: MoreThan(searchCourseCodeDto.cursorId),
},
order: { id: 'ASC' },
take: 5,
take: 21,
relations: ['courseDetails'],
});
} else {
courses = await this.courseRepository.find({
where: { courseCode: Like(`${searchCourseCodeDto.courseCode}%`) },
order: { id: 'ASC' },
take: 5,
take: 21,
relations: ['courseDetails'],
});
}
Expand Down Expand Up @@ -118,7 +118,7 @@ export class CourseService {
.andWhere('course.major = :major', { major })
.andWhere('course.category = :category', { category: 'Major' })
.orderBy('course.id', 'ASC')
.limit(5);
.limit(21);

if (searchCourseNameDto.cursorId) {
queryBuilder.andWhere('course.id > :cursorId', {
Expand Down Expand Up @@ -152,7 +152,7 @@ export class CourseService {
id: MoreThan(searchProfessorNameDto.cursorId),
},
order: { id: 'ASC' },
take: 5,
take: 21,
relations: ['courseDetails'],
});
} else {
Expand All @@ -163,7 +163,7 @@ export class CourseService {
category: 'Major',
},
order: { id: 'ASC' },
take: 5,
take: 21,
relations: ['courseDetails'],
});
}
Expand All @@ -190,7 +190,7 @@ export class CourseService {
category: 'General Studies',
})
.orderBy('course.id', 'ASC')
.limit(5);
.limit(21);

if (searchCourseNameDto.cursorId) {
queryBuilder.andWhere('course.id > :cursorId', {
Expand Down Expand Up @@ -219,7 +219,7 @@ export class CourseService {
id: MoreThan(searchProfessorNameDto.cursorId),
},
order: { id: 'ASC' },
take: 5,
take: 21,
relations: ['courseDetails'],
});
} else {
Expand All @@ -229,7 +229,7 @@ export class CourseService {
category: 'General Studies',
},
order: { id: 'ASC' },
take: 5,
take: 21,
relations: ['courseDetails'],
});
}
Expand All @@ -244,14 +244,14 @@ export class CourseService {
courses = await this.courseRepository.find({
where: { category: 'General Studies', id: MoreThan(cursorId) },
order: { id: 'ASC' },
take: 5,
take: 21,
relations: ['courseDetails'],
});
} else {
courses = await this.courseRepository.find({
where: { category: 'General Studies' },
order: { id: 'ASC' },
take: 5,
take: 21,
relations: ['courseDetails'],
});
}
Expand All @@ -270,14 +270,14 @@ export class CourseService {
courses = await this.courseRepository.find({
where: { category: 'Major', major: major, id: MoreThan(cursorId) },
order: { id: 'ASC' },
take: 5,
take: 21,
relations: ['courseDetails'],
});
} else {
courses = await this.courseRepository.find({
where: { category: 'Major', major: major },
order: { id: 'ASC' },
take: 5,
take: 21,
relations: ['courseDetails'],
});
}
Expand All @@ -300,14 +300,14 @@ export class CourseService {
id: MoreThan(cursorId),
},
order: { id: 'ASC' },
take: 5,
take: 21,
relations: ['courseDetails'],
});
} else {
courses = await this.courseRepository.find({
where: { category: 'Academic Foundations', college: college },
order: { id: 'ASC' },
take: 5,
take: 21,
relations: ['courseDetails'],
});
}
Expand Down
8 changes: 3 additions & 5 deletions src/course/dto/paginated-courses.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ export class PaginatedCoursesDto {
data: CommonCourseResponseDto[];

constructor(commonCourseResponseDto: CommonCourseResponseDto[]) {
const hasNextPage = commonCourseResponseDto.length === 5;
const nextCursorId = hasNextPage
? commonCourseResponseDto[3].id
: null;
const hasNextPage = commonCourseResponseDto.length === 21;
const nextCursorId = hasNextPage ? commonCourseResponseDto[19].id : null;

this.hasNextPage = hasNextPage;
this.nextCursorId = nextCursorId;
this.data = hasNextPage
? commonCourseResponseDto.slice(0, 4)
? commonCourseResponseDto.slice(0, 20)
: commonCourseResponseDto;
}
}

0 comments on commit dc190ca

Please sign in to comment.