Skip to content

Commit

Permalink
fix: exports can still be created if it includes deleted children
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSlimvReal authored Mar 3, 2022
1 parent 3f9003b commit 78ed5ac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
16 changes: 16 additions & 0 deletions src/app/features/reporting/query.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,22 @@ describe("QueryService", () => {
expect(result).toEqual(["custom-string", "custom-string"]);
});

it("should omit participants which can be found anymore (e.g. deleted participants)", async () => {
const maleChild = await createChild("M");
const femaleChild = await createChild("F");
await createNote(new Date(), [
{ child: maleChild, status: presentAttendanceStatus },
{ child: femaleChild, status: presentAttendanceStatus },
]);
await entityMapper.remove(femaleChild);

const result = await service.queryData(
`${EventNote.ENTITY_TYPE}:toArray:getIds(children):toEntities(${Child.ENTITY_TYPE}).gender`
);

expect(result).toEqual([maleChild.gender]);
});

async function createChild(
gender: "M" | "F" = "F",
religion?: "muslim" | "christian"
Expand Down
12 changes: 7 additions & 5 deletions src/app/features/reporting/query.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class QueryService {
* @returns a list where every string has the prefix
*/
private addPrefix(ids: string[], prefix: string): string[] {
return ids.map((id) => (id.startsWith(prefix) ? id : prefix + ":" + id));
return ids.map((id) => Entity.createPrefixedId(prefix, id));
}

/**
Expand Down Expand Up @@ -171,10 +171,12 @@ export class QueryService {
ids = this.addPrefix(ids, entityPrefix);
}

return ids.map((id) => {
const prefix = id.split(":")[0];
return this.entities[prefix][id];
});
return ids
.map((id) => {
const prefix = id.split(":")[0];
return this.entities[prefix][id];
})
.filter((entity) => !!entity);
}

/**
Expand Down

0 comments on commit 78ed5ac

Please sign in to comment.