diff --git a/src/advanced-settings/data/api.js b/src/advanced-settings/data/api.js index 76afc3be65..3d012dbb6d 100644 --- a/src/advanced-settings/data/api.js +++ b/src/advanced-settings/data/api.js @@ -1,5 +1,10 @@ /* eslint-disable import/prefer-default-export */ -import { camelCaseObject, getConfig } from '@edx/frontend-platform'; +import { + camelCaseObject, + getConfig, + modifyObjectKeys, + snakeCaseObject, +} from '@edx/frontend-platform'; import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; import { convertObjectToSnakeCase } from '../../utils'; @@ -15,7 +20,14 @@ const getProctoringErrorsApiUrl = () => `${getApiBaseUrl()}/api/contentstore/v1/ export async function getCourseAdvancedSettings(courseId) { const { data } = await getAuthenticatedHttpClient() .get(`${getCourseAdvancedSettingsApiUrl(courseId)}?fetch_all=0`); - return camelCaseObject(data); + const objectFormatted = camelCaseObject(data); + return modifyObjectKeys(objectFormatted, (key) => { + if (objectFormatted[key]) { + /* eslint-disable-next-line dot-notation */ + objectFormatted[key]['value'] = snakeCaseObject(objectFormatted[key]['value']); + } + return key; + }); } /** @@ -27,7 +39,14 @@ export async function getCourseAdvancedSettings(courseId) { export async function updateCourseAdvancedSettings(courseId, settings) { const { data } = await getAuthenticatedHttpClient() .patch(`${getCourseAdvancedSettingsApiUrl(courseId)}`, convertObjectToSnakeCase(settings)); - return camelCaseObject(data); + const objectFormatted = camelCaseObject(data); + return modifyObjectKeys(objectFormatted, (key) => { + if (objectFormatted[key]) { + /* eslint-disable-next-line dot-notation */ + objectFormatted[key]['value'] = snakeCaseObject(objectFormatted[key]['value']); + } + return key; + }); } /**