-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
21 lines (17 loc) · 731 Bytes
/
index.js
File metadata and controls
21 lines (17 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import MainClient from "./MainClient.js";
const APIProvider = ({ headers = {}, accessToken, statusHandler }) => {
const client = MainClient({ headers, accessToken, statusHandler });
const customApi = (url) => ({
getMany: (params) => client.get(url, { params }),
getOne: ({ id, ...params }) => client.get(`${url}/${id}`, { params }),
update: (params) => client.put(`${url}/${params.id}`, params.values),
add: (data) => client.post(url, data),
delete: (params) => client.delete(`${url}/${params.id}`, { params }),
});
return function (url, types) {
return types?.length
? types.map((item) => customApi(url)?.[item])
: Object.values(customApi(url));
};
};
export default APIProvider;