summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/cycle_analytics/cycle_analytics_service.js
blob: 9f74b14c4b970f896bdbe1a8a871874fc290605a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* eslint-disable no-param-reassign */
((global) => {
  global.cycleAnalytics = global.cycleAnalytics || {};

  class CycleAnalyticsService {
    constructor(options) {
      this.requestPath = options.requestPath;
    }

    fetchCycleAnalyticsData(options) {
      options = options || { startDate: 30 };

      return $.ajax({
        url: this.requestPath,
        method: 'GET',
        dataType: 'json',
        contentType: 'application/json',
        data: {
          cycle_analytics: {
            start_date: options.startDate,
          },
        },
      });
    }

    fetchStageData(options) {
      const {
        stage,
        startDate,
      } = options;

      return $.get(`${this.requestPath}/events/${stage.title.toLowerCase()}.json`, {
        cycle_analytics: {
          start_date: startDate,
        },
      });
    }
  }

  global.cycleAnalytics.CycleAnalyticsService = CycleAnalyticsService;
})(window.gl || (window.gl = {}));