summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/cycle_analytics/cycle_analytics_service.js
blob: f496c38208da855874b0a2b9e5af4fc3bced9fa9 (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
import Vue from 'vue';
import VueResource from 'vue-resource';

Vue.use(VueResource);

export default class CycleAnalyticsService {
  constructor(options) {
    this.requestPath = options.requestPath;
    this.cycleAnalytics = Vue.resource(this.requestPath);
  }

  fetchCycleAnalyticsData(options = { startDate: 30 }) {
    return this.cycleAnalytics.get({ cycle_analytics: { start_date: options.startDate } });
  }

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

    return Vue.http.get(`${this.requestPath}/events/${stage.name}.json`, {
      params: {
        cycle_analytics: {
          start_date: startDate,
        },
      },
    });
  }
}