Skip to content
Snippets Groups Projects
Commit bb2a78ae authored by Angelina Filippova's avatar Angelina Filippova
Browse files

Create function that wraps updated settings to send it to BE

parent 492828b8
Branches
Tags
1 merge request!65Update server configuration
......@@ -56,12 +56,6 @@ const parseObject = (object) => {
}, {})
}
export const parseValue = (input, value, type) => {
if (type === 'string' || type === 'boolean' || type === 'integer') {
return [{ tuple: [input, value] }]
}
}
export const valueHasTuples = (key, value) => {
const valueIsArrayOfNonObjects = Array.isArray(value) && value.length > 0 && typeof value[0] !== 'object'
return key === ':meta' ||
......@@ -75,6 +69,24 @@ export const valueHasTuples = (key, value) => {
valueIsArrayOfNonObjects
}
export const wrapUpdatedSettings = (group, settings) => {
return Object.keys(settings).map((key) => {
const value = wrapValues(settings[key])
return { group, key, value }
})
}
const wrapValues = settings => {
return Object.keys(settings).map(setting => {
const [type, value] = settings[setting]
if (type === 'keyword') {
return { 'tuple': [setting, wrapValues(setting, value)] }
} else {
return { 'tuple': [setting, value] }
}
})
}
const wrapNestedTuples = setting => {
return Object.keys(setting).reduce((acc, settingName) => {
const data = setting[settingName]
......
import { fetchDescription, fetchSettings, migrateToDB, updateSettings, uploadMedia } from '@/api/settings'
import { parseTuples, valueHasTuples } from './normalizers'
import { parseTuples, valueHasTuples, wrapUpdatedSettings } from './normalizers'
const settings = {
state: {
......@@ -72,7 +72,9 @@ const settings = {
commit('REWRITE_CONFIG', { tab, data })
},
async SubmitChanges({ getters, commit, state }) {
const configs = state.updatedSettings
const configs = Object.keys(state.updatedSettings).reduce((acc, group) => {
return [...acc, ...wrapUpdatedSettings(group, state.updatedSettings[group])]
}, [])
const response = await updateSettings(configs, getters.authHost, getters.token)
commit('SET_SETTINGS', response.data.configs)
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment