diff --git a/src/components/baruser/CreditLists.vue b/src/components/baruser/CreditLists.vue index d521dfa..4a0fc08 100644 --- a/src/components/baruser/CreditLists.vue +++ b/src/components/baruser/CreditLists.vue @@ -11,17 +11,17 @@ - 2 € - 1 € - 0,50 € @@ -29,19 +29,19 @@ - 0,40 € - 0,20 € - 0,10 € @@ -67,30 +67,35 @@ diff --git a/src/components/baruser/SearchBar.vue b/src/components/baruser/SearchBar.vue index 1735cbe..14d75e6 100644 --- a/src/components/baruser/SearchBar.vue +++ b/src/components/baruser/SearchBar.vue @@ -13,7 +13,7 @@ diff --git a/src/components/finanzer/User.vue b/src/components/finanzer/User.vue index 3e0d11a..452484a 100644 --- a/src/components/finanzer/User.vue +++ b/src/components/finanzer/User.vue @@ -134,7 +134,12 @@ this.autoLock = {value: this.activeUser.autoLock, text: this.activeUser.autoLock? "Aktiviert" : "Deaktiviert"} }, methods: { - ...mapActions(['finanzerUsers/addAmount', 'finanzerUsers/addCredit', 'finanzerUsers/sendMail', 'finanzerUsers/doLock', 'finanzerUsers/saveConfig']), + ...mapActions({ + addAmount: 'finanzerUsers/addAmount', + addCredit: 'finanzerUsers/addCredit', + sendMail: 'finanzerUsers/sendMail', + doLock: 'finanzerUsers/doLock', + saveConfig: 'finanzerUsers/saveConfig'}), getLastColor (value) { return value < 0 ? 'red' : 'green' }, diff --git a/src/plugins/restService.js b/src/plugins/restService.js deleted file mode 100644 index 01a694f..0000000 --- a/src/plugins/restService.js +++ /dev/null @@ -1,57 +0,0 @@ -import axios from 'axios' - -class Service { - constructor(url) { - this.url = url - } - getFinanzerMain(token) { - return axios.get(this.url + "getFinanzerMain", {headers: {Token: token}}) - - } - login(loginData) { - return axios.post(this.url+'login', {...loginData}) - } - getUserBar(token) { - return axios.get(this.url+'bar', {headers: {Token: token}}) - } - getOneUserBar(token, data) { - return axios.post(this.url+'barGetUser', {...data}, {headers: {Token: token}}) - } - addAmountBar(token, data) { - return axios.post(this.url+'baradd', {...data}, {headers: {Token: token}}) - } - addAmountFinanzer(token, data) { - return axios.post(this.url+'finanzerAddAmount', {...data}, {headers: {Token: token}}) - } - addCreditFinanzer(token, data) { - return axios.post(this.url+'finanzerAddCredit', {...data}, {headers: {Token: token}}) - } - searchUser(token, data) { - return axios.post(this.url+'search', {...data}, {headers: {Token: token}}) - } - getAllUser(token) { - return axios.get(this.url+'barGetUsers', {headers: {Token: token}}) - } - lockUser(token, data) { - return axios.post(this.url+'finanzerLock', {...data}, {headers: {Token: token}}) - } - finanzerSetConfig(token, data) { - return axios.post(this.url+'finanzerSetConfig', {...data}, {headers: {Token: token}}) - } - finanzerAddUser(token, data) { - return axios.post(this.url+'finanzerAddUser', {...data}, {headers: {Token: token}}) - } - finanzerSendAllMail(token) { - return axios.get(this.url+"finanzerSendAllMail", {headers: {Token: token}}) - } - finanzerSendOneMail(token, data) { - return axios.post(this.url+"finanzerSendOneMail", {...data}, {headers: {Token: token}}) - } -} - -//const httpClient = new Service("http://localhost:5000/") -const httpClient = new Service("http://192.168.5.118:5000/") -//const httpClient = new Service("http://192.168.5.128:5000/") -//const httpClient = new Service("http://groeger-clan.duckdns.org:5000/") - -export default httpClient diff --git a/src/store/modules/barUsers.js b/src/store/modules/barUsers.js index 21485f7..e6b7d1e 100644 --- a/src/store/modules/barUsers.js +++ b/src/store/modules/barUsers.js @@ -1,26 +1,109 @@ -//import axios from 'axios'; -//import url from '@/plugins/routes'; +import axios from 'axios'; +import url from '@/plugins/routes'; const state = { - users: null + users: [], + allUsers: [] }; const mutations = { + setAllUsers: (state, users) => { + state.allUsers = [] + state.allUsers = users + for (let i = 0; i < state.allUsers.length; i++) { + state.allUsers[i].fullName = state.allUsers[i].firstname + " " + state.allUsers[i].lastname + } + }, + setUsers: (state, users) => { + // eslint-disable-next-line no-console + console.log(users) + for (let user in users) { + // eslint-disable-next-line no-console + console.log(user) + let existuser = state.users.find(a => {return user === a.username}) + + if (existuser) { + existuser.sername = users[user].username + existuser.firstname = users[user].firstname + existuser.lastname = users[user].lastname + existuser.locked = users[user].locked + existuser.amount = users[user].amount + existuser.type = users[user].type + } else { + state.users.push({ + username: users[user].username, + firstname: users[user].firstname, + lastname: users[user].lastname, + locked: users[user].locked, + amount: users[user].amount, + type: users[user].type + }) + } + } + // eslint-disable-next-line no-console + console.log(state.users) + mutations.sortUsers(state) + }, + sortUsers: (state) => { + state.users = state.users.sort((a,b) => { + if (a.lastname > b.lastname) return 1 + if (a.lastname < b.lastname) return -1 + if (a.firstname > b.firstname) return 1 + if (a.firstname < b.firstname) return -1 + return 0 + }) + }, }; const actions = { // eslint-disable-next-line no-unused-vars async getUsers({commit, rootState, dispatch}) { - // try { - // const response = await axios.get(url) - // } + try { + const response = await axios.get(url.bar, {headers: {Token: rootState.login.user.accessToken}}) + // eslint-disable-next-line no-console + console.log(response.data) + commit('setUsers', response.data) + } catch (e) { + if (e.response) if (e.response.status === 401) dispatch('logout', null, {root: true}) + } + }, + async addAmount({commit, rootState, dispatch}, data) { + try { + const response = await axios.post(url.barAddAmount, {userId: data.username, amount: data.amount}, {headers: {Token: rootState.login.user.accessToken}}) + commit('setUsers', {[response.data.username]: response.data}) + } catch (e) { + if (e.response) if (e.response.status === 401) dispatch('logout', null, {root: true}) + } + }, + async addCreditList({commit, rootState, dispatch}, data) { + try { + const response = await axios.post(url.barGetUser, {userId: data.username}, {headers: {Token: rootState.login.user.accessToken}}) + commit('setUsers', {[response.data.username]: response.data}) + } catch (e) { + if (e.response) if (e.response.status === 401) dispatch('logout', null, {root: true}) + } + }, + async getAllUsers({commit, rootState, dispatch}) { + // eslint-disable-next-line no-console + console.log('hier bin ich') + try { + const response = await axios.post(url.searchUser, {searchString: ""}, {headers: {Token: rootState.login.user.accessToken}}) + // eslint-disable-next-line no-console + console.log(response) + commit('setAllUsers', response.data) + } catch (e) { + // eslint-disable-next-line no-console + console.log(e) + if (e.response) if (e.response.data === 401) dispatch('logout', null, {root: true}) + } } }; const getters = { - + users: (state) => { return state.users }, + allUsers: (state) => { return state.allUsers } }; export default { diff --git a/src/store/modules/finanzerUsers.js b/src/store/modules/finanzerUsers.js index 9a5de7c..f3b50fb 100644 --- a/src/store/modules/finanzerUsers.js +++ b/src/store/modules/finanzerUsers.js @@ -200,7 +200,7 @@ const actions = { commit('setAllUsers', response.data) } catch (err) { // eslint-disable-next-line no-console - if (err.response.status === 401) dispatch('logout', null, {root: true}) + if (err.response) if (err.response.status === 401) dispatch('logout', null, {root: true}) } }, async getUsers({commit, rootState, dispatch}) { diff --git a/src/views/BarView.vue b/src/views/BarView.vue index 0cfadd3..8ce1bba 100644 --- a/src/views/BarView.vue +++ b/src/views/BarView.vue @@ -2,8 +2,8 @@
- - + +
@@ -11,7 +11,6 @@