From 4cc5b30e45e675f0f998bd11db8ec3b789db3666 Mon Sep 17 00:00:00 2001 From: martinkrulltott Date: Tue, 7 Nov 2023 16:03:59 +0100 Subject: [PATCH] feat: add TE to the analytics constructor --- src/api/analytics/Analytics.js | 15 ++++++++++- .../AnalyticsRequestPropertiesMixin.js | 2 ++ src/api/analytics/AnalyticsTrackedEntities.js | 25 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/api/analytics/AnalyticsTrackedEntities.js diff --git a/src/api/analytics/Analytics.js b/src/api/analytics/Analytics.js index d08872524..0e0ddba2f 100644 --- a/src/api/analytics/Analytics.js +++ b/src/api/analytics/Analytics.js @@ -6,12 +6,15 @@ import AnalyticsEnrollments from './AnalyticsEnrollments.js' import AnalyticsEvents from './AnalyticsEvents.js' import AnalyticsRequest from './AnalyticsRequest.js' import AnalyticsResponse from './AnalyticsResponse.js' +import AnalyticsTrackedEntities from './AnalyticsTrackedEntities.js' /** * @description * Analytics class used to request analytics data from Web API. * * @requires analytics.AnalyticsAggregate + * @requires analytics.AnalyticsTrackedEntities + * @requires analytics.AnalyticsEnrollments * @requires analytics.AnalyticsEvents * @requires analytics.AnalyticsRequest * @requires analytics.AnalyticsResponse @@ -31,13 +34,22 @@ import AnalyticsResponse from './AnalyticsResponse.js' class Analytics { /** * @param {!module:analytics.AnalyticsAggregate} analyticsAggregate The AnalyticsAggregate instance + * @param {!module:analytics.AnalyticsTrackedEntities} analyticsTrackedEntities The AnalyticsTrackedEntities instance * @param {!module:analytics.AnalyticsEnrollments} analyticsEnrollments The AnalyticsEnrollments instance * @param {!module:analytics.AnalyticsEvents} analyticsEvents The AnalyticsEvents instance * @param {!module:analytics.AnalyticsRequest} analyticsRequest The AnalyticsRequest class * @param {!module:analytics.AnalyticsResponse} analyticsResponse The AnalyticsResponse class */ - constructor({ aggregate, enrollments, events, request, response }) { + constructor({ + aggregate, + trackedEntities, + enrollments, + events, + request, + response, + }) { this.aggregate = aggregate + this.trackedEntities = trackedEntities this.enrollments = enrollments this.events = events this.request = request @@ -60,6 +72,7 @@ class Analytics { if (!Analytics.getAnalytics.analytics) { Analytics.getAnalytics.analytics = new Analytics({ aggregate: new AnalyticsAggregate(dataEngine), + trackedEntities: new AnalyticsTrackedEntities(dataEngine), enrollments: new AnalyticsEnrollments(dataEngine), events: new AnalyticsEvents(dataEngine), request: AnalyticsRequest, diff --git a/src/api/analytics/AnalyticsRequestPropertiesMixin.js b/src/api/analytics/AnalyticsRequestPropertiesMixin.js index 6dd0f8cec..a2f7a299a 100644 --- a/src/api/analytics/AnalyticsRequestPropertiesMixin.js +++ b/src/api/analytics/AnalyticsRequestPropertiesMixin.js @@ -514,6 +514,8 @@ const AnalyticsRequestPropertiesMixin = (base) => return new AnalyticsRequest(this) } + // TODO: add withTrackedEntity + /** * Sets the program for the request. * It appends the program id to the request's path. diff --git a/src/api/analytics/AnalyticsTrackedEntities.js b/src/api/analytics/AnalyticsTrackedEntities.js new file mode 100644 index 000000000..3756be0e8 --- /dev/null +++ b/src/api/analytics/AnalyticsTrackedEntities.js @@ -0,0 +1,25 @@ +import AnalyticsBase from './AnalyticsBase.js' + +/** + * @extends module:analytics.AnalyticsBase + * + * @description + * Analytics tracked entities class used to request analytics tracked entities data from Web API. + * + * @memberof module:analytics + */ +class AnalyticsTrackedEntities extends AnalyticsBase { + /** + * @param {!AnalyticsRequest} req Request object + * + * @returns {Promise} Promise that resolves with the analytics query data from the api. + * + * @example + // TODO: provide working example + */ + getQuery(req) { + return this.fetch(req.withPath('trackedEntities/query')) + } +} + +export default AnalyticsTrackedEntities