From 3cb49cefe835ba734f9cb5f1a78a3501c6d26673 Mon Sep 17 00:00:00 2001 From: Jose Ignacio Palma Date: Mon, 30 Dec 2024 19:28:55 -0400 Subject: [PATCH] fix: use modifyObjectKeys and snakeCaseObject on api data advanced settings to format value --- src/advanced-settings/data/api.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/advanced-settings/data/api.js b/src/advanced-settings/data/api.js index f240357c9f..970b199856 100644 --- a/src/advanced-settings/data/api.js +++ b/src/advanced-settings/data/api.js @@ -1,4 +1,10 @@ -import { camelCaseObject, getConfig } from '@edx/frontend-platform'; +/* eslint-disable import/prefer-default-export */ +import { + camelCaseObject, + getConfig, + modifyObjectKeys, + snakeCaseObject, +} from '@edx/frontend-platform'; import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; import { convertObjectToSnakeCase } from '../../utils'; @@ -14,7 +20,13 @@ 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]?.value) { + objectFormatted[key].value = snakeCaseObject(objectFormatted[key].value); + } + return key; + }); } /** @@ -26,7 +38,13 @@ 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]?.value) { + objectFormatted[key].value = snakeCaseObject(objectFormatted[key].value); + } + return key; + }); } /**