Skip to content

Commit

Permalink
Exclude deleted entities from extended metadata about entity list
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-white committed Dec 12, 2023
1 parent a00c396 commit 1415c93
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/model/query/datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ const _get = extender(Dataset)(Dataset.Extended)((fields, extend, options, publi
LEFT JOIN (
SELECT "datasetId", COUNT(1) "entities", MAX(COALESCE("updatedAt", "createdAt")) "lastEntity", COUNT(1) FILTER (WHERE conflict IS NOT NULL) "conflicts"
FROM entities e
WHERE "deletedAt" IS NULL
GROUP BY "datasetId"
) stats on stats."datasetId" = datasets.id`}
${(actorId == null) ? sql`` : sql`
Expand Down
32 changes: 32 additions & 0 deletions test/integration/api/datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,38 @@ describe('datasets and entities', () => {
});
}));

it('should exclude deleted entities', testService(async (service) => {
const asAlice = await service.login('alice');
await asAlice.post('/v1/projects/1/forms?publish=true')
.send(testData.forms.simpleEntity)
.set('Content-Type', 'application/xml')
.expect(200);
await asAlice.post('/v1/projects/1/datasets/people/entities')
.send({
uuid: '12345678-1234-4123-8234-123456789abc',
label: 'Johnny Doe'
})
.expect(200);
await asAlice.get('/v1/projects/1/datasets')
.set('X-Extended-Metadata', 'true')
.expect(200)
.then(({ body }) => {
body.length.should.equal(1);
body[0].entities.should.equal(1);
body[0].lastEntity.should.be.an.isoDate();
});
await asAlice.delete('/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789abc')
.expect(200);
await asAlice.get('/v1/projects/1/datasets')
.set('X-Extended-Metadata', 'true')
.expect(200)
.then(({ body }) => {
body.length.should.equal(1);
body[0].entities.should.equal(0);
should.not.exist(body[0].lastEntity);
});
}));

it('should return the correct count for multiple dataset', testService(async (service, container) => {
const asAlice = await service.login('alice');

Expand Down

0 comments on commit 1415c93

Please sign in to comment.