1- import axios from ' axios' ;
2- import { apiUrl } from ' ./config' ;
3- import { getUserInfo } from ' ./localStorage' ;
1+ import axios from " axios" ;
2+ import { apiUrl } from " ./config" ;
3+ import { getUserInfo } from " ./localStorage" ;
44
5- export const getProducts = async ( { searchKeyword = '' } ) => {
5+ export const getProducts = async ( { searchKeyword = "" } ) => {
66 try {
7- let queryString = '?' ;
7+ let queryString = "?" ;
88 if ( searchKeyword ) queryString += `searchKeyword=${ searchKeyword } &` ;
99
1010 const response = await axios ( {
1111 url : `${ apiUrl } /api/products${ queryString } ` ,
12- method : ' GET' ,
12+ method : " GET" ,
1313 headers : {
14- ' Content-Type' : ' application/json' ,
14+ " Content-Type" : " application/json" ,
1515 } ,
1616 } ) ;
17- if ( response . statusText !== 'OK' ) {
18- throw new Error ( response . data . message ) ;
19- }
17+ // if (response.statusText !== 'OK') {
18+ // throw new Error(response.data.message);
19+ // }
2020 return response . data ;
2121 } catch ( err ) {
2222 console . log ( err ) ;
@@ -28,14 +28,14 @@ export const getProduct = async (id) => {
2828 try {
2929 const response = await axios ( {
3030 url : `${ apiUrl } /api/products/${ id } ` ,
31- method : ' GET' ,
31+ method : " GET" ,
3232 headers : {
33- ' Content-Type' : ' application/json' ,
33+ " Content-Type" : " application/json" ,
3434 } ,
3535 } ) ;
36- if ( response . statusText !== 'OK' ) {
37- throw new Error ( response . data . message ) ;
38- }
36+ // if (response.statusText !== 'OK') {
37+ // throw new Error(response.data.message);
38+ // }
3939 return response . data ;
4040 } catch ( err ) {
4141 console . log ( err ) ;
@@ -47,13 +47,13 @@ export const createProduct = async () => {
4747 const { token } = getUserInfo ( ) ;
4848 const response = await axios ( {
4949 url : `${ apiUrl } /api/products` ,
50- method : ' POST' ,
50+ method : " POST" ,
5151 headers : {
52- ' Content-Type' : ' application/json' ,
52+ " Content-Type" : " application/json" ,
5353 Authorization : `Bearer ${ token } ` ,
5454 } ,
5555 } ) ;
56- if ( response . statusText !== ' Created' ) {
56+ if ( response . statusText !== " Created" ) {
5757 throw new Error ( response . data . message ) ;
5858 }
5959 return response . data ;
@@ -67,14 +67,14 @@ export const createReview = async (productId, review) => {
6767 const { token } = getUserInfo ( ) ;
6868 const response = await axios ( {
6969 url : `${ apiUrl } /api/products/${ productId } /reviews` ,
70- method : ' POST' ,
70+ method : " POST" ,
7171 headers : {
72- ' Content-Type' : ' application/json' ,
72+ " Content-Type" : " application/json" ,
7373 Authorization : `Bearer ${ token } ` ,
7474 } ,
7575 data : review ,
7676 } ) ;
77- if ( response . statusText !== ' Created' ) {
77+ if ( response . statusText !== " Created" ) {
7878 throw new Error ( response . data . message ) ;
7979 }
8080 return response . data ;
@@ -88,15 +88,15 @@ export const deleteProduct = async (productId) => {
8888 const { token } = getUserInfo ( ) ;
8989 const response = await axios ( {
9090 url : `${ apiUrl } /api/products/${ productId } ` ,
91- method : ' DELETE' ,
91+ method : " DELETE" ,
9292 headers : {
93- ' Content-Type' : ' application/json' ,
93+ " Content-Type" : " application/json" ,
9494 Authorization : `Bearer ${ token } ` ,
9595 } ,
9696 } ) ;
97- if ( response . statusText !== 'OK' ) {
98- throw new Error ( response . data . message ) ;
99- }
97+ // if (response.statusText !== 'OK') {
98+ // throw new Error(response.data.message);
99+ // }
100100 return response . data ;
101101 } catch ( err ) {
102102 return { error : err . response . data . message || err . message } ;
@@ -108,16 +108,16 @@ export const updateProduct = async (product) => {
108108 const { token } = getUserInfo ( ) ;
109109 const response = await axios ( {
110110 url : `${ apiUrl } /api/products/${ product . _id } ` ,
111- method : ' PUT' ,
111+ method : " PUT" ,
112112 headers : {
113- ' Content-Type' : ' application/json' ,
113+ " Content-Type" : " application/json" ,
114114 Authorization : `Bearer ${ token } ` ,
115115 } ,
116116 data : product ,
117117 } ) ;
118- if ( response . statusText !== 'OK' ) {
119- throw new Error ( response . data . message ) ;
120- }
118+ // if (response.statusText !== 'OK') {
119+ // throw new Error(response.data.message);
120+ // }
121121 return response . data ;
122122 } catch ( err ) {
123123 return { error : err . response . data . message || err . message } ;
@@ -129,14 +129,14 @@ export const uploadProductImage = async (formData) => {
129129 const { token } = getUserInfo ( ) ;
130130 const response = await axios ( {
131131 url : `${ apiUrl } /api/uploads` ,
132- method : ' POST' ,
132+ method : " POST" ,
133133 headers : {
134134 Authorization : `Bearer ${ token } ` ,
135- ' Content-Type' : ' multipart/form-data' ,
135+ " Content-Type" : " multipart/form-data" ,
136136 } ,
137137 data : formData ,
138138 } ) ;
139- if ( response . statusText !== ' Created' ) {
139+ if ( response . statusText !== " Created" ) {
140140 throw new Error ( response . data . message ) ;
141141 } else {
142142 return response . data ;
@@ -150,18 +150,18 @@ export const signin = async ({ email, password }) => {
150150 try {
151151 const response = await axios ( {
152152 url : `${ apiUrl } /api/users/signin` ,
153- method : ' POST' ,
153+ method : " POST" ,
154154 header : {
155- ' Content-Type' : ' application/json' ,
155+ " Content-Type" : " application/json" ,
156156 } ,
157157 data : {
158158 email,
159159 password,
160160 } ,
161161 } ) ;
162- if ( response . statusText !== 'OK' ) {
163- throw new Error ( response . data . message ) ;
164- }
162+ // if (response.statusText !== 'OK') {
163+ // throw new Error(response.data.message);
164+ // }
165165 return response . data ;
166166 } catch ( err ) {
167167 console . log ( err ) ;
@@ -172,19 +172,19 @@ export const register = async ({ name, email, password }) => {
172172 try {
173173 const response = await axios ( {
174174 url : `${ apiUrl } /api/users/register` ,
175- method : ' POST' ,
175+ method : " POST" ,
176176 header : {
177- ' Content-Type' : ' application/json' ,
177+ " Content-Type" : " application/json" ,
178178 } ,
179179 data : {
180180 name,
181181 email,
182182 password,
183183 } ,
184184 } ) ;
185- if ( response . statusText !== 'OK' ) {
186- throw new Error ( response . data . message ) ;
187- }
185+ // if (response.statusText !== 'OK') {
186+ // throw new Error(response.data.message);
187+ // }
188188 return response . data ;
189189 } catch ( err ) {
190190 console . log ( err ) ;
@@ -196,9 +196,9 @@ export const update = async ({ name, email, password }) => {
196196 const { _id, token } = getUserInfo ( ) ;
197197 const response = await axios ( {
198198 url : `${ apiUrl } /api/users/${ _id } ` ,
199- method : ' PUT' ,
199+ method : " PUT" ,
200200 headers : {
201- ' Content-Type' : ' application/json' ,
201+ " Content-Type" : " application/json" ,
202202 Authorization : `Bearer ${ token } ` ,
203203 } ,
204204 data : {
@@ -207,9 +207,9 @@ export const update = async ({ name, email, password }) => {
207207 password,
208208 } ,
209209 } ) ;
210- if ( response . statusText !== 'OK' ) {
211- throw new Error ( response . data . message ) ;
212- }
210+ // if (response.statusText !== 'OK') {
211+ // throw new Error(response.data.message);
212+ // }
213213 return response . data ;
214214 } catch ( err ) {
215215 console . log ( err ) ;
@@ -222,14 +222,14 @@ export const createOrder = async (order) => {
222222 const { token } = getUserInfo ( ) ;
223223 const response = await axios ( {
224224 url : `${ apiUrl } /api/orders` ,
225- method : ' POST' ,
225+ method : " POST" ,
226226 headers : {
227- ' Content-Type' : ' application/json' ,
227+ " Content-Type" : " application/json" ,
228228 Authorization : `Bearer ${ token } ` ,
229229 } ,
230230 data : order ,
231231 } ) ;
232- if ( response . statusText !== ' Created' ) {
232+ if ( response . statusText !== " Created" ) {
233233 throw new Error ( response . data . message ) ;
234234 }
235235 return response . data ;
@@ -242,15 +242,15 @@ export const getOrders = async () => {
242242 const { token } = getUserInfo ( ) ;
243243 const response = await axios ( {
244244 url : `${ apiUrl } /api/orders` ,
245- method : ' GET' ,
245+ method : " GET" ,
246246 headers : {
247- ' Content-Type' : ' application/json' ,
247+ " Content-Type" : " application/json" ,
248248 Authorization : `Bearer ${ token } ` ,
249249 } ,
250250 } ) ;
251- if ( response . statusText !== 'OK' ) {
252- throw new Error ( response . data . message ) ;
253- }
251+ // if (response.statusText !== 'OK') {
252+ // throw new Error(response.data.message);
253+ // }
254254 return response . data ;
255255 } catch ( err ) {
256256 console . log ( err ) ;
@@ -262,15 +262,15 @@ export const deleteOrder = async (orderId) => {
262262 const { token } = getUserInfo ( ) ;
263263 const response = await axios ( {
264264 url : `${ apiUrl } /api/orders/${ orderId } ` ,
265- method : ' DELETE' ,
265+ method : " DELETE" ,
266266 headers : {
267- ' Content-Type' : ' application/json' ,
267+ " Content-Type" : " application/json" ,
268268 Authorization : `Bearer ${ token } ` ,
269269 } ,
270270 } ) ;
271- if ( response . statusText !== 'OK' ) {
272- throw new Error ( response . data . message ) ;
273- }
271+ // if (response.statusText !== 'OK') {
272+ // throw new Error(response.data.message);
273+ // }
274274 return response . data ;
275275 } catch ( err ) {
276276 return { error : err . response . data . message || err . message } ;
@@ -282,13 +282,13 @@ export const getOrder = async (id) => {
282282 const response = await axios ( {
283283 url : `${ apiUrl } /api/orders/${ id } ` ,
284284 headers : {
285- ' Content-Type' : ' application/json' ,
285+ " Content-Type" : " application/json" ,
286286 Authorization : `Bearer ${ token } ` ,
287287 } ,
288288 } ) ;
289- if ( response . statusText !== 'OK' ) {
290- throw new Error ( response . data . message ) ;
291- }
289+ // if (response.statusText !== 'OK') {
290+ // throw new Error(response.data.message);
291+ // }
292292 return response . data ;
293293 } catch ( err ) {
294294 return { error : err . message } ;
@@ -300,13 +300,13 @@ export const getMyOrders = async () => {
300300 const response = await axios ( {
301301 url : `${ apiUrl } /api/orders/mine` ,
302302 headers : {
303- ' Content-Type' : ' application/json' ,
303+ " Content-Type" : " application/json" ,
304304 Authorization : `Bearer ${ token } ` ,
305305 } ,
306306 } ) ;
307- if ( response . statusText !== 'OK' ) {
308- throw new Error ( response . data . message ) ;
309- }
307+ // if (response.statusText !== 'OK') {
308+ // throw new Error(response.data.message);
309+ // }
310310 return response . data ;
311311 } catch ( err ) {
312312 return { error : err . response ? err . response . data . message : err . message } ;
@@ -316,12 +316,12 @@ export const getPaypalClientId = async () => {
316316 const response = await axios ( {
317317 url : `${ apiUrl } /api/paypal/clientId` ,
318318 headers : {
319- ' Content-Type' : ' application/json' ,
319+ " Content-Type" : " application/json" ,
320320 } ,
321321 } ) ;
322- if ( response . statusText !== 'OK' ) {
323- throw new Error ( response . data . message ) ;
324- }
322+ // if (response.statusText !== 'OK') {
323+ // throw new Error(response.data.message);
324+ // }
325325 return response . data . clientId ;
326326} ;
327327
@@ -330,16 +330,16 @@ export const payOrder = async (orderId, paymentResult) => {
330330 const { token } = getUserInfo ( ) ;
331331 const response = await axios ( {
332332 url : `${ apiUrl } /api/orders/${ orderId } /pay` ,
333- method : ' PUT' ,
333+ method : " PUT" ,
334334 headers : {
335- ' Content-Type' : ' application/json' ,
335+ " Content-Type" : " application/json" ,
336336 Authorization : `Bearer ${ token } ` ,
337337 } ,
338338 data : paymentResult ,
339339 } ) ;
340- if ( response . statusText !== 'OK' ) {
341- throw new Error ( response . data . message ) ;
342- }
340+ // if (response.statusText !== 'OK') {
341+ // throw new Error(response.data.message);
342+ // }
343343 return response . data ;
344344 } catch ( err ) {
345345 return { error : err . response ? err . response . data . message : err . message } ;
@@ -350,15 +350,15 @@ export const deliverOrder = async (orderId) => {
350350 const { token } = getUserInfo ( ) ;
351351 const response = await axios ( {
352352 url : `${ apiUrl } /api/orders/${ orderId } /deliver` ,
353- method : ' PUT' ,
353+ method : " PUT" ,
354354 headers : {
355- ' Content-Type' : ' application/json' ,
355+ " Content-Type" : " application/json" ,
356356 Authorization : `Bearer ${ token } ` ,
357357 } ,
358358 } ) ;
359- if ( response . statusText !== 'OK' ) {
360- throw new Error ( response . data . message ) ;
361- }
359+ // if (response.statusText !== 'OK') {
360+ // throw new Error(response.data.message);
361+ // }
362362 return response . data ;
363363 } catch ( err ) {
364364 return { error : err . response ? err . response . data . message : err . message } ;
@@ -371,14 +371,14 @@ export const getSummary = async () => {
371371 url : `${ apiUrl } /api/orders/summary` ,
372372 headers : {
373373 Authorization : `Bearer ${ token } ` ,
374- ' content-type' : ' application/json' ,
374+ " content-type" : " application/json" ,
375375 } ,
376376 } ) ;
377- if ( response . statusText !== 'OK' ) {
378- throw new Error ( response . data . message ) ;
379- } else {
380- return response . data ;
381- }
377+ // if (response.statusText !== 'OK') {
378+ // throw new Error(response.data.message);
379+ // }
380+
381+ return response . data ;
382382 } catch ( err ) {
383383 return { error : err . response ? err . response . data . message : err . message } ;
384384 }
0 commit comments