File tree 6 files changed +21
-5
lines changed
6 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -58,4 +58,15 @@ export default class Action {
58
58
if ( config . query ) endpoint += `?${ Object . keys ( config . query ) . map ( k => `${ encodeURIComponent ( k ) } =${ encodeURIComponent ( config . query [ k ] ) } ` ) . join ( '&' ) } ` ;
59
59
return endpoint ;
60
60
}
61
+
62
+ /**
63
+ * Get appropriate methods
64
+ * @param {string } type
65
+ * @param {object } model
66
+ * @param {string } defaultMethod
67
+ */
68
+ static getMethod ( type , model , defaultMethod ) {
69
+ const customMethod = model . methodConf . methods [ type ] . http . method ;
70
+ return ( customMethod ) ? customMethod : defaultMethod ;
71
+ }
61
72
}
Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ export default class Create extends Action {
17
17
const model = context . getModelFromState ( state ) ;
18
18
const endpoint = Action . transformParams ( '$create' , model , params ) ;
19
19
const axios = new Axios ( model . methodConf . http ) ;
20
- const request = axios . post ( endpoint , params . data ) ;
20
+ const method = Action . getMethod ( '$create' , model , 'post' ) ;
21
+ const request = axios [ method ] ( endpoint , params . data ) ;
21
22
22
23
this . onRequest ( commit ) ;
23
24
request
Original file line number Diff line number Diff line change @@ -13,7 +13,8 @@ export default class Delete extends Action {
13
13
const model = context . getModelFromState ( state ) ;
14
14
const endpoint = Action . transformParams ( '$delete' , model , params ) ;
15
15
const axios = new Axios ( model . methodConf . http ) ;
16
- const request = axios . delete ( endpoint ) ;
16
+ const method = Action . getMethod ( '$delete' , model , 'delete' ) ;
17
+ const request = axios [ method ] ( endpoint ) ;
17
18
18
19
this . onRequest ( model , params ) ;
19
20
request
Original file line number Diff line number Diff line change @@ -13,7 +13,8 @@ export default class Fetch extends Action {
13
13
const model = context . getModelFromState ( state ) ;
14
14
const endpoint = Action . transformParams ( '$fetch' , model , params ) ;
15
15
const axios = new Axios ( model . methodConf . http ) ;
16
- const request = axios . get ( endpoint ) ;
16
+ const method = Action . getMethod ( '$fetch' , model , 'get' ) ;
17
+ const request = axios [ method ] ( endpoint ) ;
17
18
18
19
this . onRequest ( commit ) ;
19
20
request
Original file line number Diff line number Diff line change @@ -13,7 +13,8 @@ export default class Get extends Action {
13
13
const model = context . getModelFromState ( state ) ;
14
14
const endpoint = Action . transformParams ( '$get' , model , params ) ;
15
15
const axios = new Axios ( model . methodConf . http ) ;
16
- const request = axios . get ( endpoint ) ;
16
+ const method = Action . getMethod ( '$get' , model , 'get' ) ;
17
+ const request = axios [ method ] ( endpoint ) ;
17
18
18
19
this . onRequest ( commit ) ;
19
20
request
Original file line number Diff line number Diff line change @@ -18,7 +18,8 @@ export default class Update extends Action {
18
18
const model = context . getModelFromState ( state ) ;
19
19
const endpoint = Action . transformParams ( '$update' , model , params ) ;
20
20
const axios = new Axios ( model . methodConf . http ) ;
21
- const request = axios . put ( endpoint , params . data ) ;
21
+ const method = Action . getMethod ( '$update' , model , 'put' ) ;
22
+ const request = axios [ method ] ( endpoint , params . data ) ;
22
23
23
24
this . onRequest ( model , params ) ;
24
25
request
You can’t perform that action at this time.
0 commit comments