Skip to content

Commit

Permalink
fix: return count with tree_associated filter applied
Browse files Browse the repository at this point in the history
  • Loading branch information
ZavenArra committed Feb 4, 2022
1 parent 604172b commit 865fb74
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 2 additions & 0 deletions server/__tests__/integration/capture/capture.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,14 @@ describe('/captures', () => {
it('should get only captures with tree associated', async () => {
const result = await request(app).get(`/captures?tree_associated=true`).expect(200);
expect(result.body.captures.length).to.eql(1);
expect(result.body.count).to.eql(1);
expect(result.body.captures[0].id).to.eql("c02a5ae6-3727-11ec-8d3d-0242ac130003");
});

it('should get only captures without tree associated', async () => {
const result = await request(app).get(`/captures?tree_associated=false`).expect(200);
expect(result.body.captures.length).to.eql(1);
expect(result.body.count).to.eql(1);
expect(result.body.captures[0].id).to.eql("d2c69205-b13f-4ab6-bb5e-33dc504fa0c2");
});

Expand Down
7 changes: 3 additions & 4 deletions server/infra/repositories/CaptureRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ class CaptureRepository extends BaseRepository {
delete filterCriteria.tree_associated;
}

const countWhere = where.clone();

const captures = await where.where({ ...filterCriteria})
.select('*')
.from('capture')
.orderBy('created_at', 'desc')
.limit(Number(options.limit))
.offset(Number(options.offset));

const { count } = await this._session
.getDB()
.where({ ...filterCriteria })
.whereNot({ status: 'deleted' })
const { count } = await countWhere
.count('*')
.from('capture')
.first();
Expand Down

0 comments on commit 865fb74

Please sign in to comment.