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 Dec 30, 2024
1 parent dc0ba6a commit f921cdf
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/advanced-settings/data/api.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { camelCaseObject, getConfig } from '@edx/frontend-platform';
/* eslint-disable import/prefer-default-export */
import { camelCaseObject, getConfig, modifyObjectKeys, snakeCaseObject } from '@edx/frontend-platform';

Check failure on line 2 in src/advanced-settings/data/api.js

View workflow job for this annotation

GitHub Actions / tests

Expected a line break after this opening brace

Check failure on line 2 in src/advanced-settings/data/api.js

View workflow job for this annotation

GitHub Actions / tests

Expected a line break before this closing brace
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import { convertObjectToSnakeCase } from '../../utils';

Expand All @@ -14,7 +15,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]) {
objectFormatted[key]['value'] = snakeCaseObject(objectFormatted[key]['value'])

Check failure on line 21 in src/advanced-settings/data/api.js

View workflow job for this annotation

GitHub Actions / tests

["value"] is better written in dot notation

Check failure on line 21 in src/advanced-settings/data/api.js

View workflow job for this annotation

GitHub Actions / tests

["value"] is better written in dot notation

Check failure on line 21 in src/advanced-settings/data/api.js

View workflow job for this annotation

GitHub Actions / tests

Missing semicolon
}
return key;
});
}

/**
Expand All @@ -26,7 +33,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]) {
objectFormatted[key]['value'] = snakeCaseObject(objectFormatted[key]['value'])

Check failure on line 39 in src/advanced-settings/data/api.js

View workflow job for this annotation

GitHub Actions / tests

["value"] is better written in dot notation

Check failure on line 39 in src/advanced-settings/data/api.js

View workflow job for this annotation

GitHub Actions / tests

["value"] is better written in dot notation

Check failure on line 39 in src/advanced-settings/data/api.js

View workflow job for this annotation

GitHub Actions / tests

Missing semicolon
}
return key;
});
}

/**
Expand Down

0 comments on commit f921cdf

Please sign in to comment.