Skip to content

Commit

Permalink
Bucket age ranges in cases list #2670
Browse files Browse the repository at this point in the history
  • Loading branch information
iamleeg committed Apr 25, 2022
1 parent b38eafc commit 8a2165d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 6 additions & 5 deletions data-serving/data-service/src/controllers/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ const dtoFromCase = async (storedCase: LeanDocument<CaseDocument>) => {
}
}
}
delete dto.restrictedNotes;

return dto;
}

Expand Down Expand Up @@ -334,9 +336,8 @@ export class CasesController {
countQuery,
]);

docs.forEach((aDoc: LeanDocument<CaseDocument>) => {
delete aDoc.restrictedNotes;
});
const dtos = await Promise.all(docs.map(dtoFromCase));

logger.info('got results');
// total is actually stored in a count index in mongo, so the query is fast.
// however to maintain existing behaviour, only return the count limit
Expand All @@ -345,7 +346,7 @@ export class CasesController {
// indicating that there is more to fetch on the next page.
if (total > limit * page) {
res.json({
cases: docs,
cases: dtos,
nextPage: page + 1,
total: reportedTotal,
});
Expand All @@ -354,7 +355,7 @@ export class CasesController {
}
// If we fetched all available data, just return it.
logger.info('Got one page of results');
res.json({ cases: docs, total: reportedTotal });
res.json({ cases: dtos, total: reportedTotal });
} catch (e) {
if (e instanceof ParsingError) {
logger.error(`Parsing error ${e.message}`);
Expand Down
12 changes: 12 additions & 0 deletions data-serving/data-service/test/controllers/case.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,18 @@ describe('GET', () => {
.expect(200, /got it at work/)
.expect('Content-Type', /json/);
});
it('should use age buckets in results', async () => {
const c = new Case(minimalCase);
const aBucket = await AgeBucket.findOne({});
c.demographics.ageBuckets = [aBucket!._id];
await c.save();
const res = await request(app)
.get(`/api/cases?page=1&limit=10`)
.expect(200)
.expect('Content-Type', /json/);
expect(res.body.cases[0].demographics.ageRange.start).toEqual(aBucket!.start);
expect(res.body.cases[0].demographics.ageRange.end).toEqual(aBucket!.end);
});
it('should ignore the restricted collection', async () => {
const r = new RestrictedCase(minimalCase);
await r.save();
Expand Down

0 comments on commit 8a2165d

Please sign in to comment.