summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/groups/service/groups_service.js
blob: b79ba29146373652f5a3c509f778e40c4095fdea (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
import Vue from 'vue';
import '../../vue_shared/vue_resource_interceptor';

export default class GroupsService {
  constructor(endpoint) {
    this.groups = Vue.resource(endpoint);
  }

  getGroups(parentId, page, filterGroups, sort, archived) {
    const data = {};

    if (parentId) {
      data.parent_id = parentId;
    } else {
      // Do not send the following param for sub groups
      if (page) {
        data.page = page;
      }

      if (filterGroups) {
        data.filter = filterGroups;
      }

      if (sort) {
        data.sort = sort;
      }

      if (archived) {
        data.archived = archived;
      }
    }

    return this.groups.get(data);
  }

  // eslint-disable-next-line class-methods-use-this
  leaveGroup(endpoint) {
    return Vue.http.delete(endpoint);
  }
}