diff --git a/BE/src/postings/postings.controller.ts b/BE/src/postings/postings.controller.ts index ffc456a..1de0d8c 100644 --- a/BE/src/postings/postings.controller.ts +++ b/BE/src/postings/postings.controller.ts @@ -117,7 +117,7 @@ export class PostingsController { @ApiOkResponse({ schema: { example: searchByWord_OK } }) async searchByKeyWord( @Query('keyword', new DefaultValuePipe('')) keyword: string - ): Promise { + ) { return this.postingsService.findAllBytitle(keyword); } diff --git a/BE/src/postings/postings.service.ts b/BE/src/postings/postings.service.ts index 1194155..94c14a2 100644 --- a/BE/src/postings/postings.service.ts +++ b/BE/src/postings/postings.service.ts @@ -88,14 +88,7 @@ export class PostingsService { async findAllBytitle(keyword: string) { const titles = await this.postingsRepository.findAllByTitle(keyword); - - return [ - ...new Set( - titles - .filter((e) => e.reports.length <= BLOCKING_LIMIT) - .map((e) => e.title) - ), - ]; + return titles.map((e) => e.title); } async findAllByWriter(userId: string) { diff --git a/BE/src/postings/repositories/postings.repository.ts b/BE/src/postings/repositories/postings.repository.ts index 5df5da5..dd8127c 100644 --- a/BE/src/postings/repositories/postings.repository.ts +++ b/BE/src/postings/repositories/postings.repository.ts @@ -1,7 +1,7 @@ -import { POSTINGS_REPOSITORY } from '../postings.constants'; +import { BLOCKING_LIMIT, POSTINGS_REPOSITORY } from '../postings.constants'; import { Posting } from '../entities/posting.entity'; import { Inject, Injectable } from '@nestjs/common'; -import { Like, Repository } from 'typeorm'; +import { Repository } from 'typeorm'; import { Budget, Headcount, @@ -51,13 +51,15 @@ export class PostingsRepository { ) { const qb = this.postingsRepository .createQueryBuilder('p') + .leftJoinAndSelect('p.writer', 'u') + .where('p.title LIKE :keyword', { keyword: `%${keyword}%` }) .leftJoin('p.likeds', 'l', 'l.isDeleted = :isDeleted', { isDeleted: false, }) - .leftJoinAndSelect('p.writer', 'u') - .where('p.title LIKE :keyword', { keyword: `%${keyword}%` }) - .groupBy('p.id') - .addSelect('COUNT(l.posting)', 'likeds'); + .addSelect('COUNT(l.posting)', 'likeds') + .leftJoin('p.reports', 'r') + .having('COUNT(r.posting) <= :BLOCKING_LIMIT', { BLOCKING_LIMIT }) + .groupBy('p.id'); if (budget) { qb.where('p.budget = :budget', { budget }); @@ -138,16 +140,20 @@ export class PostingsRepository { } return qb - .skip((offset - 1) * limit) - .take(limit) + .offset((offset - 1) * limit) + .limit(limit) .getRawMany(); } async findAllByTitle(keyword: string) { - return this.postingsRepository.find({ - where: { title: Like(`${keyword}%`) }, - select: ['title'], - }); + return this.postingsRepository + .createQueryBuilder('p') + .select('DISTINCT p.title', 'title') + .where('p.title LIKE :keyword', { keyword: `%${keyword}%` }) + .leftJoin('p.reports', 'r') + .groupBy('p.id') + .having('COUNT(r.posting) <= :BLOCKING_LIMIT', { BLOCKING_LIMIT }) + .getRawMany(); } async findAllByWriter(userId: string) {