Skip to content

Commit e65fe3b

Browse files
committed
Make naming of api call handler arguments clearer
Before it call the third argument 'headers' when they are not headers, but a config object that may have a headers key.
1 parent 4a27d50 commit e65fe3b

1 file changed

Lines changed: 19 additions & 23 deletions

File tree

src/utils/apiCallHandler.js

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,24 @@ import omit from "lodash/omit";
44
const ApiCallHandler = ({ reactAppApiEndpoint }) => {
55
const host = reactAppApiEndpoint;
66

7-
const get = async (url, headers) => {
8-
return await axios.get(url, headers);
7+
const get = async (url, config) => {
8+
return await axios.get(url, config);
99
};
1010

11-
const post = async (url, body, headers) => {
12-
return await axios.post(url, body, headers);
11+
const post = async (url, body, config) => {
12+
return await axios.post(url, body, config);
1313
};
1414

15-
const put = async (url, body, headers) => {
16-
return await axios.put(url, body, headers);
15+
const put = async (url, body, config) => {
16+
return await axios.put(url, body, config);
1717
};
1818

1919
const headers = (accessToken) => {
20-
let headersHash;
2120
if (accessToken) {
22-
headersHash = { Accept: "application/json", Authorization: accessToken };
21+
return { Accept: "application/json", Authorization: accessToken };
2322
} else {
24-
headersHash = { Accept: "application/json" };
23+
return { Accept: "application/json" };
2524
}
26-
return { headers: headersHash };
2725
};
2826

2927
const createOrUpdateProject = async (projectWithUserId, accessToken) => {
@@ -32,52 +30,50 @@ const ApiCallHandler = ({ reactAppApiEndpoint }) => {
3230
return await post(
3331
`${host}/api/projects`,
3432
{ project },
35-
headers(accessToken),
33+
{ headers: headers(accessToken) },
3634
);
3735
} else {
3836
return await put(
3937
`${host}/api/projects/${project.identifier}`,
4038
{ project },
41-
headers(accessToken),
39+
{ headers: headers(accessToken) },
4240
);
4341
}
4442
};
4543

4644
const deleteProject = async (identifier, accessToken) => {
47-
return await axios.delete(
48-
`${host}/api/projects/${identifier}`,
49-
headers(accessToken),
50-
);
45+
return await axios.delete(`${host}/api/projects/${identifier}`, {
46+
headers: headers(accessToken),
47+
});
5148
};
5249

5350
const loadRemix = async (projectIdentifier, accessToken) => {
54-
return await get(
55-
`${host}/api/projects/${projectIdentifier}/remix`,
56-
headers(accessToken),
57-
);
51+
return await get(`${host}/api/projects/${projectIdentifier}/remix`, {
52+
headers: headers(accessToken),
53+
});
5854
};
5955

6056
const createRemix = async (project, accessToken) => {
6157
return await post(
6258
`${host}/api/projects/${project.identifier}/remix`,
6359
{ project },
64-
headers(accessToken),
60+
{ headers: headers(accessToken) },
6561
);
6662
};
6763

6864
const readProject = async (projectIdentifier, locale, accessToken) => {
6965
const queryString = locale ? `?locale=${locale}` : "";
7066
return await get(
7167
`${host}/api/projects/${projectIdentifier}${queryString}`,
72-
headers(accessToken),
68+
{ headers: headers(accessToken) },
7369
);
7470
};
7571

7672
const loadAssets = async (assetsIdentifier, locale, accessToken) => {
7773
const queryString = locale ? `?locale=${locale}` : "";
7874
return await get(
7975
`${host}/api/projects/${assetsIdentifier}/images${queryString}`,
80-
headers(accessToken),
76+
{ headers: headers(accessToken) },
8177
);
8278
};
8379

0 commit comments

Comments
 (0)