Passed
Pull Request — master (#123)
by Mathieu
02:04
created

client/src/utils/axios.js   A

Complexity

Total Complexity 5
Complexity/F 1.67

Size

Lines of Code 28
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 16
mnd 2
bc 2
fnc 3
dl 0
loc 28
rs 10
bpm 0.6666
cpm 1.6666
noi 0
c 0
b 0
f 0
1
import axios from 'axios';
2
3
const client = axios.create({
4
  baseURL: '/api'
5
});
6
7
const header = token => {
8
  if (!token) {
9
    return;
10
  }
11
12
  return {
13
    headers: {
14
      Authorization: `Bearer ${token}`
15
    }
16
  };
17
};
18
19
export const post = (url, payload, token) => {
20
  return client.post(url, payload, header(token));
21
};
22
23
export const put = (url, payload, token) => {
24
  return client.put(url, payload, header(token));
25
};
26
27
export const del = (url, token) => {
28
  return client.delete(url, header(token));
29
};
30
31
export const get = (url, payload, token) => {
32
  return client.get(url, { ...payload, ...header(token) });
33
};
34