diff --git a/src/shows/shows.controller.ts b/src/shows/shows.controller.ts index 86e4ca1..9d06964 100644 --- a/src/shows/shows.controller.ts +++ b/src/shows/shows.controller.ts @@ -88,9 +88,13 @@ export class ShowsController { async search(@Query() search: SearchDto) { try { const { query } = search; - const shows = await this.showsService.search(query); - if (shows.length > 0) { - return { status: 'Ok', show: shows, test: shows.length }; + const serviceResponse = await this.showsService.search(query); + if (serviceResponse.showCount > 0) { + return { + status: 'Ok', + shows: serviceResponse.shows, + showCount: serviceResponse.showCount + }; } else { throw new NotFoundException({ status: 'Error', diff --git a/src/shows/shows.service.ts b/src/shows/shows.service.ts index 5becbcd..b7e543b 100644 --- a/src/shows/shows.service.ts +++ b/src/shows/shows.service.ts @@ -37,7 +37,10 @@ export class ShowsService { const filter = { $or: [{ title: { $regex: regex } }, { description: { $regex: regex } }], }; - return this.showModel.find(filter); + return { + shows: await this.showModel.find(filter), + showCount: await this.showModel.find(filter).countDocuments() + }; } async update(id: string, dto: ShowDto): Promise {