diff --git a/app/src/api/api.js b/app/src/api/api.js index d199dccb..29cd73ba 100644 --- a/app/src/api/api.js +++ b/app/src/api/api.js @@ -5,7 +5,6 @@ import store from '@/store' import { openWebSocket, getResponseData, handleError } from './handlers' -import { objectToParams } from '@/helpers/commons' /** @@ -31,6 +30,31 @@ import { objectToParams } from '@/helpers/commons' */ +/** + * Converts an object literal into an `URLSearchParams` that can be turned into a + * query string or used as a body in a `fetch` call. + * + * @param {Object} obj - An object literal to convert. + * @param {Object} options + * @param {Boolean} [options.addLocale=false] - Option to append the locale to the query string. + * @return {URLSearchParams} + */ +export function objectToParams (obj, { addLocale = false } = {}) { + const urlParams = new URLSearchParams() + for (const [key, value] of Object.entries(obj)) { + if (Array.isArray(value)) { + value.forEach(v => urlParams.append(key, v)) + } else { + urlParams.append(key, value) + } + } + if (addLocale) { + urlParams.append('locale', store.getters.locale) + } + return urlParams +} + + export default { options: { credentials: 'include', diff --git a/app/src/api/index.js b/app/src/api/index.js index 4c919aa1..c3f1ae7f 100644 --- a/app/src/api/index.js +++ b/app/src/api/index.js @@ -1,2 +1,2 @@ -export { default } from './api' +export { default, objectToParams } from './api' export { handleError, registerGlobalErrorHandlers } from './handlers' diff --git a/app/src/helpers/commons.js b/app/src/helpers/commons.js index 7a94f386..b9510510 100644 --- a/app/src/helpers/commons.js +++ b/app/src/helpers/commons.js @@ -1,6 +1,3 @@ -import store from '@/store' - - /** * Allow to set a timeout on a `Promise` expected response. * The returned Promise will be rejected if the original Promise is not resolved or @@ -19,31 +16,6 @@ export function timeout (promise, delay) { } -/** - * Converts an object literal into an `URLSearchParams` that can be turned into a - * query string or used as a body in a `fetch` call. - * - * @param {Object} obj - An object literal to convert. - * @param {Object} options - * @param {Boolean} [options.addLocale=false] - Option to append the locale to the query string. - * @return {URLSearchParams} - */ -export function objectToParams (obj, { addLocale = false } = {}) { - const urlParams = new URLSearchParams() - for (const [key, value] of Object.entries(obj)) { - if (Array.isArray(value)) { - value.forEach(v => urlParams.append(key, v)) - } else { - urlParams.append(key, value) - } - } - if (addLocale) { - urlParams.append('locale', store.getters.locale) - } - return urlParams -} - - /** * Check if passed value is an object literal. * diff --git a/app/src/views/app/AppActions.vue b/app/src/views/app/AppActions.vue index 51a64e5f..117a1325 100644 --- a/app/src/views/app/AppActions.vue +++ b/app/src/views/app/AppActions.vue @@ -38,11 +38,10 @@