Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Glydric committed Jan 23, 2024
1 parent 9517c8d commit 52988fa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Backend/src/database/database.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('DatabaseService', () => {
});

it('should get aggregated data', async () => {
const aggregateData = await databaseService.aggregateCamera();
const aggregateData = await databaseService.aggregateCamera('all');

expect(aggregateData).not.toBeNull();
});
Expand Down
21 changes: 18 additions & 3 deletions Backend/src/database/database.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,24 @@ export class DatabaseService {
else return res.toArray();
}

aggregateCamera(filter?: FiltersAvailable): Promise<Document[]> {
aggregateCamera(filter: FiltersAvailable): Promise<Document[]> {
console.log(this.getFilter(filter));
return this.DB.collection('cameras')
.aggregate()
.aggregate([
{
$addFields: {
intrusionDetection: {
$cond: {
if: {
$ifNull: ['$intrusionDetection', false],
},
then: true,
else: false,
},
},
},
},
])
.match(this.getFilter(filter))
.group({
_id: '$cameraId',
Expand Down Expand Up @@ -149,7 +164,7 @@ export class DatabaseService {
});
}

private getFilter(filter?: FiltersAvailable) {
private getFilter(filter: FiltersAvailable) {
switch (filter) {
case 'intrusionDetection':
return {
Expand Down

0 comments on commit 52988fa

Please sign in to comment.