Signed-off-by: dartcafe <github@dartcafe.de>
This commit is contained in:
dartcafe 2021-02-27 13:03:54 +01:00
Родитель 79929fe6f8
Коммит 4d422a37f3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: CCE73CEF3035D3C8
10 изменённых файлов: 326 добавлений и 401 удалений

Просмотреть файл

@ -62,7 +62,7 @@ const getters = {
} }
const actions = { const actions = {
list(context) { async list(context) {
let endPoint = 'apps/polls' let endPoint = 'apps/polls'
if (context.rootState.route.name === 'publicVote') { if (context.rootState.route.name === 'publicVote') {
@ -76,17 +76,15 @@ const actions = {
return return
} }
return axios.get(generateUrl(endPoint + '/comments')) try {
.then((response) => { const response = await axios.get(generateUrl(endPoint + '/comments'))
context.commit('set', response.data) context.commit('set', response.data)
}) } catch (e) {
.catch(() => { context.commit('reset')
context.commit('reset') }
})
}, },
add(context, payload) { async add(context, payload) {
let endPoint = 'apps/polls' let endPoint = 'apps/polls'
if (context.rootState.route.name === 'publicVote') { if (context.rootState.route.name === 'publicVote') {
@ -100,35 +98,33 @@ const actions = {
return return
} }
return axios.post(generateUrl(endPoint + '/comment'), { try {
message: payload.message, const response = await 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
}) })
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' let endPoint = 'apps/polls'
if (context.rootState.route.name === 'publicVote') { if (context.rootState.route.name === 'publicVote') {
endPoint = endPoint + '/s/' + context.rootState.route.params.token endPoint = endPoint + '/s/' + context.rootState.route.params.token
} }
return axios.delete(generateUrl(endPoint + '/comment/' + payload.comment.id)) try {
.then((response) => { const response = await axios.delete(generateUrl(endPoint + '/comment/' + payload.comment.id))
context.commit('delete', { comment: payload.comment }) context.commit('delete', { comment: payload.comment })
return response.data return response.data
}) } catch (e) {
.catch((error) => { console.error('Error deleting comment', { error: e.response }, { payload: payload })
console.error('Error deleting comment', { error: error.response }, { payload: payload }) throw e
throw error }
})
}, },
} }

Просмотреть файл

@ -119,7 +119,7 @@ const getters = {
const actions = { const actions = {
list(context) { async list(context) {
let endPoint = 'apps/polls' let endPoint = 'apps/polls'
if (context.rootState.route.name === 'publicVote') { if (context.rootState.route.name === 'publicVote') {
endPoint = endPoint + '/s/' + context.rootState.route.params.token endPoint = endPoint + '/s/' + context.rootState.route.params.token
@ -132,127 +132,112 @@ const actions = {
return return
} }
return axios.get(generateUrl(endPoint + '/options')) try {
.then((response) => { const response = await axios.get(generateUrl(endPoint + '/options'))
context.commit('set', { options: response.data.options }) context.commit('set', { options: response.data.options })
}) } catch (e) {
.catch((error) => { console.error('Error loding options', { error: e.response }, { pollId: context.rootState.route.params.id })
console.error('Error loding options', { error: error.response }, { pollId: context.rootState.route.params.id }) throw e
throw error }
})
}, },
add(context, payload) { async add(context, payload) {
const endPoint = 'apps/polls/option' const endPoint = 'apps/polls/option'
return axios.post(generateUrl(endPoint), { try {
pollId: context.rootState.route.params.id, const response = await axios.post(generateUrl(endPoint), {
timestamp: payload.timestamp, pollId: context.rootState.route.params.id,
pollOptionText: payload.pollOptionText, timestamp: payload.timestamp,
duration: payload.duration, pollOptionText: payload.pollOptionText,
}) duration: payload.duration,
.then((response) => {
context.commit('setItem', { option: response.data.option })
})
.catch((error) => {
console.error('Error adding option: ' + error.response.data, { error: error.response }, { payload: payload })
context.dispatch('list')
throw error
}) })
context.commit('setItem', { option: response.data.option })
} catch (e) {
console.error('Error adding option: ' + e.response.data, { error: e.response }, { payload: payload })
context.dispatch('list')
throw e
}
}, },
update(context, payload) { async update(context, payload) {
const endPoint = 'apps/polls/option' const endPoint = 'apps/polls/option'
return axios.put(generateUrl(endPoint + '/' + payload.option.id), { try {
timestamp: payload.option.timestamp, const response = await axios.put(generateUrl(endPoint + '/' + payload.option.id), {
pollOptionText: payload.option.timeStamp, timestamp: payload.option.timestamp,
duration: payload.option.duration, pollOptionText: payload.option.timeStamp,
}) duration: payload.option.duration,
.then((response) => {
context.commit('setItem', { option: response.data.option })
})
.catch((error) => {
console.error('Error updating option', { error: error.response }, { payload: payload })
context.dispatch('list')
throw error
}) })
context.commit('setItem', { option: response.data.option })
} catch (e) {
console.error('Error updating option', { error: e.response }, { payload: payload })
context.dispatch('list')
throw e
}
}, },
delete(context, payload) { async delete(context, payload) {
const endPoint = 'apps/polls/option' const endPoint = 'apps/polls/option'
try {
return axios.delete(generateUrl(endPoint + '/' + payload.option.id)) await axios.delete(generateUrl(endPoint + '/' + payload.option.id))
.then((response) => { context.commit('delete', { option: payload.option })
context.commit('delete', { option: payload.option }) } catch (e) {
}) console.error('Error deleting option', { error: e.response }, { payload: payload })
.catch((error) => { context.dispatch('list')
console.error('Error deleting option', { error: error.response }, { payload: payload }) throw e
context.dispatch('list') }
throw error
})
}, },
confirm(context, payload) { async confirm(context, payload) {
context.commit('confirm', { option: payload.option }) context.commit('confirm', { option: payload.option })
const endPoint = 'apps/polls/option' const endPoint = 'apps/polls/option'
return axios.put(generateUrl(endPoint + '/' + payload.option.id + '/confirm')) try {
.then((response) => { const response = await axios.put(generateUrl(endPoint + '/' + payload.option.id + '/confirm'))
context.commit('setItem', { option: response.data.option }) context.commit('setItem', { option: response.data.option })
}) } catch (e) {
.catch((error) => { console.error('Error confirming option', { error: e.response }, { payload: payload })
console.error('Error confirming option', { error: error.response }, { payload: payload }) context.dispatch('list')
context.dispatch('list') throw e
throw error }
})
}, },
reorder(context, payload) { async reorder(context, payload) {
const endPoint = 'apps/polls/poll'
context.commit('reorder', { options: payload }) context.commit('reorder', { options: payload })
return axios.post(generateUrl(endPoint + '/' + context.rootState.route.params.id + '/options/reorder'), { const endPoint = 'apps/polls/poll'
options: payload, try {
}) const response = await axios.post(generateUrl(endPoint + '/' + context.rootState.route.params.id + '/options/reorder'), {
.then((response) => { options: payload,
context.commit('set', { options: response.data.options })
})
.catch((error) => {
console.error('Error reordering option', { error: error.response }, { payload: payload })
context.dispatch('list')
throw error
}) })
context.commit('set', { options: response.data.options })
} catch (e) {
console.error('Error reordering option', { error: e.response }, { payload: payload })
context.dispatch('list')
throw e
}
}, },
sequence(context, payload) { async sequence(context, payload) {
const endPoint = 'apps/polls/option' const endPoint = 'apps/polls/option'
return axios.post(generateUrl(endPoint + '/' + payload.option.id + '/sequence'), { try {
step: payload.sequence.step, const response = await axios.post(generateUrl(endPoint + '/' + payload.option.id + '/sequence'), {
unit: payload.sequence.unit.value, step: payload.sequence.step,
amount: payload.sequence.amount, unit: payload.sequence.unit.value,
}) amount: payload.sequence.amount,
.then((response) => {
context.commit('set', { options: response.data.options })
})
.catch((error) => {
console.error('Error creating sequence', { error: error.response }, { payload: payload })
context.dispatch('list')
throw error
}) })
context.commit('set', { options: response.data.options })
} catch (e) {
console.error('Error creating sequence', { error: e.response }, { payload: payload })
context.dispatch('list')
throw e
}
}, },
getEvents(context, payload) { async getEvents(context, payload) {
const endPoint = 'apps/polls/option' const endPoint = 'apps/polls/option'
return axios.get(generateUrl(endPoint + '/' + payload.option.id + '/events')) try {
.then((response) => { const response = await axios.get(generateUrl(endPoint + '/' + payload.option.id + '/events'))
return response.data return response.data
}) } catch (e) {
.catch((error) => { return { events: [] }
if (error.message === 'Network Error') { }
console.error('Got an ugly network error while loading calendar events', { error: error }, { payload: payload })
throw error
}
console.error('Error loading calendar events - start whistling and behave as if nothing happened', { error: error }, { payload: payload })
return { events: [] }
})
}, },
} }

Просмотреть файл

@ -132,7 +132,7 @@ const actions = {
context.commit('reset') context.commit('reset')
}, },
get(context) { async get(context) {
let endPoint = 'apps/polls' let endPoint = 'apps/polls'
if (context.rootState.route.name === 'publicVote') { if (context.rootState.route.name === 'publicVote') {
@ -144,88 +144,78 @@ const actions = {
context.commit('acl/reset') context.commit('acl/reset')
return return
} }
return axios.get(generateUrl(endPoint + '/poll')) try {
.then((response) => { const response = await axios.get(generateUrl(endPoint + '/poll'))
context.commit('set', response.data) context.commit('set', response.data)
context.commit('acl/set', response.data) context.commit('acl/set', response.data)
return response return response
}) } catch (e) {
.catch((error) => { console.debug('Error loading poll', { error: e.response })
console.debug('Error loading poll', { error: error.response }) throw e
throw error }
})
}, },
add(context, payload) { async add(context, payload) {
const endPoint = 'apps/polls/poll/add' const endPoint = 'apps/polls/poll/add'
return axios.post(generateUrl(endPoint), { title: payload.title, type: payload.type }) try {
.then((response) => { const response = await axios.post(generateUrl(endPoint), { title: payload.title, type: payload.type })
return response return response
}) } catch (e) {
.catch((error) => { console.error('Error adding poll:', { error: e.response }, { state: state })
console.error('Error adding poll:', { error: error.response }, { state: state }) throw e
throw error }
})
}, },
clone(context, payload) { async clone(context, payload) {
const endPoint = 'apps/polls/poll' const endPoint = 'apps/polls/poll'
return axios.get(generateUrl(endPoint + '/' + payload.pollId + '/clone')) try {
.then((response) => { const response = await axios.get(generateUrl(endPoint + '/' + payload.pollId + '/clone'))
return response.data return response.data
}) } catch (e) {
.catch((error) => { console.error('Error cloning poll', { error: e.response }, { payload: payload })
console.error('Error cloning poll', { error: error.response }, { payload: payload }) }
})
}, },
update(context) { async update(context) {
const endPoint = 'apps/polls/poll' const endPoint = 'apps/polls/poll'
return axios.put(generateUrl(endPoint + '/' + state.id), { poll: state }) try {
.then((response) => { const response = await axios.put(generateUrl(endPoint + '/' + state.id), { poll: state })
context.commit('set', { poll: response.data }) context.commit('set', { poll: response.data })
return response return response
}) } catch (e) {
.catch((error) => { console.error('Error updating poll:', { error: e.response }, { poll: state })
console.error('Error updating poll:', { error: error.response }, { poll: state }) throw e
throw error }
})
}, },
switchDeleted(context, payload) { async switchDeleted(context, payload) {
const endPoint = 'apps/polls/poll' const endPoint = 'apps/polls/poll'
return axios.put(generateUrl(endPoint + '/' + payload.pollId + '/switchDeleted')) try {
.then((response) => { const response = await axios.put(generateUrl(endPoint + '/' + payload.pollId + '/switchDeleted'))
return response return response
}) } catch (e) {
.catch((error) => { console.error('Error switching deleted status', { error: e.response }, { payload: payload })
console.error('Error switching deleted status', { error: error.response }, { payload: payload }) }
})
}, },
delete(context, payload) { async delete(context, payload) {
const endPoint = 'apps/polls/poll' const endPoint = 'apps/polls/poll'
return axios.delete(generateUrl(endPoint + '/' + payload.pollId)) try {
.then((response) => { const response = await axios.delete(generateUrl(endPoint + '/' + payload.pollId))
return response return response
}) } catch (e) {
.catch((error) => { console.error('Error deleting poll', { error: e.response }, { payload: payload })
console.error('Error deleting poll', { error: error.response }, { payload: payload }) }
})
}, },
getParticipantsEmailAddresses(context, payload) { async getParticipantsEmailAddresses(context, payload) {
const endPoint = 'apps/polls/poll' const endPoint = 'apps/polls/poll'
return axios.get(generateUrl(endPoint + '/' + payload.pollId + '/addresses')) try {
.then((response) => { const response = await axios.get(generateUrl(endPoint + '/' + payload.pollId + '/addresses'))
return response return response
}) } catch (e) {
.catch((error) => { console.error('Error retrieving email addresses', { error: e.response }, { payload: payload })
console.error('Error retrieving email addresses', { error: error.response }, { payload: payload }) }
})
}, },
} }

Просмотреть файл

@ -71,16 +71,15 @@ const getters = {
} }
const actions = { const actions = {
load(context) { async load(context) {
const endPoint = 'apps/polls/polls' const endPoint = 'apps/polls/polls'
return axios.get(generateUrl(endPoint)) try {
.then((response) => { const response = await axios.get(generateUrl(endPoint))
context.commit('set', { list: response.data }) context.commit('set', { list: response.data })
}) } catch (e) {
.catch((error) => { console.error('Error loading polls', { error: e.response })
console.error('Error loading polls', { error: error.response }) }
})
}, },
} }

