Skip to content

Commit 5f61ba0

Browse files
committed
type api requests
modeled-mobx now expects an object for hydration
1 parent a230165 commit 5f61ba0

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

tutor/src/helpers/course-enrollment.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Enroll from '../components/enroll';
1313
import urlFor from '../api';
1414
import { ApiErrorData, isApiError } from 'shared/api/request';
1515
import type { User, CoursesMap } from '../models';
16+
import { CourseData } from '../models/types';
1617

1718
export class CourseEnrollment extends BaseModel {
1819

@@ -188,7 +189,7 @@ export class CourseEnrollment extends BaseModel {
188189
@action async create() {
189190
if (this.needsPeriodSelection) {
190191
this.courseToJoin = new Course()
191-
const courseData = await this.api.request(
192+
const courseData = await this.api.request<CourseData>(
192193
urlFor('fetchEnrollmentChoices', { enrollmentCode: this.originalEnrollmentCode }),
193194
)
194195
this.courseToJoin = hydrateModel(Course, courseData)

tutor/src/models/course.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export class Course extends BaseModel {
325325

326326
@action async saveExerciseExclusion({ exercise, is_excluded }: { exercise: Exercise, is_excluded: boolean }) {
327327
exercise.is_excluded = is_excluded; // eagerly set exclusion
328-
const data = await this.api.request(
328+
const data = await this.api.request<CourseData>(
329329
urlFor('saveExerciseExclusion', { courseId: this.id }),
330330
{ data: [{ id: exercise.id, is_excluded }] },
331331
)

tutor/src/models/course/lms.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import urlFor from '../../api'
55
import type { Course } from '../../models'
66
import Time from 'shared/model/time';
77
import UiSettings from 'shared/model/ui-settings';
8+
import { CourseLMSData } from '../types';
89

910
const LMS_VENDOR = 'lmsv';
1011

@@ -36,7 +37,7 @@ export class CourseLMS extends BaseModel {
3637
}
3738

3839
async fetch() {
39-
const json = await this.api.request(urlFor('fetchCourseLMS', { courseId: this.course.id }))
40+
const json = await this.api.request<CourseLMSData>(urlFor('fetchCourseLMS', { courseId: this.course.id }))
4041
hydrateInstance(this, json)
4142
}
4243

tutor/src/models/types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ export interface TeacherProfileData {
4444
name: string
4545
}
4646

47+
export interface CourseLMSData {
48+
id: ID
49+
key: string
50+
secret: string
51+
launch_url: string
52+
configuration_url: string
53+
xml: string
54+
created_at: string
55+
updated_at: string
56+
}
57+
4758
export interface CoursePeriodData {
4859
id: ID
4960
enrollment_code: string

0 commit comments

Comments
 (0)