-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathapi.js
61 lines (50 loc) · 1.66 KB
/
api.js
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
import { AUTH_API_BASE } from '../api-version';
const filterUndef = (obj) =>
Object.keys(obj).reduce((ret, k) => {
if (obj[k] !== undefined) {
ret[k] = obj[k];
}
return ret;
}, {});
export default function apiServletFactory(fetch, options) {
return {
getMeProfile: () => fetch(`${AUTH_API_BASE}/me/profile`, options),
updateMeProfile: (data) => {
const payload = filterUndef(data);
return fetch(`${AUTH_API_BASE}/me/profile`, {
...options,
method: 'POST',
body: JSON.stringify(payload),
});
},
getMeAvatar: () =>
fetch(`${AUTH_API_BASE}/me/avatar`, { ...options, raw: true }),
meAccount: () => fetch(`${AUTH_API_BASE}/me/account`, options),
mePassword: (oldPassword, newPassword) => {
return fetch(`${AUTH_API_BASE}/me/password`, {
...options,
method: 'PUT',
body: JSON.stringify({
oldPassword,
newPassword,
}),
});
},
meTeams: () => fetch(`${AUTH_API_BASE}/me/teams`, options),
updateMeAvatar: (data) => {
return fetch(`${AUTH_API_BASE}/me/avatar`, {
...options,
method: 'PUT',
body: data,
headers: {
...options.headers,
'Content-Type': data.type,
},
raw: true,
});
},
meRoles: () => {
return fetch(`${AUTH_API_BASE}/me/roles`, options);
},
};
}