Skip to content

Commit b953541

Browse files
committed
Added Update Method
1 parent fc892c9 commit b953541

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

src/actions/Update.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
1+
import Axios from '../orm/axios';
12
import Action from './Action'
3+
import Context from '../common/context'
24

35
export 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
}

0 commit comments

Comments
 (0)