Skip to content

Commit

Permalink
Merge pull request #14 from unicam-complex-system/glydric
Browse files Browse the repository at this point in the history
Added api for step counter
  • Loading branch information
nabil-nablotech authored Jan 23, 2024
2 parents 5219121 + 9517c8d commit dc5567b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
12 changes: 10 additions & 2 deletions Backend/src/app/frontend/frontend.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
34 changes: 20 additions & 14 deletions Backend/src/database/database.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,31 @@ export class DatabaseService {
getData(
filter: FiltersAvailable,
limit: number = undefined,
step: number = undefined,
): Promise<Document[]> {
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<Document[]> {
Expand Down

0 comments on commit dc5567b

Please sign in to comment.