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 {
private loadTermsForPlan<T extends { visibleRoadmapId: number }>(stdin: T) {
return forkJoin(
this.api.getAllNotes(stdin.visibleRoadmapId),
this.api.getAllCourses(stdin.visibleRoadmapId),
this.api.getAllTermCourses(stdin.visibleRoadmapId),
this.api.getActiveTerms(),
).pipe(
// 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
* the active terms, generate a sorted list of all unqiue term codes.
*/
const uniqueTermCodes = [notes, courses, currentTerms]
.map((ts: { termCode: string }[]) => ts.map(t => t.termCode))
.reduce((flat, nested) => flat.concat(nested), [])
.filter((termCode, index, self) => self.indexOf(termCode) === index)
.sort();
const uniqueTermCodes = termCourses.map(course => course.termCode);
/**
* For each unique termCode, build a Term object that includes any
* courses or notes relevant to that termCode.
......@@ -320,7 +315,8 @@ export class DegreePlanEffects {
return {
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 {
return this.http.get<Note[]>(this.degreePlanEndpoint(roadmapId, 'notes'));
}
public getAllCourses(roadmapId: number): Observable<Course[]> {
return this.http.get<Course[]>(
this.degreePlanEndpoint(roadmapId, 'courses'),
public getAllTermCourses(
roadmapId: number,
): 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