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