Skip to content

Commit

Permalink
fix: use modifyObjectKeys and snakeCaseObject on api data advanced se…
Browse files Browse the repository at this point in the history
…ttings to format values
  • Loading branch information
jignaciopm committed Jan 3, 2025
1 parent 580ad66 commit 3f612c4
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/advanced-settings/data/api.js
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -15,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;
});
}

/**
Expand All @@ -27,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;
});
}

/**
Expand Down

0 comments on commit 3f612c4

Please sign in to comment.