diff --git a/Backend/src/app/frontend/frontend.controller.ts b/Backend/src/app/frontend/frontend.controller.ts index 24f6748..e0b5e50 100644 --- a/Backend/src/app/frontend/frontend.controller.ts +++ b/Backend/src/app/frontend/frontend.controller.ts @@ -71,6 +71,20 @@ export class FrontendController { return this.databaseService.getData(filter); } + @ApiParam(filterParams) + @ApiParam({ + name: 'limit', + type: 'number', + example: 10, + }) + @Get(`:filter(${filters.join('|')})/:limit(\\d+)`) + getValuesLimit( + @Param('filter', FiltersValidator) filter: FiltersAvailable, + @Param('limit', PositiveNumberValidator) limit: number, + ) { + return this.databaseService.getData(filter, limit); + } + @ApiParam({ name: 'id', type: 'number', diff --git a/Backend/src/database/database.service.ts b/Backend/src/database/database.service.ts index 78a7cf2..4be9756 100644 --- a/Backend/src/database/database.service.ts +++ b/Backend/src/database/database.service.ts @@ -71,25 +71,28 @@ export class DatabaseService { return await col.insertOne(data); } - getData(filter?: FiltersAvailable): Promise { - return this.DB.collection('cameras') - .aggregate([ - { - $addFields: { - intrusionDetection: { - $cond: { - if: { - $ifNull: ['$intrusionDetection', false], - }, - then: true, - else: false, + getData( + filter: FiltersAvailable, + limit: number = undefined, + ): Promise { + const res = this.DB.collection('cameras').aggregate([ + { + $addFields: { + intrusionDetection: { + $cond: { + if: { + $ifNull: ['$intrusionDetection', false], }, + then: true, + else: false, }, }, }, - ]) - .match(this.getFilter(filter)) - .toArray(); + }, + ]); + if (limit != undefined) + return res.limit(limit).match(this.getFilter(filter)).toArray(); + else return res.match(this.getFilter(filter)).toArray(); } aggregateCamera(filter?: FiltersAvailable): Promise {