Просмотреть файл

@ -44,29 +44,22 @@ const getters = {
} }
const actions = { const actions = {
load(context) { async load(context) {
const endPoint = 'apps/polls/administration' const endPoint = 'apps/polls/administration'
if (getCurrentUser().isAdmin) { if (getCurrentUser().isAdmin) {
return axios.get(generateUrl(endPoint + '/polls')) try {
.then((response) => { const response = await axios.get(generateUrl(endPoint + '/polls'))
context.commit('set', { list: response.data }) context.commit('set', { list: response.data })
}) } catch (e) {
.catch((error) => { console.error('Error loading polls', { error: e.response })
console.error('Error loading polls', { error: error.response }) }
})
} }
}, },
takeOver(context, payload) { async takeOver(context, payload) {
const endPoint = 'apps/polls/administration' const endPoint = 'apps/polls/administration'
if (getCurrentUser().isAdmin) { if (getCurrentUser().isAdmin) {
return axios.get(generateUrl(endPoint + '/poll/' + payload.pollId + '/takeover')) return await axios.get(generateUrl(endPoint + '/poll/' + payload.pollId + '/takeover'))
.then((response) => {
return response
})
.catch((error) => {
throw error
})
} }
}, },
} }

Просмотреть файл

@ -67,39 +67,33 @@ const mutations = {
} }
const actions = { const actions = {
get(context) { async get(context) {
const endPoint = 'apps/polls/preferences/get' const endPoint = 'apps/polls/preferences/get'
try {
return axios.get(generateUrl(endPoint)) const response = await axios.get(generateUrl(endPoint))
.then((response) => { console.debug('settings loaded ')
console.debug('settings loaded ') context.commit('setPreference', response.data.preferences)
context.commit('setPreference', response.data.preferences) } catch (e) {
}) context.commit('reset')
.catch(() => { }
context.commit('reset')
})
}, },
write(context) {
async write(context) {
const endPoint = 'apps/polls/preferences/write' const endPoint = 'apps/polls/preferences/write'
try {
return axios.post(generateUrl(endPoint), { settings: context.state.user }) const response = await axios.post(generateUrl(endPoint), { settings: context.state.user })
.then((response) => { context.commit('setPreference', response.data.preferences)
context.commit('setPreference', response.data.preferences) } catch (e) {
}) console.error('Error writing preferences', { error: e.response }, { preferences: state.user })
.catch((error) => { throw e
console.error('Error writing preferences', { error: error.response }, { preferences: state.user }) }
throw error
})
}, },
getCalendars(context) { async getCalendars(context) {
const endPoint = 'apps/polls/calendars' const endPoint = 'apps/polls/calendars'
const response = await axios.get(generateUrl(endPoint))
return axios.get(generateUrl(endPoint)) context.commit('setCalendars', { calendars: response.data.calendars })
.then((response) => { return response
context.commit('setCalendars', { calendars: response.data.calendars })
return response
})
}, },
} }

