Skip to content

Commit

Permalink
feat: add TE to the analytics constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkrulltott committed Nov 7, 2023
1 parent 4a8a54a commit 4cc5b30
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/api/analytics/Analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/api/analytics/AnalyticsRequestPropertiesMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 25 additions & 0 deletions src/api/analytics/AnalyticsTrackedEntities.js
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4cc5b30

Please sign in to comment.