Extract action for API calls
This commit is contained in:
parent
0e438e0244
commit
0b1f673c05
@ -39,14 +39,7 @@ export default {
|
||||
let formData = new FormData();
|
||||
formData.append("transactions", this.$data.transactionsFile);
|
||||
formData.append("assignments", this.$data.assignmentsFile);
|
||||
|
||||
fetch('/api/v1/budget/'+this.$store.getters.CurrentBudget.ID+"/import/ynab", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + this.$store.state.Session.Token
|
||||
},
|
||||
body: formData}
|
||||
);
|
||||
this.$store.dispatch("YNAB", formData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,12 +51,32 @@ const store = createStore({
|
||||
commit(LOGIN_SUCCESS, x);
|
||||
this.$router.replace("/dashboard");
|
||||
})
|
||||
},
|
||||
YNAB({getters, dispatch}, formData) {
|
||||
return dispatch("POST", {path: "/budget/"+getters.CurrentBudget.ID+"/import/ynab", body: formData});
|
||||
},
|
||||
GET({getters}, {path}){
|
||||
return fetch("/api/v1" + path, {
|
||||
headers: getters.AuthHeaders,
|
||||
})
|
||||
},
|
||||
POST({getters}, {path, body}){
|
||||
return fetch("/api/v1" + path, {
|
||||
method: "POST",
|
||||
headers: getters.AuthHeaders,
|
||||
body: body,
|
||||
})
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
Budgets(state) {
|
||||
return state.Budgets || [];
|
||||
},
|
||||
AuthHeaders(state) {
|
||||
return {
|
||||
'Authorization': 'Bearer ' + state.Session.Token
|
||||
}
|
||||
}
|
||||
},
|
||||
modules: {
|
||||
dashboard
|
||||
|
Loading…
x
Reference in New Issue
Block a user