Просмотреть файл

@ -56,7 +56,7 @@ const mutations = {
} }
const actions = { const actions = {
get(context) { async get(context) {
let endPoint = 'apps/polls' let endPoint = 'apps/polls'
if (context.rootState.route.name === 'publicVote') { if (context.rootState.route.name === 'publicVote') {
endPoint = endPoint + '/s/' + context.rootState.route.params.token endPoint = endPoint + '/s/' + context.rootState.route.params.token
@ -64,77 +64,67 @@ const actions = {
context.commit('reset') context.commit('reset')
return return
} }
return axios.get(generateUrl(endPoint + '/share')) try {
.then((response) => { const response = await axios.get(generateUrl(endPoint + '/share'))
context.commit('set', { share: response.data.share }) context.commit('set', { share: response.data.share })
return response.data return response.data
}) } catch (e) {
.catch((error) => { console.debug('Error retrieving share', { error: e.response })
console.debug('Error retrieving share', { error: error.response }) throw e.response
throw error.response }
})
}, },
register(context, payload) { async register(context, payload) {
let endPoint = 'apps/polls' let endPoint = 'apps/polls'
if (context.rootState.route.name === 'publicVote') { if (context.rootState.route.name === 'publicVote') {
endPoint = endPoint + '/s/' + context.rootState.route.params.token endPoint = endPoint + '/s/' + context.rootState.route.params.token
} else { } else {
return return
} }
try {
return axios.post(generateUrl(endPoint + '/register'), { const response = await axios.post(generateUrl(endPoint + '/register'), {
userName: payload.userName, userName: payload.userName,
emailAddress: payload.emailAddress, emailAddress: payload.emailAddress,
})
.then((response) => {
return { token: response.data.share.token }
}) })
.catch((error) => { return { token: response.data.share.token }
console.error('Error writing personal share', { error: error.response }, { payload: payload }) } catch (e) {
throw error console.error('Error writing personal share', { error: e.response }, { payload: payload })
}) throw e
}
}, },
updateEmailAddress(context, payload) { async updateEmailAddress(context, payload) {
let endPoint = 'apps/polls' let endPoint = 'apps/polls'
if (context.rootState.route.name === 'publicVote') { if (context.rootState.route.name === 'publicVote') {
endPoint = endPoint + '/s/' + context.rootState.route.params.token endPoint = endPoint + '/s/' + context.rootState.route.params.token
} else { } else {
return return
} }
try {
return axios.put(generateUrl(endPoint + '/email'), { const response = await axios.put(generateUrl(endPoint + '/email'), {
emailAddress: payload.emailAddress, emailAddress: payload.emailAddress,
})
.then((response) => {
context.commit('set', { share: response.data.share })
return response.data
}) })
.catch((error) => { context.commit('set', { share: response.data.share })
console.error('Error writing email address', { error: error.response }, { payload: payload }) return response.data
throw error } catch (e) {
}) console.error('Error writing email address', { error: e.response }, { payload: payload })
throw e
}
}, },
resendInvitation(context, payload) { async resendInvitation(context, payload) {
let endPoint = 'apps/polls' let endPoint = 'apps/polls'
if (context.rootState.route.name === 'publicVote') { if (context.rootState.route.name === 'publicVote') {
endPoint = endPoint + '/s/' + context.rootState.route.params.token endPoint = endPoint + '/s/' + context.rootState.route.params.token
} else { } else {
return return
} }
try {
return axios.get(generateUrl(endPoint + '/resend')) return await axios.get(generateUrl(endPoint + '/resend'))
.then((response) => { } catch (e) {
return response console.error('Error sending invitation', { error: e.response }, { payload: payload })
}) throw e
.catch((error) => { }
console.error('Error sending invitation', { error: error.response }, { payload: payload })
throw error
})
}, },
} }

Просмотреть файл

@ -87,7 +87,7 @@ const getters = {
} }
const actions = { const actions = {
list(context) { async list(context) {
let endPoint = 'apps/polls' let endPoint = 'apps/polls'
if (context.rootState.route.name === 'vote') { if (context.rootState.route.name === 'vote') {
@ -98,77 +98,64 @@ const actions = {
context.commit('reset') context.commit('reset')
return return
} }
return axios.get(generateUrl(endPoint + '/shares')) try {
.then((response) => { const response = await axios.get(generateUrl(endPoint + '/shares'))
context.commit('set', response.data) context.commit('set', response.data)
return response.data return response.data
}) } catch (e) {
.catch((error) => { console.error('Error loading shares', { error: e.response }, { pollId: context.rootState.route.params.id })
console.error('Error loading shares', { error: error.response }, { pollId: context.rootState.route.params.id }) throw e
throw error }
})
}, },
add(context, payload) { async add(context, payload) {
const endPoint = 'apps/polls/poll/' + context.rootState.route.params.id const endPoint = 'apps/polls/poll/' + context.rootState.route.params.id
try {
return axios.post(generateUrl(endPoint + '/share'), payload.share) await axios.post(generateUrl(endPoint + '/share'), payload.share)
.then((response) => { } catch (e) {
return response.data console.error('Error writing share', { error: e.response }, { payload: payload })
}) throw e
.catch((error) => { } finally {
console.error('Error writing share', { error: error.response }, { payload: payload }) context.dispatch('list')
throw error }
})
.finally(() => {
context.dispatch('list')
})
}, },
delete(context, payload) { async delete(context, payload) {
const endPoint = 'apps/polls/share' const endPoint = 'apps/polls/share'
context.commit('delete', { share: payload.share }) context.commit('delete', { share: payload.share })
return axios.delete(generateUrl(endPoint + '/' + payload.share.token)) try {
.then((response) => { return await axios.delete(generateUrl(endPoint + '/' + payload.share.token))
return response } catch (e) {
}) console.error('Error removing share', { error: e.response }, { payload: payload })
.catch((error) => { throw e
console.error('Error removing share', { error: error.response }, { payload: payload }) } finally {
throw error context.dispatch('list')
}) }
.finally(() => {
context.dispatch('list')
})
}, },
sendInvitation(context, payload) { async sendInvitation(context, payload) {
const endPoint = 'apps/polls/share' const endPoint = 'apps/polls/share'
try {
return axios.post(generateUrl(endPoint + '/' + payload.share.token + '/invite')) return await axios.post(generateUrl(endPoint + '/' + payload.share.token + '/invite'))
.then((response) => { } catch (e) {
return response console.error('Error sending invitation', { error: e.response }, { payload: payload })
}) throw e
.catch((error) => { } finally {
console.error('Error sending invitation', { error: error.response }, { payload: payload }) context.dispatch('list')
throw error }
})
.finally(() => {
context.dispatch('list')
})
}, },
resolveGroup(context, payload) { async resolveGroup(context, payload) {
const endPoint = 'apps/polls/share' const endPoint = 'apps/polls/share'
try {
return axios.get(generateUrl(endPoint + '/' + payload.share.token + '/resolve')) return await axios.get(generateUrl(endPoint + '/' + payload.share.token + '/resolve'))
.catch((error) => { } catch (e) {
console.error('Error exploding group', error.response.data, { error: error.response }, { payload: payload }) console.error('Error exploding group', e.response.data, { error: e.response }, { payload: payload })
throw error throw e
}) } finally {
.finally(() => { context.dispatch('list')
context.dispatch('list') }
})
}, },
} }

Просмотреть файл

@ -44,7 +44,7 @@ const mutations = {
const actions = { const actions = {
get(context) { async get(context) {
let endPoint = 'apps/polls' let endPoint = 'apps/polls'
if (context.rootState.route.name === 'publicVote') { if (context.rootState.route.name === 'publicVote') {
@ -54,34 +54,29 @@ const actions = {
} else { } else {
return return
} }
try {
return axios.get(generateUrl(endPoint + '/subscription')) const response = await axios.get(generateUrl(endPoint + '/subscription'))
.then((response) => { context.commit('set', response.data)
context.commit('set', response.data) } catch (e) {
}) context.commit('set', false)
.catch(() => { }
context.commit('set', false)
})
}, },
update(context, payload) { async update(context, payload) {
let endPoint = 'apps/polls' let endPoint = 'apps/polls'
if (context.rootState.route.name === 'publicVote') { if (context.rootState.route.name === 'publicVote') {
endPoint = endPoint + '/s/' + context.rootState.route.params.token endPoint = endPoint + '/s/' + context.rootState.route.params.token
} else if (context.rootState.route.name === 'vote') { } else if (context.rootState.route.name === 'vote') {
endPoint = endPoint + '/poll/' + context.rootState.route.params.id endPoint = endPoint + '/poll/' + context.rootState.route.params.id
} else {
return
} }
return axios.put(generateUrl(endPoint + (payload ? '/subscribe' : '/unsubscribe'))) try {
.then((response) => { const response = await axios.put(generateUrl(endPoint + (payload ? '/subscribe' : '/unsubscribe')))
context.commit('set', response.data) context.commit('set', response.data)
}) } catch (e) {
.catch((error) => { console.error(e.response)
console.error(error.response) }
})
}, },
} }

Просмотреть файл

@ -117,7 +117,7 @@ const getters = {
} }
const actions = { const actions = {
list(context) { async list(context) {
let endPoint = 'apps/polls' let endPoint = 'apps/polls'
if (context.rootState.route.name === 'publicVote') { if (context.rootState.route.name === 'publicVote') {
@ -128,51 +128,47 @@ const actions = {
context.commit('reset') context.commit('reset')
return return
} }
try {
return axios.get(generateUrl(endPoint + '/votes')) const response = await axios.get(generateUrl(endPoint + '/votes'))
.then((response) => { context.commit('set', response.data)
context.commit('set', response.data) } catch (e) {
}) context.commit('reset')
.catch(() => { }
context.commit('reset')
})
}, },
set(context, payload) {
async set(context, payload) {
let endPoint = 'apps/polls' let endPoint = 'apps/polls'
if (context.rootState.poll.acl.token) { if (context.rootState.route.name === 'publicVote') {
endPoint = endPoint + '/s/' + context.rootState.poll.acl.token endPoint = endPoint + '/s/' + context.rootState.poll.acl.token
} }
return axios.put(generateUrl(endPoint + '/vote'), { try {
optionId: payload.option.id, const response = await axios.put(generateUrl(endPoint + '/vote'), {
setTo: payload.setTo, optionId: payload.option.id,
}) setTo: payload.setTo,
.then((response) => {
context.commit('setItem', { option: payload.option, pollId: context.rootState.poll.id, vote: response.data.vote })
return response.data
})
.catch((error) => {
if (error.response.status === 409) {
context.dispatch('list')
} else {
console.error('Error setting vote', { error: error.response }, { payload: payload })
throw error
}
}) })
context.commit('setItem', { option: payload.option, pollId: context.rootState.poll.id, vote: response.data.vote })
return response.data
} catch (e) {
if (e.response.status === 409) {
context.dispatch('list')
} else {
console.error('Error setting vote', { error: e.response }, { payload: payload })
throw e
}
}
}, },
deleteUser(context, payload) { async deleteUser(context, payload) {
const endPoint = 'apps/polls/poll/' + context.rootState.route.params.id + '/user/' + payload.userId const endPoint = 'apps/polls/poll/' + context.rootState.route.params.id + '/user/' + payload.userId
return axios.delete(generateUrl(endPoint)) try {
.then(() => { await axios.delete(generateUrl(endPoint))
context.commit('deleteVotes', payload) context.commit('deleteVotes', payload)
}) } catch (e) {
.catch((error) => { console.error('Error deleting votes', { error: e.response }, { payload: payload })
console.error('Error deleting votes', { error: error.response }, { payload: payload }) throw e
throw error }
})
}, },
} }