diff --git a/src/app/features/reporting/data-aggregation.service.spec.ts b/src/app/features/reporting/data-aggregation.service.spec.ts index 78d104d02d..3f5096e93b 100644 --- a/src/app/features/reporting/data-aggregation.service.spec.ts +++ b/src/app/features/reporting/data-aggregation.service.spec.ts @@ -12,6 +12,8 @@ import { School } from "../../child-dev-project/schools/model/school"; import { ChildSchoolRelation } from "../../child-dev-project/children/model/childSchoolRelation"; import { centersUnique } from "../../child-dev-project/children/demo-data-generators/fixtures/centers"; import { genders } from "../../child-dev-project/children/model/genders"; +import { mockEntityMapper } from "../../core/entity/mock-entity-mapper-service"; +import { entityRegistry } from "../../core/entity/database-entity.decorator"; describe("DataAggregationService", () => { let service: DataAggregationService; @@ -661,4 +663,37 @@ describe("DataAggregationService", () => { }, ]); }); + + it("should handle subfields of filtered query anywhere in the reporting structure", async () => { + const c1 = new Child(); + c1.status = "1"; + + const entityMapper = mockEntityMapper([c1]); + const queryService = new QueryService( + entityMapper, + null, + null, + entityRegistry + ); + service = new DataAggregationService(queryService); + + const complexQuery: Aggregation = { + label: "!!", + query: "Child:toArray.status", + }; + const otherQuery: Aggregation = { + label: "other", + query: "School:toArray", + }; + + const result = await service.calculateReport([complexQuery, otherQuery]); + + expect(result).toEqual([ + { + header: { label: "!!", groupedBy: [], result: 1 }, + subRows: [], + }, + { header: { label: "other", groupedBy: [], result: 0 }, subRows: [] }, + ]); + }); }); diff --git a/src/app/features/reporting/data-aggregation.service.ts b/src/app/features/reporting/data-aggregation.service.ts index 7a38cd0e11..cef6148815 100644 --- a/src/app/features/reporting/data-aggregation.service.ts +++ b/src/app/features/reporting/data-aggregation.service.ts @@ -26,7 +26,7 @@ export class DataAggregationService { ): Promise { this.fromDate = from; this.toDate = to; - const fullQuery = aggregations.map((a) => this.concatQueries(a)).join(""); + const fullQuery = aggregations.map((a) => this.concatQueries(a)).join("|"); await this.queryService.cacheRequiredData( fullQuery, this.fromDate,