Skip to content
Snippets Groups Projects
api.service.ts 1.86 KiB
Newer Older
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { DegreeProgram } from '../models/degree-program';
import { AuditMetadata } from '../models/audit-metadata';
import { StudentDegreeProgram } from '../models/student-degree-program';
import { environment } from './../../../environments/environment';

const HTTP_OPTIONS = {
  headers: new HttpHeaders({
    'Content-Type': 'applications/json',
  }),
};

@Injectable({ providedIn: 'root' })
export class DarsApiService {
  constructor(private http: HttpClient) {}

  /**
   * Get all degree programs, honors, and institution data.
   *
   * All the data for institutions, honors, and degree programs is static.
   * The backend is going to cache all this data in S3 and create a single
   * endpoint for us to hit and get all of it!
   */
  public getStaticData(): Observable<DegreeProgram[]> {
    return new Observable();
  }

  /**
   * Get a students degree programs.
   */
  public getStudentDegreePrograms(emplid: number) {
    const url = `${environment.apiDarsUrl}/student-degree-programs/${emplid}`;
    return this.http.get<StudentDegreeProgram[]>(url, HTTP_OPTIONS);
  }

  /**
   * Get audit metadata for all audits a user has.
   */
  public getAudits(): Observable<AuditMetadata[]> {
    const url = `${environment.apiDarsUrl}/audit-metadata`;
    return this.http.get<AuditMetadata[]>(url, HTTP_OPTIONS);
  }

  /**
   * Get a single audit.
   */
  public getAudit(reportId: number): Observable<any> {
    const url = `${environment.apiDarsUrl}/reports/${reportId}`;
    return this.http.get<any>(url, HTTP_OPTIONS);
  }

  /**
   * Request a new audit
   */
  public newAudit(): Observable<AuditMetadata> {
    const url = `${environment.apiDarsUrl}/single-audit-requests`;
    return this.http.post<AuditMetadata>(url, HTTP_OPTIONS);
  }
}