File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import Axios from '../orm/axios' ;
12import Action from './Action'
3+ import Context from '../common/context'
24
35export default class Update extends Action {
4- static call ( { state, dispatch } , params = { } ) {
5- console . log ( state , dispatch , params ) ;
6+ /**
7+ * Call $update method
8+ * @param {object } store
9+ * @param {object } params
10+ */
11+ static async call ( { state, commit } , params = { } ) {
12+ if ( ! params . data || typeof params !== 'object' ) {
13+ throw new TypeError ( "You must include a data object in the params to send a POST request" , params )
14+ }
15+
16+ const context = Context . getInstance ( ) ;
17+ const model = context . getModelFromState ( state ) ;
18+ const endpoint = Action . transformParams ( '$update' , model , params ) ;
19+ const axios = new Axios ( model . methodConf . http ) ;
20+ const request = axios . put ( endpoint , params . data ) ;
21+
22+ request
23+ . then ( data => {
24+ model . update ( {
25+ where : data . id ,
26+ data
27+ } )
28+ } )
29+
30+ return request ;
631 }
732}
You can’t perform that action at this time.
0 commit comments