Use async await for createTimetrackAccount

This commit is contained in:
Marcel Schwarz 2020-07-26 03:25:55 +02:00
parent 5748cc8410
commit ee1f4c5222

View File

@ -35,36 +35,32 @@
</v-container> </v-container>
</template> </template>
<script> <script>
import {BASE_URI} from "../globals"; import {BASE_URI} from "../globals"
import axios from "axios" import axios from "axios"
export default { export default {
name: "CreateTimeTrackAccount", name: "CreateTimeTrackAccount",
data: () => ({ data() {
return {
user: sessionStorage.getItem("timeTrackAccountListUserId"), user: sessionStorage.getItem("timeTrackAccountListUserId"),
accountData: {name: "", revenue: "", description: ""} accountData: {name: "", revenue: "", description: ""}
}), }
},
methods: { methods: {
addAccount() { async addAccount() {
if (Object.values(this.accountData).every(data => data)) { if (Object.values(this.accountData).every(data => data)) {
let postData = { let postData = {
user: this.user, user: this.user,
...this.accountData ...this.accountData
} }
let config = { try {
headers: { await axios.post(BASE_URI + "/accounts", postData)
'Authorization': sessionStorage.getItem("jwt") await this.$router.push("/timetrackaccounts")
} } catch (err) {
}
axios.post(BASE_URI + "/accounts", postData, config)
.then(() => {
this.$router.push("/timetrackaccounts")
})
.catch(err => {
console.log("Error " + err) console.log("Error " + err)
}) }
} }
}, },
} }
}; }
</script> </script>