File size: 4,636 Bytes
1e92f2d |
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
import { API } from '../config';
export const createCategory = (userId, token, category) => {
return fetch(`${API}/category/create/${userId}`, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
},
body: JSON.stringify(category)
})
.then(response => {
return response.json();
})
.catch(err => {
console.log(err);
});
};
export const updateCategory = (categoryId, userId, token, category) => {
return fetch(`${API}/category/${categoryId}/${userId}`, {
method: 'PUT',
headers: {
// content type?
'Content-Type': 'application/json',
Accept: 'application/json',
Authorization: `Bearer ${token}`
},
body: JSON.stringify(category)
})
.then(response => {
return response.json();
})
.catch(err => console.log(err));
};
export const createProduct = (userId, token, product) => {
return fetch(`${API}/product/create/${userId}`, {
method: 'POST',
headers: {
Accept: 'application/json',
Authorization: `Bearer ${token}`
},
body: product
})
.then(response => {
return response.json();
})
.catch(err => {
console.log(err);
});
};
export const getCategory = categoryId => {
return fetch(`${API}/category/${categoryId}`, {
method: 'GET'
})
.then(response => {
return response.json();
})
.catch(err => console.log(err));
};
export const getCategories = () => {
return fetch(`${API}/categories`, {
method: 'GET'
})
.then(response => {
return response.json();
})
.catch(err => console.log(err));
};
export const listOrders = (userId, token) => {
return fetch(`${API}/order/list/${userId}`, {
method: 'GET',
headers: {
Accept: 'application/json',
Authorization: `Bearer ${token}`
}
})
.then(response => {
return response.json();
})
.catch(err => console.log(err));
};
export const getStatusValues = (userId, token) => {
return fetch(`${API}/order/status-values/${userId}`, {
method: 'GET',
headers: {
Accept: 'application/json',
Authorization: `Bearer ${token}`
}
})
.then(response => {
return response.json();
})
.catch(err => console.log(err));
};
export const updateOrderStatus = (userId, token, orderId, status) => {
return fetch(`${API}/order/${orderId}/status/${userId}`, {
method: 'PUT',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
},
body: JSON.stringify({ status, orderId })
})
.then(response => {
return response.json();
})
.catch(err => console.log(err));
};
/**
* to perform crud on product
* get all products
* get a single product
* update single product
* delete single product
*/
export const getProducts = () => {
return fetch(`${API}/products?limit=undefined`, {
method: 'GET'
})
.then(response => {
return response.json();
})
.catch(err => console.log(err));
};
export const deleteProduct = (productId, userId, token) => {
return fetch(`${API}/product/${productId}/${userId}`, {
method: 'DELETE',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
}
})
.then(response => {
return response.json();
})
.catch(err => console.log(err));
};
export const getProduct = productId => {
return fetch(`${API}/product/${productId}`, {
method: 'GET'
})
.then(response => {
return response.json();
})
.catch(err => console.log(err));
};
export const updateProduct = (productId, userId, token, product) => {
return fetch(`${API}/product/${productId}/${userId}`, {
method: 'PUT',
headers: {
Accept: 'application/json',
Authorization: `Bearer ${token}`
},
body: product
})
.then(response => {
return response.json();
})
.catch(err => console.log(err));
};
|