aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/workspaces/api.js
blob: 733cb55930ab54e15ed0e45ae3dece18a24db8c2 (plain) (blame)
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
import { pick } from 'lodash';
import { sendAuthRequest } from '../../api/utils/auth';
import { API, API_VERSION } from '../../environment';

export default {
  getUserWorkspaces: async () => {
    const url = `${API}/${API_VERSION}/workspace`;
    const request = await sendAuthRequest(url, { method: 'GET' });
    if (!request.ok) throw request;
    return request.json();
  },

  createWorkspace: async (name) => {
    const url = `${API}/${API_VERSION}/workspace`;
    const request = await sendAuthRequest(url, {
      method: 'POST',
      body: JSON.stringify({ name }),
    });
    if (!request.ok) throw request;
    return request.json();
  },

  deleteWorkspace: async (workspace) => {
    const url = `${API}/${API_VERSION}/workspace/${workspace.id}`;
    const request = await sendAuthRequest(url, { method: 'DELETE' });
    if (!request.ok) throw request;
    return request.json();
  },

  updateWorkspace: async (workspace) => {
    const url = `${API}/${API_VERSION}/workspace/${workspace.id}`;
    const request = await sendAuthRequest(url, {
      method: 'PUT',
      body: JSON.stringify(pick(workspace, ['name', 'services'])),
    });
    if (!request.ok) throw request;
    return request.json();
  },
};