Shows/service: get search document count from db

This commit is contained in:
Toast 2025-02-02 18:29:48 +01:00
parent 7a29130234
commit f219011784
2 changed files with 11 additions and 4 deletions

View file

@ -88,9 +88,13 @@ export class ShowsController {
async search(@Query() search: SearchDto) { async search(@Query() search: SearchDto) {
try { try {
const { query } = search; const { query } = search;
const shows = await this.showsService.search(query); const serviceResponse = await this.showsService.search(query);
if (shows.length > 0) { if (serviceResponse.showCount > 0) {
return { status: 'Ok', show: shows, test: shows.length }; return {
status: 'Ok',
shows: serviceResponse.shows,
showCount: serviceResponse.showCount
};
} else { } else {
throw new NotFoundException({ throw new NotFoundException({
status: 'Error', status: 'Error',

View file

@ -37,7 +37,10 @@ export class ShowsService {
const filter = { const filter = {
$or: [{ title: { $regex: regex } }, { description: { $regex: regex } }], $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<any> { async update(id: string, dto: ShowDto): Promise<any> {