From 9e32270f1026cf0c666b3da636a5272abdb1d532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sat, 21 Dec 2019 13:16:37 +0100 Subject: [PATCH] baruser cann add amount to a user --- src/components/baruser/CreditLists.vue | 14 +++++++++++--- src/plugins/restService.js | 4 +++- src/views/BarView.vue | 26 +++++++++++++++++--------- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/components/baruser/CreditLists.vue b/src/components/baruser/CreditLists.vue index 795ee0a..3c5bf21 100644 --- a/src/components/baruser/CreditLists.vue +++ b/src/components/baruser/CreditLists.vue @@ -1,7 +1,7 @@ diff --git a/src/plugins/restService.js b/src/plugins/restService.js index 15a1e01..376f79b 100644 --- a/src/plugins/restService.js +++ b/src/plugins/restService.js @@ -15,7 +15,9 @@ class Service { return axios.get(this.url+'bar', {headers: {Token: token}}) } addAmountBar(token, data) { - return axios.post(this.url+'baradd', ...data, {headers: {Token: token}}) + // eslint-disable-next-line no-console + console.log("addAmountdata: ", data) + return axios.post(this.url+'baradd', {...data}, {headers: {Token: token}}) } } diff --git a/src/views/BarView.vue b/src/views/BarView.vue index a9cf34c..cbdc99e 100644 --- a/src/views/BarView.vue +++ b/src/views/BarView.vue @@ -9,6 +9,7 @@ import TitleBar from "@/components/TitleBar"; import CreditLists from "@/components/baruser/CreditLists"; import httpClient from "../plugins/restService"; + // eslint-disable-next-line no-unused-vars import axios from "axios"; export default { name: "BarView", @@ -24,6 +25,7 @@ methods: { getUser() { // eslint-disable-next-line no-console + this. users = [] httpClient.getUserBar(this.$store.getters.getToken) .then(response => { // eslint-disable-next-line no-console @@ -35,27 +37,33 @@ username: response.data[user].username, firstname: response.data[user].firstname, lastname: response.data[user].lastname, - amount: response.data[user].amount + amount: response.data[user].amount, + type: response.data[user].type }) } }) .catch(error => { // eslint-disable-next-line no-console console.log(error) + this.$store.dispatch("logout") this.users = [] }) }, + // eslint-disable-next-line no-unused-vars addAmount(username, amount) { - axios.post('http://192.168.5.118:5000/baradd', {userId: username, amount: amount}, {headers: {Token: this.$store.getters.getToken}}) - //httpClient.addAmountBar(this.$store.getters.getToken, {username: username, amount: amount}) - /*.then(response => { + httpClient.addAmountBar(this.$store.getters.getToken, {userId: username, amount: amount}) + .then((response) => { + // eslint-disable-next-line no-console - console.log("responsedata: ", response.data) + console.log(response.data) + + let user = this.users.find(user => { + // eslint-disable-next-line no-console + console.log(user) + return user.username === username ? user : false + }) + user.amount = response.data.amount }) - .catch(error => { - // eslint-disable-next-line no-console - console.log("error: ", error.response.data.error) - })*/ } } }