diff --git a/src/boot/plugins.ts b/src/boot/plugins.ts index 8725881..7bcd890 100644 --- a/src/boot/plugins.ts +++ b/src/boot/plugins.ts @@ -1,6 +1,6 @@ import { boot } from 'quasar/wrappers'; import { RouteConfig } from 'vue-router'; -import { Module, Store } from 'vuex'; +import { Store } from 'vuex'; import { StateInterface } from 'src/store'; import { FG_Plugin } from 'src/plugins'; import routes from 'src/router/routes'; diff --git a/src/components/navigation/EssentialLink.vue b/src/components/navigation/EssentialLink.vue index 601a75f..5e13044 100644 --- a/src/components/navigation/EssentialLink.vue +++ b/src/components/navigation/EssentialLink.vue @@ -1,22 +1,28 @@ - + - + {{ realTitle }} - - {{ permissions }} - + diff --git a/src/components/navigation/ShortCutLink.vue b/src/components/navigation/ShortCutLink.vue index 17a4af4..85e7807 100644 --- a/src/components/navigation/ShortCutLink.vue +++ b/src/components/navigation/ShortCutLink.vue @@ -1,11 +1,12 @@ - + diff --git a/src/plugins/balance/pages/Add.vue b/src/plugins/balance/pages/Add.vue index 76a3a3a..65862e4 100644 --- a/src/plugins/balance/pages/Add.vue +++ b/src/plugins/balance/pages/Add.vue @@ -1,12 +1,95 @@ - Add works + + + + + + + + + + + + + + + + + + + + + + + {{ balance.toFixed(2) }} € + + + + + diff --git a/src/plugins/balance/plugin.ts b/src/plugins/balance/plugin.ts index cb5dd38..7a7a9d1 100644 --- a/src/plugins/balance/plugin.ts +++ b/src/plugins/balance/plugin.ts @@ -1,13 +1,17 @@ -import {Module} from 'vuex'; -import {StateInterface} from "src/store"; -import mainRoutes from "./routes" +import { Module } from 'vuex'; +import { StateInterface } from 'src/store'; +import mainRoutes from './routes'; import { FG_Plugin } from 'src/plugins'; +import balance, { BalanceInterface } from './store/balance'; const plugin: FG_Plugin.Plugin = { name: 'Balance', mainRoutes, requiredModules: ['User'], version: '0.0.1', -} + store: new Map>([ + ['balance', balance] + ]) +}; export default plugin; diff --git a/src/plugins/balance/routes/index.ts b/src/plugins/balance/routes/index.ts index 2014716..2639c7c 100644 --- a/src/plugins/balance/routes/index.ts +++ b/src/plugins/balance/routes/index.ts @@ -1,22 +1,22 @@ -import {FG_Plugin} from 'src/plugins'; +import { FG_Plugin } from 'src/plugins'; const permissions = { -// Show own and others balance - SHOW: "balance_show", - SHOW_OTHER: "balance_show_others", -// Credit balance - ADD: "balance_add", -// Debit balance - SUB: "balance_sub", -// Send from to other - SEND: "balance_send", -// Send from other to another - SEND_OTHER: "balance_send_others", -// Can set limit for users - SET_LIMIT: "balance_set_limit", -//Allow sending / sub while exceeding the set limit - EXCEED_LIMIT: "balance_exceed_limit" -} + // Show own and others balance + SHOW: 'balance_show', + SHOW_OTHER: 'balance_show_others', + // Credit balance + ADD: 'balance_add', + // Debit balance + SUB: 'balance_sub', + // Send from to other + SEND: 'balance_send', + // Send from other to another + SEND_OTHER: 'balance_send_others', + // Can set limit for users + SET_LIMIT: 'balance_set_limit', + //Allow sending / sub while exceeding the set limit + EXCEED_LIMIT: 'balance_exceed_limit' +}; const mainRoutes: FG_Plugin.PluginRouteConfig[] = [ { @@ -25,7 +25,7 @@ const mainRoutes: FG_Plugin.PluginRouteConfig[] = [ path: 'balance', name: 'balance', component: () => import('../pages/MainPage.vue'), - meta: {permissions: ['user']}, + meta: { permissions: ['user'] }, children: [ { title: 'Anschreiben', @@ -33,11 +33,11 @@ const mainRoutes: FG_Plugin.PluginRouteConfig[] = [ path: 'balance-add', name: 'balance-add', shortcut: true, - meta: {permissions: [permissions.ADD, permissions.SHOW]}, + meta: { permissions: [permissions.SUB, permissions.SHOW] }, component: () => import('../pages/Add.vue') } ] } -] +]; -export default mainRoutes +export default mainRoutes; diff --git a/src/plugins/balance/store/balance.ts b/src/plugins/balance/store/balance.ts new file mode 100644 index 0000000..5b7b49d --- /dev/null +++ b/src/plugins/balance/store/balance.ts @@ -0,0 +1,83 @@ +import { Module, MutationTree, ActionTree, GetterTree } from 'vuex'; +import { StateInterface } from 'src/store'; +import { axios } from 'src/boot/axios'; +import { AxiosResponse } from 'axios'; + +interface BalanceResponse { + balance: number; + credit: number; + debit: number; +} + +export interface BalanceInterface extends BalanceResponse { + limit: number; +} + +const state: BalanceInterface = { + balance: 0, + credit: 0, + debit: 0, + limit: 0 +}; + +const mutations: MutationTree = { + setBalance(state, data: number) { + state.balance = data; + }, + setCredit(state, data: number) { + state.credit = data; + }, + setDebit(state, data: number) { + state.debit = data; + }, + setLimit(state, data: number) { + state.limit = data; + } +}; + +const actions: ActionTree = { + getBalance({ commit, rootState }) { + axios + .get(`/users/${rootState.user.user.userid}/balance`) + .then(({ data }: AxiosResponse) => { + commit('setBalance', data.balance); + commit('setCredit', data.credit); + commit('setDebit', data.debit); + }) + .catch(err => { + console.warn(err); + }); + }, + getLimit({ rootState }) { + axios + .get(`/users/${rootState.user.user.userid}/balance/limit`) + .then(({ data }) => { + console.log(data); + }) + .catch(err => { + console.warn(err); + }); + }, + changeBalance({ rootState, dispatch }, amount: number) { + axios + .put(`/users/${rootState.user.user.userid}/balance`, <{ amount: number }>{ + amount: amount + }) + .then(() => { + dispatch('getBalance').catch(err => console.warn(err)); + }) + .catch(err => console.warn(err)); + } +}; + +const getters: GetterTree = {}; + +const balance: Module = { + namespaced: true, + state, + mutations, + actions, + getters +}; + +export default balance;