Skip to content
Snippets Groups Projects
Commit e9f2c4df authored by jvanboxtel@wisc.edu's avatar jvanboxtel@wisc.edu
Browse files

refactor to use termcourses endpoint

parent d2c411ec
No related branches found
No related tags found
No related merge requests found
...@@ -297,21 +297,16 @@ export class DegreePlanEffects { ...@@ -297,21 +297,16 @@ export class DegreePlanEffects {
private loadTermsForPlan<T extends { visibleRoadmapId: number }>(stdin: T) { private loadTermsForPlan<T extends { visibleRoadmapId: number }>(stdin: T) {
return forkJoin( return forkJoin(
this.api.getAllNotes(stdin.visibleRoadmapId), this.api.getAllNotes(stdin.visibleRoadmapId),
this.api.getAllCourses(stdin.visibleRoadmapId), this.api.getAllTermCourses(stdin.visibleRoadmapId),
this.api.getActiveTerms(), this.api.getActiveTerms(),
).pipe( ).pipe(
// Combine courses and notes by term. // Combine courses and notes by term.
map(([notes, courses, currentTerms]) => { map(([notes, termCourses, currentTerms]) => {
/** /**
* Using the notes & courses relevant to the current degree plan and * Using the notes & courses relevant to the current degree plan and
* the active terms, generate a sorted list of all unqiue term codes. * the active terms, generate a sorted list of all unqiue term codes.
*/ */
const uniqueTermCodes = [notes, courses, currentTerms] const uniqueTermCodes = termCourses.map(course => course.termCode);
.map((ts: { termCode: string }[]) => ts.map(t => t.termCode))
.reduce((flat, nested) => flat.concat(nested), [])
.filter((termCode, index, self) => self.indexOf(termCode) === index)
.sort();
/** /**
* For each unique termCode, build a Term object that includes any * For each unique termCode, build a Term object that includes any
* courses or notes relevant to that termCode. * courses or notes relevant to that termCode.
...@@ -320,7 +315,8 @@ export class DegreePlanEffects { ...@@ -320,7 +315,8 @@ export class DegreePlanEffects {
return { return {
termCode, termCode,
note: notes.find(note => note.termCode === termCode), note: notes.find(note => note.termCode === termCode),
courses: courses.filter(course => course.termCode === termCode), courses: termCourses.filter(term => term.termCode === termCode)[0]
.courses,
}; };
}); });
......
...@@ -51,9 +51,11 @@ export class DegreePlannerApiService { ...@@ -51,9 +51,11 @@ export class DegreePlannerApiService {
return this.http.get<Note[]>(this.degreePlanEndpoint(roadmapId, 'notes')); return this.http.get<Note[]>(this.degreePlanEndpoint(roadmapId, 'notes'));
} }
public getAllCourses(roadmapId: number): Observable<Course[]> { public getAllTermCourses(
return this.http.get<Course[]>( roadmapId: number,
this.degreePlanEndpoint(roadmapId, 'courses'), ): Observable<{ termCode: string; courses: Course[] }[]> {
return this.http.get<{ termCode: string; courses: Course[] }[]>(
this.degreePlanEndpoint(roadmapId, 'termcourses'),
); );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment