Skip to content
Snippets Groups Projects
Commit c157e5c3 authored by Isaac Evavold's avatar Isaac Evavold Committed by Isaac Evavold
Browse files

ROENROLL-1701 fix course dup moving from future to active term

parent 8e49ee38
No related branches found
No related tags found
No related merge requests found
Pipeline #37149 passed
import { Injectable } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { of } from 'rxjs';
import { of, forkJoin } from 'rxjs';
import {
tap,
map,
......@@ -57,40 +57,43 @@ export class CourseEffects {
flatMap(([action, degreePlan]) => {
const roadmapId = degreePlan.roadmapId;
const activeTerms = this.constants.activeTermCodes();
const recordId = action.payload.id;
const termCode = action.payload.to;
const fromTermCode = action.payload.from;
// When adding to an active term use cart endpoint
if (activeTerms.some(term => term.equals(termCode))) {
const subjectCode = action.payload.subjectCode;
const courseId = action.payload.courseId;
const {
id: recordId,
to: toTermCode,
subjectCode,
courseId,
} = action.payload;
const toActiveTerm = activeTerms.some(t => t.equals(toTermCode));
const moveCourse = this.api.updateCourseTerm(
roadmapId,
recordId,
toTermCode,
);
const addCourseToCart = this.api.addCourseToCart(
if (toActiveTerm) {
/**
* The `updateCourseTerm` API won't force cart validation which we want
* if we're adding a course to the cart. Calling the `addCourseToCart`
* API when moving a cart to an active term will trigger the cart
* validation.
*/
const validateCart = this.api.addCourseToCart(
subjectCode,
courseId,
termCode,
toTermCode,
);
// If both terms are active terms, we have to remove course
if (activeTerms.some(term => term.equals(fromTermCode))) {
return addCourseToCart.pipe(
mergeMap(() => this.api.removeCourse(roadmapId, recordId)),
map(() => action),
);
} else {
return addCourseToCart.pipe(map(() => action));
}
return forkJoin(moveCourse, validateCart).pipe(map(() => action));
} else {
return this.api
.updateCourseTerm(roadmapId, recordId, termCode)
.pipe(map(() => action));
return moveCourse.pipe(map(() => action));
}
}),
map(action => new MoveCourseBetweenTermsSuccess(action.payload)),
tap(state => {
const touchedTerm = state.payload.to.description;
tap(action => {
const touchedTerm = action.payload.to.description;
const message = `Course has been moved to ${touchedTerm}`;
this.snackBar.open(message, undefined, {});
}),
......
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