Skip to content
Snippets Groups Projects
Commit b17e19c9 authored by pnogal's avatar pnogal Committed by Paulina Nogal
Browse files

Create Actions and Effect for newAudit POST request

parent 8a82af51
Branches audit-header
No related tags found
No related merge requests found
Pipeline #40016 passed
export interface SingleAuditRequest {
sisEmplId?: string;
darsInstitutionCode: string;
darsDegreeProgramCode: string;
darsCatalogYearTerm?: string;
darsAlternateCatalogYearTerm1?: string;
darsHonorsOptionCode?: string;
whichEnrolledCoursesIncluded?: string;
degreePlannerPlanName?: string;
}
......@@ -25,7 +25,7 @@
}
.step-buttons-group {
margin-top: 1.2em;
margin-top: 2em;
button {
text-transform: uppercase;
}
......
......@@ -2,11 +2,13 @@ import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MatSnackBar } from '@angular/material';
import { DarsApiService } from '../services/api.service';
import { DegreeProgram, DegreePrograms } from '../models/degree-program';
import { SingleAuditRequest } from '../models/single-audit-request';
import { StudentDegreeProgram } from '../models/student-degree-program';
import { Observable } from 'rxjs';
import { Store, select } from '@ngrx/store';
import { GlobalState } from '@app/core/state';
import * as selectors from '../store/selectors';
import * as darsActions from '../store/actions';
import { DARSState } from '../store/state';
import { MAT_DIALOG_DATA } from '@angular/material';
import {
......@@ -34,6 +36,7 @@ export class NewAuditOptionsComponent implements OnInit {
public honorsOptions: HonorsOption[] = [];
public courses: { termCode: string; courses: CourseBase[] }[];
public degreePlans$: Observable<DARSState['degreePlans']>;
public singleAuditRequest$: Observable<SingleAuditRequest>;
public degreePlans: DegreePlan[];
public primaryPlan: DegreePlan[];
public primaryPlanId: string;
......@@ -160,6 +163,13 @@ export class NewAuditOptionsComponent implements OnInit {
credits,
} = this.newAuditForm.value;
this.store.dispatch(
new darsActions.StartSendingAudit({
darsInstitutionCode: programOfStudy,
darsDegreeProgramCode: academicProgram,
}),
);
this.dialogRef.close();
this.snackBar.open(
'Audit in progress. You will be notified when the audit is ready to be viewed.',
......
......@@ -79,8 +79,15 @@ export class DarsApiService {
/**
* Request a new audit
*/
public newAudit(): Observable<AuditMetadata> {
public newAudit(
darsInstitutionCode: string,
darsDegreeProgramCode: string,
): Observable<AuditMetadata> {
const url = `${environment.apiDarsUrl}/single-audit-requests`;
return this.http.post<AuditMetadata>(url, HTTP_OPTIONS);
return this.http.post<AuditMetadata>(
url,
{ darsInstitutionCode, darsDegreeProgramCode },
HTTP_OPTIONS,
);
}
}
......@@ -2,6 +2,7 @@ import { DARSState } from '@app/dars/store/state';
import { Action } from '@ngrx/store';
import { AuditMetadata } from '../models/audit-metadata';
import { Audit } from '../models/audit/audit';
import { SingleAuditRequest } from '../models/single-audit-request';
export enum DarsActionTypes {
ErrorLoadingMetadata = '[DARS] Error Loading Metadata',
......@@ -13,9 +14,12 @@ export enum DarsActionTypes {
StartLoadingAudit = '[DARS] Start Loading Audit',
DoneLoadingAudit = '[DARS] Done Loading Audit',
CloseAudit = '[DARS] Close Audit',
PopulateDarsState = '[DARS] Done Loading state',
ErrorSendingAudit = 'DARS Error Sending Audit',
StartSendingAudit = '[DARS] Start Sending Audit',
DoneSendingAudit = '[DARS] Done Sending Audit',
DismissAlert = '[DARS] Dismiss Alert',
}
......@@ -67,6 +71,31 @@ export class CloseAudit implements Action {
public readonly type = DarsActionTypes.CloseAudit;
}
export class ErrorSendingAudit implements Action {
public readonly type = DarsActionTypes.ErrorSendingAudit;
constructor(public payload: { message: string }) {}
}
export class StartSendingAudit implements Action {
public readonly type = DarsActionTypes.StartSendingAudit;
constructor(
public payload: {
darsInstitutionCode: string;
darsDegreeProgramCode: string;
},
) {}
}
export class DoneSendingAudit implements Action {
public readonly type = DarsActionTypes.DoneSendingAudit;
constructor(
public payload: {
darsInstitutionCode: string;
darsDegreeProgramCode: string;
},
) {}
}
export class DismissAlert implements Action {
public readonly type = DarsActionTypes.DismissAlert;
constructor(public payload: { key: string }) {}
......
......@@ -11,6 +11,7 @@ import { DarsApiService } from '../services/api.service';
import { Alert, DarsDisclaimerAlert } from '@app/core/models/alert';
import { DegreePlannerApiService } from '@app/degree-planner/services/api.service';
import { AuditMetadata } from '../models/audit-metadata';
import { SingleAuditRequest } from '../models/single-audit-request';
import { StudentDegreeProgram } from '../models/student-degree-program';
import { of } from 'rxjs';
......@@ -100,4 +101,27 @@ export class DARSEffects {
);
}),
);
@Effect()
newAudit$ = this.actions$.pipe(
ofType(DarsActionTypes.StartSendingAudit),
flatMap((action: darsActions.StartSendingAudit) => {
const metadata = action.payload;
return this.api
.newAudit(metadata.darsInstitutionCode, metadata.darsDegreeProgramCode)
.pipe(
map(audit => {
return new darsActions.DoneSendingAudit(action.payload);
}),
);
}),
catchError(error => {
return of(
new darsActions.ErrorSendingAudit({
message: 'Unable to add course',
}),
);
}),
);
}
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