diff --git a/Backend/src/app/frontend/frontend.controller.ts b/Backend/src/app/frontend/frontend.controller.ts index e0b5e50..b3ba4ef 100644 --- a/Backend/src/app/frontend/frontend.controller.ts +++ b/Backend/src/app/frontend/frontend.controller.ts @@ -77,12 +77,20 @@ export class FrontendController { type: 'number', example: 10, }) - @Get(`:filter(${filters.join('|')})/:limit(\\d+)`) + @ApiParam({ + name: 'step', + type: 'number', + example: 0, + description: + 'if 0 returns the first values, if 1 returns the second values, etc... . When no data is found it simply return an empty string', + }) + @Get(`:filter(${filters.join('|')})/:limit(\\d+)/:step(\\d+)`) getValuesLimit( @Param('filter', FiltersValidator) filter: FiltersAvailable, @Param('limit', PositiveNumberValidator) limit: number, + @Param('step', PositiveNumberValidator) step: number, ) { - return this.databaseService.getData(filter, limit); + return this.databaseService.getData(filter, limit, step); } @ApiParam({ diff --git a/Backend/src/database/database.service.ts b/Backend/src/database/database.service.ts index 4be9756..559fe65 100644 --- a/Backend/src/database/database.service.ts +++ b/Backend/src/database/database.service.ts @@ -74,25 +74,31 @@ export class DatabaseService { getData( filter: FiltersAvailable, limit: number = undefined, + step: number = undefined, ): Promise { - const res = this.DB.collection('cameras').aggregate([ - { - $addFields: { - intrusionDetection: { - $cond: { - if: { - $ifNull: ['$intrusionDetection', false], + const res = this.DB.collection('cameras') + .aggregate([ + { + $addFields: { + intrusionDetection: { + $cond: { + if: { + $ifNull: ['$intrusionDetection', false], + }, + then: true, + else: false, }, - then: true, - else: false, }, }, }, - }, - ]); - if (limit != undefined) - return res.limit(limit).match(this.getFilter(filter)).toArray(); - else return res.match(this.getFilter(filter)).toArray(); + ]) + .match(this.getFilter(filter)); + if (limit != undefined && step != undefined) + return res + .skip(limit * step) + .limit(limit) + .toArray(); + else return res.toArray(); } aggregateCamera(filter?: FiltersAvailable): Promise {