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 Create extends Action {
4- static call ( { state, dispatch } , params = { } ) {
5- // console.log(state, dispatch, params);
6+ /**
7+ * Call $create 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 ( '$create' , model , params ) ;
19+ const axios = new Axios ( model . methodConf . http ) ;
20+ const request = axios . post ( endpoint , params . data ) ;
21+
22+ commit ( 'onRequest' ) ;
23+ request
24+ . then ( data => {
25+ commit ( 'onSuccess' )
26+ model . insertOrUpdate ( {
27+ data,
28+ } ) ;
29+ } )
30+ . catch ( error => commit ( 'onError' , error ) )
31+
32+ return request ;
633 }
734}
You can’t perform that action at this time.
0 commit comments