@@ -14,6 +14,10 @@ import {
1414
1515const getApiBaseUrl = ( ) => getConfig ( ) . STUDIO_BASE_URL ;
1616
17+ const pickDefined = < T extends Record < string , any > > ( obj : T ) => Object . fromEntries (
18+ Object . entries ( obj ) . filter ( ( [ , value ] ) => value !== undefined ) ,
19+ ) ;
20+
1721export const getCourseOutlineIndexApiUrl = (
1822 courseId : string ,
1923) => `${ getApiBaseUrl ( ) } /api/contentstore/v1/course_index/${ courseId } ` ;
@@ -239,30 +243,58 @@ export async function configureCourseSection(variables: ConfigureSectionData): P
239243/**
240244 * Configure course subsection
241245 */
242- export async function configureCourseSubsection ( variables : Partial < ConfigureSubsectionData > & Pick < ConfigureSubsectionData , 'itemId' > ) : Promise < object > {
246+ export async function configureCourseSubsection (
247+ variables : Partial < ConfigureSubsectionData > & Pick < ConfigureSubsectionData , 'itemId' > ,
248+ ) : Promise < object > {
249+ const {
250+ itemId,
251+ isVisibleToStaffOnly,
252+ dueDate,
253+ hideAfterDue,
254+ showCorrectness,
255+ isPracticeExam,
256+ isTimeLimited,
257+ isProctoredExam,
258+ isOnboardingExam,
259+ examReviewRules,
260+ defaultTimeLimitMinutes,
261+ releaseDate,
262+ graderType,
263+ isPrereq,
264+ prereqUsageKey,
265+ prereqMinScore,
266+ prereqMinCompletion,
267+ } = variables ;
268+
269+ const metadata = pickDefined ( {
270+ visible_to_staff_only : isVisibleToStaffOnly === undefined ? undefined : isVisibleToStaffOnly ? true : null ,
271+ due : dueDate ,
272+ hide_after_due : hideAfterDue ,
273+ show_correctness : showCorrectness ,
274+ is_practice_exam : isPracticeExam ,
275+ is_time_limited : isTimeLimited ,
276+ is_proctored_enabled : ( isProctoredExam !== undefined || isPracticeExam !== undefined || isOnboardingExam !== undefined )
277+ ? ( isProctoredExam || isPracticeExam || isOnboardingExam )
278+ : undefined ,
279+ exam_review_rules : examReviewRules ,
280+ default_time_limit_minutes : defaultTimeLimitMinutes ,
281+ is_onboarding_exam : isOnboardingExam ,
282+ start : releaseDate ,
283+ } ) ;
284+
285+ const body = pickDefined ( {
286+ publish : 'republish' ,
287+ graderType,
288+ isPrereq,
289+ prereqUsageKey,
290+ prereqMinScore,
291+ prereqMinCompletion,
292+ metadata,
293+ } ) ;
294+
243295 const { data } = await getAuthenticatedHttpClient ( )
244- . post ( getCourseItemApiUrl ( variables . itemId ) , {
245- publish : 'republish' ,
246- ...( variables . graderType !== undefined && { graderType : variables . graderType } ) ,
247- ...( variables . isPrereq !== undefined && { isPrereq : variables . isPrereq } ) ,
248- ...( variables . prereqUsageKey !== undefined && { prereqUsageKey : variables . prereqUsageKey } ) ,
249- ...( variables . prereqMinScore !== undefined && { prereqMinScore : variables . prereqMinScore } ) ,
250- ...( variables . prereqMinCompletion !== undefined && { prereqMinCompletion : variables . prereqMinCompletion } ) ,
251- metadata : {
252- // The backend expects metadata.visible_to_staff_only to either true or null
253- ...( variables . isVisibleToStaffOnly !== undefined && { visible_to_staff_only : variables . isVisibleToStaffOnly ? true : null } ) ,
254- ...( variables . dueDate !== undefined && { due : variables . dueDate } ) ,
255- ...( variables . hideAfterDue !== undefined && { hide_after_due : variables . hideAfterDue } ) ,
256- ...( variables . showCorrectness !== undefined && { show_correctness : variables . showCorrectness } ) ,
257- ...( variables . isPracticeExam !== undefined && { is_practice_exam : variables . isPracticeExam } ) ,
258- ...( variables . isTimeLimited !== undefined && { is_time_limited : variables . isTimeLimited } ) ,
259- ...( variables . isProctoredExam !== undefined || variables . isPracticeExam !== undefined || variables . isOnboardingExam !== undefined ? { is_proctored_enabled : variables . isProctoredExam || variables . isPracticeExam || variables . isOnboardingExam } : { } ) ,
260- ...( variables . examReviewRules !== undefined && { exam_review_rules : variables . examReviewRules } ) ,
261- ...( variables . defaultTimeLimitMinutes !== undefined && { default_time_limit_minutes : variables . defaultTimeLimitMinutes } ) ,
262- ...( variables . isOnboardingExam !== undefined && { is_onboarding_exam : variables . isOnboardingExam } ) ,
263- ...( variables . releaseDate !== undefined && { start : variables . releaseDate } ) ,
264- } ,
265- } ) ;
296+ . post ( getCourseItemApiUrl ( itemId ) , body ) ;
297+
266298 return data ;
267299}
268300
0 commit comments