File tree Expand file tree Collapse file tree 6 files changed +21
-5
lines changed Expand file tree Collapse file tree 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 {
5858 if ( config . query ) endpoint += `?${ Object . keys ( config . query ) . map ( k => `${ encodeURIComponent ( k ) } =${ encodeURIComponent ( config . query [ k ] ) } ` ) . join ( '&' ) } ` ;
5959 return endpoint ;
6060 }
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+ }
6172}
Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ export default class Create extends Action {
1717 const model = context . getModelFromState ( state ) ;
1818 const endpoint = Action . transformParams ( '$create' , model , params ) ;
1919 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 ) ;
2122
2223 this . onRequest ( commit ) ;
2324 request
Original file line number Diff line number Diff line change @@ -13,7 +13,8 @@ export default class Delete extends Action {
1313 const model = context . getModelFromState ( state ) ;
1414 const endpoint = Action . transformParams ( '$delete' , model , params ) ;
1515 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 ) ;
1718
1819 this . onRequest ( model , params ) ;
1920 request
Original file line number Diff line number Diff line change @@ -13,7 +13,8 @@ export default class Fetch extends Action {
1313 const model = context . getModelFromState ( state ) ;
1414 const endpoint = Action . transformParams ( '$fetch' , model , params ) ;
1515 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 ) ;
1718
1819 this . onRequest ( commit ) ;
1920 request
Original file line number Diff line number Diff line change @@ -13,7 +13,8 @@ export default class Get extends Action {
1313 const model = context . getModelFromState ( state ) ;
1414 const endpoint = Action . transformParams ( '$get' , model , params ) ;
1515 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 ) ;
1718
1819 this . onRequest ( commit ) ;
1920 request
Original file line number Diff line number Diff line change @@ -18,7 +18,8 @@ export default class Update extends Action {
1818 const model = context . getModelFromState ( state ) ;
1919 const endpoint = Action . transformParams ( '$update' , model , params ) ;
2020 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 ) ;
2223
2324 this . onRequest ( model , params ) ;
2425 request
You can’t perform that action at this time.
0 commit comments