BigW Consortium Gitlab

cycle_analytics_service.js 879 Bytes
Newer Older
Alfredo Sumaran committed
1
/* eslint-disable no-param-reassign */
2

3 4
const global = window.gl || (window.gl = {});
global.cycleAnalytics = global.cycleAnalytics || {};
5

6 7 8 9
class CycleAnalyticsService {
  constructor(options) {
    this.requestPath = options.requestPath;
  }
10

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

14 15 16 17 18 19
    return $.ajax({
      url: this.requestPath,
      method: 'GET',
      dataType: 'json',
      contentType: 'application/json',
      data: {
20
        cycle_analytics: {
21
          start_date: options.startDate,
Alfredo Sumaran committed
22
        },
23 24 25 26 27 28 29 30 31 32
      },
    });
  }

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

33
    return $.get(`${this.requestPath}/events/${stage.name}.json`, {
34 35 36 37
      cycle_analytics: {
        start_date: startDate,
      },
    });
Alfredo Sumaran committed
38
  }
39
}
40

41
global.cycleAnalytics.CycleAnalyticsService = CycleAnalyticsService;