Balance Admin: Load all balances

This commit is contained in:
Ferdinand Thiessen 2021-01-29 23:29:38 +01:00
parent c9d8365def
commit 008d40b56a
2 changed files with 32 additions and 18 deletions

View File

@ -11,25 +11,24 @@
</template>
<script lang="ts">
// TODO: Load all users / balances
// TODO: Fill usefull data
import { computed, defineComponent } from '@vue/composition-api';
import { StateInterfaceBalance } from '../store/balance';
import { ref, defineComponent, onMounted } from '@vue/composition-api';
import { StateInterfaceBalance, BalancesResponse } from '../store/balance';
import { Store } from 'vuex';
export default defineComponent({
// name: 'PageName'
setup(_, { root }) {
const store = <Store<StateInterfaceBalance>>root.$store;
const rows = computed(() => {
const fo: Array<{ userid: string; balance: number }> = [];
store.state.balance.balances.forEach((value, key) =>
fo.push(Object.assign(value, { userid: key }))
);
return fo;
});
onMounted(
() =>
void store
.dispatch('balance/getBalances')
.then((balances: Array<BalancesResponse>) => rows.value.push(...balances))
);
const rows = ref(new Array<BalancesResponse>());
const columns = [
{
@ -41,16 +40,22 @@ export default defineComponent({
sortable: true
},
{
name: 'balance',
label: 'Kontostand',
field: 'balance',
name: 'credit',
label: 'Haben',
field: 'credit',
format: (val: number) => val.toFixed(2)
},
{
name: 'limit',
label: 'Limit',
field: 'limit',
format: (val: number) => (val === null ? 'keins' : val)
name: 'debit',
label: 'Soll',
field: 'debit',
format: (val: number) => val.toFixed(2)
},
{
name: 'balance',
label: 'Kontostand',
format: (_: undefined, row: { debit: number; credit: number }) =>
(row.credit - row.debit).toFixed(2)
}
];
return { rows, columns };

View File

@ -9,6 +9,10 @@ interface BalanceResponse {
debit: number;
}
export interface BalancesResponse extends BalanceResponse {
userid: string;
}
export interface TransactionsResponse {
transactions: Array<FG.Transaction>;
count?: number;
@ -122,6 +126,11 @@ const actions: ActionTree<BalanceInterface, StateInterface> = {
})
.finally(() => commit('setLoading', false));
},
getBalances() {
return axios.get('/balance').then(({ data }: AxiosResponse<Array<BalancesResponse>>) => {
return data;
});
},
getTransactions(
{ commit, rootState },
payload: {