diff --git a/src/app/features/reporting/query.service.spec.ts b/src/app/features/reporting/query.service.spec.ts index e8c83b4911..4abdffee05 100644 --- a/src/app/features/reporting/query.service.spec.ts +++ b/src/app/features/reporting/query.service.spec.ts @@ -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" diff --git a/src/app/features/reporting/query.service.ts b/src/app/features/reporting/query.service.ts index 8c16e46d24..e925a32e08 100644 --- a/src/app/features/reporting/query.service.ts +++ b/src/app/features/reporting/query.service.ts @@ -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)); } /** @@ -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); } /**