summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/cycle_analytics/cycle_analytics_service.js
blob: 681d6eef565770152c1c17ad065bdf5b60cc9cef (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 */

const global = window.gl || (window.gl = {});
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;