Shows/service: get search document count from db
This commit is contained in:
parent
7a29130234
commit
f219011784
2 changed files with 11 additions and 4 deletions
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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<any> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue