From d6d5ea8853a7509a620baceac3645b95a1632087 Mon Sep 17 00:00:00 2001 From: lukassxp Date: Tue, 26 Nov 2019 15:26:48 -0300 Subject: [PATCH] refactored api calls to use async await syntax --- src/components/Revision/AddRevision.vue | 82 +++++++++++----------- src/components/Revision/DeleteRevision.vue | 76 +++++++++++--------- src/components/Revision/EditRevision.vue | 69 ++++++++++-------- src/components/Revision/Revision.vue | 22 +++--- 4 files changed, 135 insertions(+), 114 deletions(-) diff --git a/src/components/Revision/AddRevision.vue b/src/components/Revision/AddRevision.vue index c3dc34ff..2159fb5b 100644 --- a/src/components/Revision/AddRevision.vue +++ b/src/components/Revision/AddRevision.vue @@ -1,19 +1,20 @@ diff --git a/src/components/Revision/DeleteRevision.vue b/src/components/Revision/DeleteRevision.vue index 8550aad6..e5155b66 100644 --- a/src/components/Revision/DeleteRevision.vue +++ b/src/components/Revision/DeleteRevision.vue @@ -1,27 +1,38 @@ diff --git a/src/components/Revision/EditRevision.vue b/src/components/Revision/EditRevision.vue index 6e3808be..4cb98e9f 100644 --- a/src/components/Revision/EditRevision.vue +++ b/src/components/Revision/EditRevision.vue @@ -1,19 +1,20 @@ diff --git a/src/components/Revision/Revision.vue b/src/components/Revision/Revision.vue index c8682d94..1c1e9355 100644 --- a/src/components/Revision/Revision.vue +++ b/src/components/Revision/Revision.vue @@ -45,7 +45,7 @@ import { mapState } from 'vuex'; import ListRevision from './ListRevision.vue'; import DeleteRevision from './DeleteRevision.vue'; import EditRevision from './EditRevision.vue'; -import { HTTP } from '../../http-common'; +import { HTTP as api } from '../../http-common'; export default { name: 'Revision', @@ -70,17 +70,19 @@ export default { }, methods: { - getRevision() { + async getRevision() { const headers = { Authorization: this.token }; - HTTP.get(`revisions/${this.$route.params.id}`, { headers }) - .then((response) => { - this.doneReport = response.data.done_report, - this.undoneReport = response.data.undone_report; - }) - .catch((e) => { - this.errors.push(e); - }); + try { + const response = await api.get( + `revisions/${this.$route.params.id}`, + { headers } + ); + this.doneReport = response.data.done_report; + this.undoneReport = response.data.undone_report; + } catch(err) { + this.errors.push(err); + } }, },