diff --git a/frontend/src/app/services/fasten-api.service.ts b/frontend/src/app/services/fasten-api.service.ts index 94b7da12..5b8a6703 100644 --- a/frontend/src/app/services/fasten-api.service.ts +++ b/frontend/src/app/services/fasten-api.service.ts @@ -1,12 +1,8 @@ import { Injectable } from '@angular/core'; -import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { HttpClient } from '@angular/common/http'; import {Observable} from 'rxjs'; -import { Router } from '@angular/router'; import {map} from 'rxjs/operators'; import {ResponseWrapper} from '../models/response-wrapper'; -import {Source} from '../models/fasten/source'; -import {User} from '../models/fasten/user'; -import {ResourceFhir} from '../models/fasten/resource_fhir'; import {MetadataSource} from '../models/fasten/metadata-source'; @Injectable({ @@ -14,121 +10,15 @@ import {MetadataSource} from '../models/fasten/metadata-source'; }) export class FastenApiService { - AUTH_TOKEN_KEY = 'token'; - - constructor(private _httpClient: HttpClient, private router: Router) { + constructor(private _httpClient: HttpClient) { } - getBasePath(): string { + private getBasePath(): string { return window.location.pathname.split('/web').slice(0, 1)[0]; } - // Auth functions - token() { - return localStorage.getItem(this.AUTH_TOKEN_KEY); - } - isAuthenticated() { - return !!localStorage.getItem(this.AUTH_TOKEN_KEY); - } - - logout() { - localStorage.removeItem(this.AUTH_TOKEN_KEY); - } - - signup(newUser: User): Observable { - return this._httpClient.post(`${this.getBasePath()}/api/auth/signup`, newUser).pipe( - map((res: any) => { - if(res.success){ - localStorage.setItem(this.AUTH_TOKEN_KEY, res.data); - return res.data - } else { - throw new Error(res.error) - } - - } - )); - } - - - signin(username: string, pass: string): Observable { - - const data = { - username: username, - password: pass - }; - - return this._httpClient.post(`${this.getBasePath()}/api/auth/signin`, data).pipe( - map((res: any) => { - if(res.success){ - localStorage.setItem(this.AUTH_TOKEN_KEY, res.data); - return res.data - } else { - throw new Error(res.error) - } - } - )); - } - - - /* - SECURE ENDPOINTS - */ - - createManualSource(file: File): Observable { - - const formData = new FormData(); - formData.append('file', file); - - return this._httpClient.post(`${this.getBasePath()}/api/secure/source/manual`, formData) - .pipe( - map((response: ResponseWrapper) => { - console.log("MANUAL SOURCE RESPONSE", response) - return response.data as Source - }) - ); - } - - syncSource(sourceId: string): Observable { - return this._httpClient.post(`${this.getBasePath()}/api/secure/source/${sourceId}/sync`, {}) - .pipe( - map((response: ResponseWrapper) => { - console.log("SOURCE RESPONSE", response) - return response.data - }) - ); - } - - getResources(sourceResourceType?: string, sourceID?: string): Observable { - let queryParams = {} - if(sourceResourceType){ - queryParams["sourceResourceType"] = sourceResourceType - } - if(sourceID){ - queryParams["sourceID"] = sourceID - } - - return this._httpClient.get(`${this.getBasePath()}/api/secure/resource/fhir`, {params: queryParams}) - .pipe( - map((response: ResponseWrapper) => { - console.log("RESPONSE", response) - return response.data as ResourceFhir[] - }) - ); - } - - getResourceBySourceId(sourceId: string, resourceId: string): Observable { - - return this._httpClient.get(`${this.getBasePath()}/api/secure/resource/fhir/${sourceId}/${resourceId}`) - .pipe( - map((response: ResponseWrapper) => { - console.log("RESPONSE", response) - return response.data as ResourceFhir - }) - ); - } - - getMetadataSources(): Observable<{[name: string]: MetadataSource}> { - return this._httpClient.get(`${this.getBasePath()}/api/metadata/source`) + public GetMetadataSources(): Observable<{[name: string]: MetadataSource}> { + return this._httpClient.get(`${this.getBasePath()}/api/metadata/source`) .pipe( map((response: ResponseWrapper) => { console.log("Metadata RESPONSE", response)