diff options
author | dartcafe <github@dartcafe.de> | 2022-08-21 10:45:49 +0300 |
---|---|---|
committer | dartcafe <github@dartcafe.de> | 2022-08-21 10:45:49 +0300 |
commit | 55f56794f86b84ca8b37ae527ca67d9cca1311ab (patch) | |
tree | 52c64173fa81d5b6335004c164998cb2f6df83f2 /src | |
parent | d2b00a1e2c7daf0c3159bd499314d18c4f86ebc6 (diff) |
fix ajax requests
Signed-off-by: dartcafe <github@dartcafe.de>
Diffstat (limited to 'src')
-rw-r--r-- | src/js/store/modules/activity.js | 7 | ||||
-rw-r--r-- | src/js/store/modules/appSettings.js | 8 | ||||
-rw-r--r-- | src/js/store/modules/combo.js | 10 | ||||
-rw-r--r-- | src/js/store/modules/comments.js | 14 | ||||
-rw-r--r-- | src/js/store/modules/options.js | 34 | ||||
-rw-r--r-- | src/js/store/modules/poll.js | 31 | ||||
-rw-r--r-- | src/js/store/modules/polls.js | 3 | ||||
-rw-r--r-- | src/js/store/modules/pollsAdmin.js | 10 | ||||
-rw-r--r-- | src/js/store/modules/settings.js | 15 | ||||
-rw-r--r-- | src/js/store/modules/share.js | 28 | ||||
-rw-r--r-- | src/js/store/modules/shares.js | 31 | ||||
-rw-r--r-- | src/js/store/modules/subModules/acl.js | 3 | ||||
-rw-r--r-- | src/js/store/modules/subscription.js | 10 | ||||
-rw-r--r-- | src/js/store/modules/votes.js | 17 |
14 files changed, 86 insertions, 135 deletions
diff --git a/src/js/store/modules/activity.js b/src/js/store/modules/activity.js index c16a4edb..ee924caa 100644 --- a/src/js/store/modules/activity.js +++ b/src/js/store/modules/activity.js @@ -28,9 +28,9 @@ const defaultActivities = () => ({ list: [], }) -const state = defaultActivities() - const namespaced = true +const state = defaultActivities() +const axiosDefaultConfig = { headers: { Accept: 'application/json' } } const mutations = { set(state, payload) { @@ -55,9 +55,10 @@ const actions = { params.append('limit', 50) params.append('object_type', 'poll') params.append('object_id', context.rootState.route.params.id) + const endPoint = generateOcsUrl('apps/activity/api/v2/activity/filter?') + params try { - const response = await axios.get(generateOcsUrl('apps/activity/api/v2/activity/filter?') + params) + const response = await axios.get(endPoint, axiosDefaultConfig) context.commit('set', response.data.ocs.data) } catch { context.commit('reset') diff --git a/src/js/store/modules/appSettings.js b/src/js/store/modules/appSettings.js index 9f7a1f09..8e9879d1 100644 --- a/src/js/store/modules/appSettings.js +++ b/src/js/store/modules/appSettings.js @@ -53,8 +53,9 @@ const defaultAppSettings = () => ({ showMailAddressesGroups: [], }) -const state = defaultAppSettings() const namespaced = true +const state = defaultAppSettings() +const axiosDefaultConfig = { headers: { Accept: 'application/json' } } const mutations = { reset(state) { @@ -73,7 +74,7 @@ const actions = { const endPoint = 'apps/polls/settings/app' try { const response = await axios.get(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, + ...axiosDefaultConfig, params: { time: +new Date() }, }) context.commit('set', response.data.appSettings) @@ -86,9 +87,8 @@ const actions = { const endPoint = 'apps/polls/settings/app' try { const response = await axios.post(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, appSettings: context.state, - }) + }, axiosDefaultConfig) context.commit('set', response.data.appSettings) } catch (e) { console.error('Error writing appSettings', { error: e.response }, { appSettings: state }) diff --git a/src/js/store/modules/combo.js b/src/js/store/modules/combo.js index 778c80e0..334f553d 100644 --- a/src/js/store/modules/combo.js +++ b/src/js/store/modules/combo.js @@ -34,9 +34,9 @@ const defaultCombo = () => ({ votes: [], }) -const state = defaultCombo() - const namespaced = true +const state = defaultCombo() +const axiosDefaultConfig = { headers: { Accept: 'application/json' } } const mutations = { set(state, payload) { @@ -146,7 +146,7 @@ const actions = { const endPoint = `apps/polls/poll/${payload.pollId}/poll` try { const response = await axios.get(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, + ...axiosDefaultConfig, params: { time: +new Date() }, }) context.commit('addPoll', response.data) @@ -160,7 +160,7 @@ const actions = { try { const response = await axios.get(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, + ...axiosDefaultConfig, params: { time: +new Date() }, }) context.commit('addOptions', response.data) @@ -174,7 +174,7 @@ const actions = { try { const response = await axios.get(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, + ...axiosDefaultConfig, params: { time: +new Date() }, }) context.commit('addVotes', response.data) diff --git a/src/js/store/modules/comments.js b/src/js/store/modules/comments.js index be5207bc..7e1425f8 100644 --- a/src/js/store/modules/comments.js +++ b/src/js/store/modules/comments.js @@ -28,9 +28,9 @@ const defaultComments = () => ({ list: [], }) -const state = defaultComments() - const namespaced = true +const state = defaultComments() +const axiosDefaultConfig = { headers: { Accept: 'application/json' } } const mutations = { @@ -72,7 +72,7 @@ const actions = { try { const response = await axios.get(generateUrl(`${endPoint}/comments`), { - headers: { Accept: 'application/json' }, + ...axiosDefaultConfig, params: { time: +new Date() }, }) context.commit('set', response.data) @@ -97,9 +97,8 @@ const actions = { try { await axios.post(generateUrl(`${endPoint}/comment`), { - headers: { Accept: 'application/json' }, message: payload.message, - }) + }, axiosDefaultConfig) context.dispatch('list') // context.commit('add', { comment: response.data.comment }) } catch (e) { @@ -114,11 +113,10 @@ const actions = { if (context.rootState.route.name === 'publicVote') { endPoint = `${endPoint}/s/${context.rootState.route.params.token}` } + endPoint = `${endPoint}/comment/${payload.comment.id}` try { - await axios.delete(generateUrl(`${endPoint}/comment/${payload.comment.id}`), { - headers: { Accept: 'application/json' }, - }) + await axios.delete(generateUrl(endPoint), axiosDefaultConfig) context.commit('delete', { comment: payload.comment }) } catch (e) { console.error('Error deleting comment', { error: e.response }, { payload }) diff --git a/src/js/store/modules/options.js b/src/js/store/modules/options.js index 08375aa5..5270d1f8 100644 --- a/src/js/store/modules/options.js +++ b/src/js/store/modules/options.js @@ -31,9 +31,9 @@ const defaultOptions = () => ({ ranked: false, }) -const state = defaultOptions() - const namespaced = true +const state = defaultOptions() +const axiosDefaultConfig = { headers: { Accept: 'application/json' } } const mutations = { set(state, payload) { @@ -151,7 +151,7 @@ const actions = { try { const response = await axios.get(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, + ...axiosDefaultConfig, params: { time: +new Date() }, }) context.commit('set', { options: response.data.options }) @@ -171,12 +171,11 @@ const actions = { try { const response = await axios.post(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, pollId: context.rootState.route.params.id, timestamp: payload.timestamp, text: payload.text, duration: payload.duration, - }) + }, axiosDefaultConfig) context.commit('setItem', { option: response.data.option }) } catch (e) { console.error(`Error adding option: ${e.response.data}`, { error: e.response }, { payload }) @@ -190,10 +189,9 @@ const actions = { try { const response = await axios.post(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, pollId: context.rootState.route.params.id, text: payload.text, - }) + }, axiosDefaultConfig) context.commit('set', { options: response.data.options }) } catch (e) { console.error(`Error adding option: ${e.response.data}`, { error: e.response }, { payload }) @@ -207,11 +205,10 @@ const actions = { try { const response = await axios.put(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, timestamp: payload.option.timestamp, text: payload.option.timeStamp, duration: payload.option.duration, - }) + }, axiosDefaultConfig) context.commit('setItem', { option: response.data.option }) } catch (e) { console.error('Error updating option', { error: e.response }, { payload }) @@ -230,9 +227,7 @@ const actions = { } try { - await axios.delete(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, - }) + await axios.delete(generateUrl(endPoint), axiosDefaultConfig) context.commit('delete', { option: payload.option }) } catch (e) { console.error('Error deleting option', { error: e.response }, { payload }) @@ -247,9 +242,7 @@ const actions = { context.commit('confirm', { option: payload.option }) try { - const response = await axios.put(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, - }) + const response = await axios.put(generateUrl(endPoint), null, axiosDefaultConfig) context.commit('setItem', { option: response.data.option }) } catch (e) { console.error('Error confirming option', { error: e.response }, { payload }) @@ -265,9 +258,8 @@ const actions = { try { const response = await axios.post(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, options: payload, - }) + }, axiosDefaultConfig) context.commit('set', { options: response.data.options }) } catch (e) { console.error('Error reordering option', { error: e.response }, { payload }) @@ -281,11 +273,10 @@ const actions = { try { const response = await axios.post(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, step: payload.sequence.step, unit: payload.sequence.unit.value, amount: payload.sequence.amount, - }) + }, axiosDefaultConfig) context.commit('set', { options: response.data.options }) } catch (e) { console.error('Error creating sequence', { error: e.response }, { payload }) @@ -299,10 +290,9 @@ const actions = { try { const response = await axios.post(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, step: payload.shift.step, unit: payload.shift.unit.value, - }) + }, axiosDefaultConfig) context.commit('set', { options: response.data.options }) } catch (e) { console.error('Error shifting dates', { error: e.response }, { payload }) @@ -316,7 +306,7 @@ const actions = { try { return await axios.get(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, + ...axiosDefaultConfig, params: { tz: Intl.DateTimeFormat().resolvedOptions().timeZone }, }) } catch (e) { diff --git a/src/js/store/modules/poll.js b/src/js/store/modules/poll.js index 4ba5cd0c..dcad3e38 100644 --- a/src/js/store/modules/poll.js +++ b/src/js/store/modules/poll.js @@ -57,12 +57,10 @@ const defaultPoll = () => ({ }, }) -const state = defaultPoll() - const namespaced = true -const modules = { - acl, -} +const modules = { acl } +const state = defaultPoll() +const axiosDefaultConfig = { headers: { Accept: 'application/json' } } const mutations = { set(state, payload) { @@ -188,7 +186,7 @@ const actions = { } try { const response = await axios.get(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, + ...axiosDefaultConfig, params: { time: +new Date() }, }) context.commit('set', response.data) @@ -203,10 +201,9 @@ const actions = { const endPoint = 'apps/polls/poll/add' try { return await axios.post(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, title: payload.title, type: payload.type, - }) + }, axiosDefaultConfig) } catch (e) { console.error('Error adding poll:', { error: e.response }, { state: context.state }) throw e @@ -216,7 +213,7 @@ const actions = { async clone(context, payload) { const endPoint = `apps/polls/poll/${payload.pollId}/clone` try { - return await axios.get(generateUrl(endPoint)) + return await axios.post(generateUrl(endPoint), null, axiosDefaultConfig) } catch (e) { console.error('Error cloning poll', { error: e.response }, { payload }) } @@ -226,9 +223,9 @@ const actions = { const endPoint = `apps/polls/poll/${context.state.id}` try { const response = await axios.put(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, poll: context.state, - }) + }, axiosDefaultConfig) + context.commit('set', response.data) context.commit('acl/set', response.data) context.dispatch('options/list', null, { root: true }) @@ -241,7 +238,7 @@ const actions = { async toggleArchive(context, payload) { const endPoint = `apps/polls/poll/${payload.pollId}/toggleArchive` try { - await axios.put(generateUrl(endPoint)) + await axios.put(generateUrl(endPoint), null, axiosDefaultConfig) } catch (e) { console.error('Error archiving/restoring', { error: e.response }, { payload }) } @@ -250,7 +247,7 @@ const actions = { async sendConfirmation(context, payload) { const endPoint = `apps/polls/poll/${context.rootState.route.params.id}/confirmation` try { - const response = await axios.post(generateUrl(endPoint)) + const response = await axios.post(generateUrl(endPoint), null, axiosDefaultConfig) return response.data.confirmations } catch (e) { console.error('Error sending confirmation', { error: e.response }, { payload }) @@ -260,9 +257,7 @@ const actions = { async delete(context, payload) { const endPoint = `apps/polls/poll/${payload.pollId}` try { - await axios.delete(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, - }) + await axios.delete(generateUrl(endPoint), axiosDefaultConfig) } catch (e) { console.error('Error deleting poll', { error: e.response }, { payload }) } @@ -271,9 +266,7 @@ const actions = { async getParticipantsEmailAddresses(context) { const endPoint = `apps/polls/poll/${context.state.id}/addresses` try { - return await axios.get(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, - }) + return await axios.get(generateUrl(endPoint), axiosDefaultConfig) } catch (e) { console.error('Error retrieving email addresses', { error: e.response }) } diff --git a/src/js/store/modules/polls.js b/src/js/store/modules/polls.js index 96f1b162..9095b52c 100644 --- a/src/js/store/modules/polls.js +++ b/src/js/store/modules/polls.js @@ -138,6 +138,7 @@ const state = { } const namespaced = true +const axiosDefaultConfig = { headers: { Accept: 'application/json' } } const mutations = { set(state, payload) { @@ -200,7 +201,7 @@ const actions = { try { const response = await axios.get(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, + ...axiosDefaultConfig, params: { time: +new Date() }, }) context.commit('set', { list: response.data.list }) diff --git a/src/js/store/modules/pollsAdmin.js b/src/js/store/modules/pollsAdmin.js index 52076bf1..a0182d42 100644 --- a/src/js/store/modules/pollsAdmin.js +++ b/src/js/store/modules/pollsAdmin.js @@ -27,11 +27,11 @@ import axios from '@nextcloud/axios' import { getCurrentUser } from '@nextcloud/auth' import { generateUrl } from '@nextcloud/router' +const namespaced = true const state = { list: [], } - -const namespaced = true +const axiosDefaultConfig = { headers: { Accept: 'application/json' } } const mutations = { set(state, payload) { @@ -52,7 +52,7 @@ const actions = { const endPoint = 'apps/polls/administration/polls' try { const response = await axios.get(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, + ...axiosDefaultConfig, params: { time: +new Date() }, }) context.commit('set', { list: response.data }) @@ -67,9 +67,7 @@ const actions = { } const endPoint = `apps/polls/administration/poll/${payload.pollId}/takeover` - axios.put(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, - }) + axios.put(generateUrl(endPoint), null, axiosDefaultConfig) }, } diff --git a/src/js/store/modules/settings.js b/src/js/store/modules/settings.js index 750313ba..01bd45da 100644 --- a/src/js/store/modules/settings.js +++ b/src/js/store/modules/settings.js @@ -62,8 +62,9 @@ const defaultSettings = () => ({ ], }) -const state = defaultSettings() const namespaced = true +const state = defaultSettings() +const axiosDefaultConfig = { headers: { Accept: 'application/json' } } const mutations = { reset(state) { @@ -209,7 +210,10 @@ const actions = { async get(context) { const endPoint = 'apps/polls/preferences' try { - const response = await axios.get(generateUrl(endPoint), { params: { time: +new Date() } }) + const response = await axios.get(generateUrl(endPoint), { + ...axiosDefaultConfig, + params: { time: +new Date() }, + }) if (response.data.preferences.defaultViewTextPoll === 'desktop') { response.data.preferences.defaultViewTextPoll = 'table-view' } @@ -241,9 +245,8 @@ const actions = { const endPoint = 'apps/polls/preferences' try { const response = await axios.post(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, settings: context.state.user, - }) + }, axiosDefaultConfig) context.commit('setPreference', response.data.preferences) } catch (e) { console.error('Error writing preferences', { error: e.response }, { preferences: state.user }) @@ -253,9 +256,7 @@ const actions = { async getCalendars(context) { const endPoint = 'apps/polls/calendars' - const response = await axios.get(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, - }) + const response = await axios.get(generateUrl(endPoint), axiosDefaultConfig) context.commit('setCalendars', { calendars: response.data.calendars }) return response }, diff --git a/src/js/store/modules/share.js b/src/js/store/modules/share.js index d9c64e7f..c5d5e604 100644 --- a/src/js/store/modules/share.js +++ b/src/js/store/modules/share.js @@ -37,9 +37,9 @@ const defaultShares = () => ({ publicPollEmail: 'optional', }) -const state = defaultShares() - const namespaced = true +const state = defaultShares() +const axiosDefaultConfig = { headers: { Accept: 'application/json' } } const mutations = { set(state, payload) { @@ -66,7 +66,7 @@ const actions = { try { const response = await axios.get(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, + ...axiosDefaultConfig, params: { time: +new Date() }, }) context.commit('set', { share: response.data.share }) @@ -86,11 +86,10 @@ const actions = { try { const response = await axios.post(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, userName: payload.userName, emailAddress: payload.emailAddress, timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone, - }) + }, axiosDefaultConfig) if (payload.saveCookie && context.state.type === 'public') { const cookieExpiration = (30 * 24 * 60 * 1000) @@ -110,13 +109,10 @@ const actions = { return } - const endPoint = `apps/polls/s/${context.rootState.route.params.token}/email` + const endPoint = `apps/polls/s/${context.rootState.route.params.token}/email/${payload.emailAddress}` try { - const response = await axios.put(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, - emailAddress: payload.emailAddress, - }) + const response = await axios.put(generateUrl(endPoint), null, axiosDefaultConfig) context.commit('set', { share: response.data.share }) context.dispatch('poll/get', null, { root: true }) } catch (e) { @@ -133,9 +129,7 @@ const actions = { const endPoint = `apps/polls/s/${context.rootState.route.params.token}/name/${payload.displayName}` try { - const response = await axios.put(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, - }) + const response = await axios.put(generateUrl(endPoint), null, axiosDefaultConfig) context.commit('set', { share: response.data.share }) context.dispatch('poll/get', null, { root: true }) context.dispatch('comments/list', null, { root: true }) @@ -155,9 +149,7 @@ const actions = { const endPoint = `apps/polls/s/${context.rootState.route.params.token}/email` try { - const response = await axios.delete(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, - }) + const response = await axios.delete(generateUrl(endPoint), axiosDefaultConfig) context.commit('set', { share: response.data.share }) context.dispatch('subscription/update', false, { root: true }) context.dispatch('poll/get', null, { root: true }) @@ -175,9 +167,7 @@ const actions = { const endPoint = `apps/polls/s/${context.rootState.route.params.token}/resend` try { - return await axios.put(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, - }) + return await axios.put(generateUrl(endPoint), null, axiosDefaultConfig) } catch (e) { console.error('Error sending invitation', { error: e.response }, { payload }) throw e diff --git a/src/js/store/modules/shares.js b/src/js/store/modules/shares.js index 519603eb..497364d3 100644 --- a/src/js/store/modules/shares.js +++ b/src/js/store/modules/shares.js @@ -28,9 +28,9 @@ const defaultShares = () => ({ list: [], }) -const state = defaultShares() - const namespaced = true +const state = defaultShares() +const axiosDefaultConfig = { headers: { Accept: 'application/json' } } const mutations = { set(state, payload) { @@ -76,7 +76,7 @@ const actions = { try { const response = await axios.get(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, + ...axiosDefaultConfig, params: { time: +new Date() }, }) context.commit('set', response.data) @@ -90,10 +90,7 @@ const actions = { const endPoint = `apps/polls/poll/${context.rootState.route.params.id}/share` try { - await axios.post(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, - ...payload.share, - }) + await axios.post(generateUrl(endPoint), payload.share, axiosDefaultConfig) } catch (e) { console.error('Error writing share', { error: e.response }, { payload }) throw e @@ -108,9 +105,7 @@ const actions = { context.commit('delete', { share: payload.share }) try { - await axios.delete(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, - }) + await axios.delete(generateUrl(endPoint), axiosDefaultConfig) } catch (e) { console.error('Error removing share', { error: e.response }, { payload }) throw e @@ -129,9 +124,7 @@ const actions = { } try { - await axios.put(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, - }) + await axios.put(generateUrl(endPoint), null, axiosDefaultConfig) } catch (e) { console.error('Error switching type', { error: e.response }, { payload }) throw e @@ -144,9 +137,7 @@ const actions = { const endPoint = `apps/polls/share/${payload.share.token}/publicpollemail/${payload.value}` try { - await axios.put(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, - }) + await axios.put(generateUrl(endPoint), null, axiosDefaultConfig) } catch (e) { console.error('Error changing email register setting', { error: e.response }, { payload }) throw e @@ -159,9 +150,7 @@ const actions = { const endPoint = `apps/polls/share/${payload.share.token}/invite` try { - return await axios.post(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, - }) + return await axios.post(generateUrl(endPoint), null, axiosDefaultConfig) } catch (e) { console.error('Error sending invitation', { error: e.response }, { payload }) throw e @@ -174,9 +163,7 @@ const actions = { const endPoint = `apps/polls/share/${payload.share.token}/resolve` try { - await axios.get(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, - }) + await axios.get(generateUrl(endPoint), axiosDefaultConfig) } catch (e) { console.error('Error exploding group', e.response.data, { error: e.response }, { payload }) throw e diff --git a/src/js/store/modules/subModules/acl.js b/src/js/store/modules/subModules/acl.js index 6dee371f..3bf79674 100644 --- a/src/js/store/modules/subModules/acl.js +++ b/src/js/store/modules/subModules/acl.js @@ -52,9 +52,8 @@ const defaultAcl = () => ({ pollExpire: 0, }) -const state = defaultAcl() - const namespaced = true +const state = defaultAcl() const mutations = { diff --git a/src/js/store/modules/subscription.js b/src/js/store/modules/subscription.js index aac566b1..607f45a6 100644 --- a/src/js/store/modules/subscription.js +++ b/src/js/store/modules/subscription.js @@ -28,9 +28,9 @@ const defaultSubscription = () => ({ subscribed: false, }) -const state = defaultSubscription() - const namespaced = true +const state = defaultSubscription() +const axiosDefaultConfig = { headers: { Accept: 'application/json' } } const mutations = { @@ -60,7 +60,7 @@ const actions = { try { const response = await axios.get(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, + ...axiosDefaultConfig, params: { time: +new Date() }, }) context.commit('set', response.data) @@ -82,9 +82,7 @@ const actions = { } try { - const response = await axios.put(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, - }) + const response = await axios.put(generateUrl(endPoint), null, axiosDefaultConfig) context.commit('set', response.data) } catch (e) { console.error(e.response) diff --git a/src/js/store/modules/votes.js b/src/js/store/modules/votes.js index e62e319d..9e836df8 100644 --- a/src/js/store/modules/votes.js +++ b/src/js/store/modules/votes.js @@ -28,9 +28,9 @@ const defaultVotes = () => ({ list: [], }) -const state = defaultVotes() - const namespaced = true +const state = defaultVotes() +const axiosDefaultConfig = { headers: { Accept: 'application/json' } } const mutations = { set(state, payload) { @@ -93,7 +93,7 @@ const actions = { } try { const response = await axios.get(generateUrl(`${endPoint}/votes`), { - headers: { Accept: 'application/json' }, + ...axiosDefaultConfig, params: { time: +new Date() }, }) const votes = [] @@ -125,10 +125,9 @@ const actions = { try { const response = await axios.put(generateUrl(`${endPoint}/vote`), { - headers: { Accept: 'application/json' }, optionId: payload.option.id, setTo: payload.setTo, - }) + }, axiosDefaultConfig) context.commit('setItem', { option: payload.option, pollId: context.rootState.poll.id, vote: response.data.vote }) context.dispatch('options/list', null, { root: true }) context.dispatch('poll/get', null, { root: true }) @@ -154,9 +153,7 @@ const actions = { } try { - const response = await axios.delete(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, - }) + const response = await axios.delete(generateUrl(endPoint), axiosDefaultConfig) context.commit('deleteVotes', { userId: response.data.deleted }) } catch (e) { console.error('Error deleting votes', { error: e.response }) @@ -167,9 +164,7 @@ const actions = { async deleteUser(context, payload) { const endPoint = `apps/polls/poll/${context.rootState.route.params.id}/user/${payload.userId}` try { - await axios.delete(generateUrl(endPoint), { - headers: { Accept: 'application/json' }, - }) + await axios.delete(generateUrl(endPoint), axiosDefaultConfig) context.commit('deleteVotes', payload) } catch (e) { console.error('Error deleting votes', { error: e.response }, { payload }) |