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