All files / ee/app/assets/javascripts/api groups_api.js

100% Statements 23/23
100% Branches 2/2
100% Functions 5/5
100% Lines 23/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69        4x 4x   4x   4x 4x 4x         4x               4x 1x       1x     4x 3x       3x     4x 4x   4x 4x 4x           4x               4x   4x 4x       4x    
import { DEFAULT_PER_PAGE } from '~/api';
import { buildApiUrl } from '~/api/api_utils';
import axios from '~/lib/utils/axios_utils';
 
const GROUPS_BILLABLE_MEMBERS_SINGLE_PATH = '/api/:version/groups/:group_id/billable_members/:id';
const GROUPS_BILLABLE_MEMBERS_PATH = '/api/:version/groups/:id/billable_members';
const GROUPS_BILLABLE_MEMBERS_SINGLE_MEMBERSHIPS_PATH =
  '/api/:version/groups/:group_id/billable_members/:member_id/memberships';
 
export const fetchBillableGroupMembersList = (namespaceId, options = {}) => {
  const url = buildApiUrl(GROUPS_BILLABLE_MEMBERS_PATH).replace(':id', namespaceId);
  const defaults = {
    per_page: DEFAULT_PER_PAGE,
    page: 1,
  };
 
  return axios.get(url, {
    params: {
      ...defaults,
      ...options,
    },
  });
};
 
export const fetchBillableGroupMemberMemberships = (namespaceId, memberId) => {
  const url = buildApiUrl(GROUPS_BILLABLE_MEMBERS_SINGLE_MEMBERSHIPS_PATH)
    .replace(':group_id', namespaceId)
    .replace(':member_id', memberId);
 
  return axios.get(url);
};
 
export const removeBillableMemberFromGroup = (groupId, memberId) => {
  const url = buildApiUrl(GROUPS_BILLABLE_MEMBERS_SINGLE_PATH)
    .replace(':group_id', groupId)
    .replace(':id', memberId);
 
  return axios.delete(url);
};
 
const GROUPS_PENDING_MEMBERS_PATH = '/api/:version/groups/:id/pending_members';
const GROUPS_PENDING_MEMBERS_STATE = 'awaiting';
 
export const fetchPendingGroupMembersList = (namespaceId, options = {}) => {
  const url = buildApiUrl(GROUPS_PENDING_MEMBERS_PATH).replace(':id', namespaceId);
  const defaults = {
    state: GROUPS_PENDING_MEMBERS_STATE,
    per_page: DEFAULT_PER_PAGE,
    page: 1,
  };
 
  return axios.get(url, {
    params: {
      ...defaults,
      ...options,
    },
  });
};
 
const APPROVE_PENDING_GROUP_MEMBER_PATH = '/api/:version/groups/:id/members/:user_id/approve';
 
export const approvePendingGroupMember = (namespaceId, userId) => {
  const url = buildApiUrl(APPROVE_PENDING_GROUP_MEMBER_PATH)
    .replace(':id', namespaceId)
    .replace(':user_id', userId);
 
  return axios.put(url);
};