generated from staticwebdev/mongoose-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
itemAPI.js
25 lines (24 loc) · 816 Bytes
/
itemAPI.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
import axios from 'axios';
const baseUrl = '/api/lists';
export const itemService = {
list: async (listId) => {
const response = await axios.get(`${baseUrl}/${listId}/items`);
return response.data;
},
save: async (item) => {
if (!item.id) {
// New item, post/save
item.state = 'active';
const response = await axios.post(`${baseUrl}/${item.listId}/items`, item);
return response.data;
} else {
// Existing item updating, put/save
const response = await axios.put(`${baseUrl}/${item.listId}/items/${item.id}`, item);
return response.data;
}
},
delete: async (item) => {
await axios.delete(`${baseUrl}/${item.listId}/items/${item.id}`);
return item;
}
}