Skip to content

Commit

Permalink
fix: report cache correctly detects required entities from multiple q…
Browse files Browse the repository at this point in the history
…ueries (#1877)

Co-authored-by: Simon <simon@aam-digital.com>
  • Loading branch information
sleidig and TheSlimvReal authored May 30, 2023
1 parent 555151b commit 5fdfb0f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions src/app/features/reporting/data-aggregation.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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: [] },
]);
});
});
2 changes: 1 addition & 1 deletion src/app/features/reporting/data-aggregation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class DataAggregationService {
): Promise<ReportRow[]> {
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,
Expand Down

0 comments on commit 5fdfb0f

Please sign in to comment.