Skip to content

Commit

Permalink
Update filter query on all pages
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis Rico <sferadev@gmail.com>
  • Loading branch information
SferaDev committed Feb 16, 2022
1 parent cd51146 commit 1fc0ba9
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/data/Dhis2RelationshipTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,18 @@ async function getConstraintForTypeTei(
} as const;

const results = await promiseMap(_.chunk(query.ou, 250), async ouChunk => {
const filterQuery =
query.ouMode === "SELECTED" || query.ouMode === "CHILDREN" || query.ouMode === "DESCENDANTS"
? { ...query, ou: ouChunk }
: query;

const { trackedEntityInstances: firstPage, pager } = await api.trackedEntityInstances
.get(
query.ouMode === "SELECTED" || query.ouMode === "CHILDREN" || query.ouMode === "DESCENDANTS"
? { ...query, ou: ouChunk }
: query
)
.get(filterQuery)
.getData();

const pages = _.range(2, pager.pageCount + 1);
const otherPages = await promiseMap(pages, async page => {
const { trackedEntityInstances } = await api.trackedEntityInstances.get({ ...query, page }).getData();
const { trackedEntityInstances } = await api.trackedEntityInstances.get({ ...filterQuery, page }).getData();
return trackedEntityInstances;
});

Expand Down

0 comments on commit 1fc0ba9

Please sign in to comment.