Only safe transaction if user owns it

This commit is contained in:
Ferdinand Thiessen 2021-01-29 23:03:05 +01:00
parent b4c080fec6
commit bda5602e9f
1 changed files with 10 additions and 3 deletions

View File

@ -1,5 +1,5 @@
import { Module, MutationTree, ActionTree, GetterTree } from 'vuex';
import { StateInterface } from 'src/store';
import store, { StateInterface } from 'src/store';
import { axios } from 'src/boot/axios';
import { AxiosResponse } from 'axios';
@ -170,14 +170,21 @@ const actions: ActionTree<BalanceInterface, StateInterface> = {
dispatch('getBalance').catch(err => console.warn(err));
});
},
changeBalance({ dispatch, commit }, data: { amount: number; user: string; sender?: string }) {
changeBalance(
{ dispatch, commit, rootState },
data: { amount: number; user: string; sender?: string }
) {
commit('setLoading');
return axios
.put(`/users/${data.user}/balance`, data)
.then((response: AxiosResponse<FG.Transaction>) => {
const transaction = response.data;
fixTransaction(transaction);
commit('addTransaction', transaction);
if (
data.user == rootState.user.currentUser?.userid ||
data.sender === rootState.user.currentUser?.userid
)
commit('addTransaction', transaction);
commit(state.balances.has(data.user) ? 'changeBalance' : 'setBalance', {
userid: data.user,
amount: data.amount