Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions apps/backend/src/quiz/quiz.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class QuizService {
}

async deleteQuizSet(quizSetId: number) {
const quiz = await this.findQuizSet(quizSetId);
const quizSet = await this.findQuizSet(quizSetId);

await this.quizSetRepository.delete({ id: quizSetId });
}
Expand All @@ -80,10 +80,6 @@ export class QuizService {
async searchQuizSet(searchQuery: SearchQuizSetRequestDTO) {
const { name, page, size } = searchQuery;

if (!name) {
return this.findDefaultQuizSet(page, size);
}

const [quizSets, count] = await Promise.all([
this.quizSetRepository.searchByName(name, page, size),
this.quizSetRepository.countByName(name),
Expand All @@ -93,12 +89,4 @@ export class QuizService {
return { quizSetDetails, total: count, currentPage: page };
}

private async findDefaultQuizSet(page: number, size: number) {
const [quizSets, count] = await Promise.all([
this.quizSetRepository.findByRecommend(page, size),
this.quizSetRepository.countByRecommend(),
]);
const quizSetDetails = quizSets.map(QuizSetDetails.from);
return { quizSetDetails, total: count, currentPage: page };
}
}
15 changes: 1 addition & 14 deletions apps/backend/src/quiz/repository/quiz-set.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class QuizSetRepository extends Repository<QuizSet> {
searchByName(name: string, page: number, pageSize: number) {
return this.find({
where: {name: ILike(`${name}%`)},
order: {createAt: 'desc'},
order: {recommended: 'DESC', createAt: 'desc' },
skip: (page - 1) * pageSize,
take: pageSize,
});
Expand All @@ -20,17 +20,4 @@ export class QuizSetRepository extends Repository<QuizSet> {
countByName(name: string) {
return this.count({ where: { name: ILike(`${name}%`) } });
}

countByRecommend() {
return this.count({where: {recommended: true}});
}

findByRecommend(page: number, pageSize: number) {
return this.find({
where: {recommended: true},
order: {createAt: 'desc'},
skip: (page - 1) * pageSize,
take: pageSize,
})
}
}
Loading