diff options
Diffstat (limited to 'src/js/store/modules/comments.js')
-rw-r--r-- | src/js/store/modules/comments.js | 56 |
1 files changed, 26 insertions, 30 deletions
diff --git a/src/js/store/modules/comments.js b/src/js/store/modules/comments.js index 7595ee8e..f54ab2ce 100644 --- a/src/js/store/modules/comments.js +++ b/src/js/store/modules/comments.js @@ -62,7 +62,7 @@ const getters = { } const actions = { - list(context) { + async list(context) { let endPoint = 'apps/polls' if (context.rootState.route.name === 'publicVote') { @@ -76,17 +76,15 @@ const actions = { return } - return axios.get(generateUrl(endPoint + '/comments')) - .then((response) => { - context.commit('set', response.data) - }) - .catch(() => { - context.commit('reset') - }) - + try { + const response = await axios.get(generateUrl(endPoint + '/comments')) + context.commit('set', response.data) + } catch (e) { + context.commit('reset') + } }, - add(context, payload) { + async add(context, payload) { let endPoint = 'apps/polls' if (context.rootState.route.name === 'publicVote') { @@ -100,35 +98,33 @@ const actions = { return } - return axios.post(generateUrl(endPoint + '/comment'), { - message: payload.message, - }) - .then((response) => { - context.commit('add', { comment: response.data.comment }) - return response.data - }) - .catch((error) => { - console.error('Error writing comment', { error: error.response }, { payload: payload }) - throw error + try { + const response = await axios.post(generateUrl(endPoint + '/comment'), { + message: payload.message, }) + context.commit('add', { comment: response.data.comment }) + return response.data + } catch (e) { + console.error('Error writing comment', { error: e.response }, { payload: payload }) + throw e + } }, - delete(context, payload) { + async delete(context, payload) { let endPoint = 'apps/polls' if (context.rootState.route.name === 'publicVote') { endPoint = endPoint + '/s/' + context.rootState.route.params.token } - return axios.delete(generateUrl(endPoint + '/comment/' + payload.comment.id)) - .then((response) => { - context.commit('delete', { comment: payload.comment }) - return response.data - }) - .catch((error) => { - console.error('Error deleting comment', { error: error.response }, { payload: payload }) - throw error - }) + try { + const response = await axios.delete(generateUrl(endPoint + '/comment/' + payload.comment.id)) + context.commit('delete', { comment: payload.comment }) + return response.data + } catch (e) { + console.error('Error deleting comment', { error: e.response }, { payload: payload }) + throw e + } }, } |