|
1 | 1 | import request from 'superagent'; |
2 | | -import { handleSuccess, handleError } from '_utils/api'; |
| 2 | +import { handleError, handleSuccess } from '_utils/api'; |
3 | 3 |
|
4 | | -// from userID, get all the items the user created |
5 | | -export const getItemByUserId = (userId) => request.get('/api/item/') |
6 | | - .query({ owner: userId }) |
| 4 | +// get item with item id |
| 5 | +export const getItem = (itemId) => request.get(`/api/item/${itemId}`) |
7 | 6 | .then(handleSuccess) |
8 | 7 | .catch(handleError); |
9 | 8 |
|
10 | | -export const getItemByItemId = (itemId) => request.get(`/api/item/${itemId}`) |
11 | | - // .query({ item_id: item_id }) |
| 9 | +// get all items from user with user id |
| 10 | +// all item's owner property would be same current as user's id |
| 11 | +export const getUserItem = (userId) => request.get('/api/item/') |
| 12 | + .query({ owner: userId }) |
12 | 13 | .then(handleSuccess) |
13 | 14 | .catch(handleError); |
14 | 15 |
|
15 | | -export const getItemChild = (itemPath) => request.get('/api/item') |
| 16 | +// get item's children if exists |
| 17 | +// searches with ?path={itemPath} query |
| 18 | +export const getItemChildren = (itemPath) => request.get('/api/item') |
16 | 19 | .query({ path: itemPath }) |
17 | 20 | .then(handleSuccess) |
18 | 21 | .catch(handleError); |
19 | 22 |
|
20 | | -export const getRecommendItem = (id) => request.get('/api/recommend') |
21 | | - .query({ userId: id }) |
| 23 | +// get recommended items with user id |
| 24 | +export const getRecommendItem = (userId) => request.get('/api/recommend') |
| 25 | + .query({ userId: userId }) |
22 | 26 | .then(handleSuccess) |
23 | 27 | .catch(handleError); |
24 | 28 |
|
| 29 | +// get Algolia search result |
25 | 30 | export const algoliaSearch = (query) => request.get(`/api/item/algolia/${query}`) |
26 | 31 | // .query({ query }) |
27 | 32 | .then(handleSuccess) |
28 | 33 | .catch(handleError); |
29 | 34 |
|
| 35 | +// update item with item id |
30 | 36 | export const updateItem = (itemId, object) => request.put(`/api/item/${itemId}`) |
31 | 37 | .send(object) |
32 | 38 | .then(handleSuccess) |
33 | 39 | .catch(handleError); |
34 | 40 |
|
| 41 | +// update item.status to 'archived' with item id |
| 42 | +export const archiveItem = (itemId) => request.put(`/api/item/${itemId}`) |
| 43 | + .send({status: 'archived'}) |
| 44 | + .then(handleSuccess) |
| 45 | + .catch(handleError); |
| 46 | + |
| 47 | +// update item.status to 'published' with item id |
| 48 | +export const publishItem = (itemId) => request.put(`/api/item/${itemId}`) |
| 49 | + .send({status: 'published'}) |
| 50 | + .then(handleSuccess) |
| 51 | + .catch(handleError); |
| 52 | + |
| 53 | +// delete item with item id |
35 | 54 | export const deleteItem = (itemId) => request.delete(`/api/item/${itemId}`) |
36 | 55 | .then(handleSuccess) |
37 | 56 | .catch(handleError); |
38 | 57 |
|
39 | | -export const createItem = (object) => request.post('api/item') |
| 58 | +// create item with object |
| 59 | +export const createItem = (object) => request.post('/api/item') |
40 | 60 | .send(object) |
41 | 61 | .then(handleSuccess) |
42 | 62 | .catch(handleError); |
0 commit comments