Skip to content

Commit

Permalink
type api requests
Browse files Browse the repository at this point in the history
modeled-mobx now expects an object for hydration
  • Loading branch information
nathanstitt committed Jun 22, 2021
1 parent a230165 commit 5f61ba0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion tutor/src/helpers/course-enrollment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Enroll from '../components/enroll';
import urlFor from '../api';
import { ApiErrorData, isApiError } from 'shared/api/request';
import type { User, CoursesMap } from '../models';
import { CourseData } from '../models/types';

export class CourseEnrollment extends BaseModel {

Expand Down Expand Up @@ -188,7 +189,7 @@ export class CourseEnrollment extends BaseModel {
@action async create() {
if (this.needsPeriodSelection) {
this.courseToJoin = new Course()
const courseData = await this.api.request(
const courseData = await this.api.request<CourseData>(
urlFor('fetchEnrollmentChoices', { enrollmentCode: this.originalEnrollmentCode }),
)
this.courseToJoin = hydrateModel(Course, courseData)
Expand Down
2 changes: 1 addition & 1 deletion tutor/src/models/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export class Course extends BaseModel {

@action async saveExerciseExclusion({ exercise, is_excluded }: { exercise: Exercise, is_excluded: boolean }) {
exercise.is_excluded = is_excluded; // eagerly set exclusion
const data = await this.api.request(
const data = await this.api.request<CourseData>(
urlFor('saveExerciseExclusion', { courseId: this.id }),
{ data: [{ id: exercise.id, is_excluded }] },
)
Expand Down
3 changes: 2 additions & 1 deletion tutor/src/models/course/lms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import urlFor from '../../api'
import type { Course } from '../../models'
import Time from 'shared/model/time';
import UiSettings from 'shared/model/ui-settings';
import { CourseLMSData } from '../types';

const LMS_VENDOR = 'lmsv';

Expand Down Expand Up @@ -36,7 +37,7 @@ export class CourseLMS extends BaseModel {
}

async fetch() {
const json = await this.api.request(urlFor('fetchCourseLMS', { courseId: this.course.id }))
const json = await this.api.request<CourseLMSData>(urlFor('fetchCourseLMS', { courseId: this.course.id }))
hydrateInstance(this, json)
}

Expand Down
11 changes: 11 additions & 0 deletions tutor/src/models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ export interface TeacherProfileData {
name: string
}

export interface CourseLMSData {
id: ID
key: string
secret: string
launch_url: string
configuration_url: string
xml: string
created_at: string
updated_at: string
}

export interface CoursePeriodData {
id: ID
enrollment_code: string
Expand Down

0 comments on commit 5f61ba0

Please sign in to comment.