All files / src/app/services dynamic-component.service.ts

85.71% Statements 12/14
75% Branches 3/4
87.5% Functions 7/8
84.61% Lines 11/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46                  37x   2x   2x 2x                   2x       2x       1x 1x       1x 1x       1x      
import { Injectable } from '@angular/core';
import { environment } from '../../environments/environment';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { CustomView } from '../models/customView';
import { Observable } from 'rxjs';
 
@Injectable({
  providedIn: 'root'
})
export class DynamicComponentService {
 
  apiUrl: string = environment['apiUrl'];
 
  constructor(private http:HttpClient) {
    Iif(!this.apiUrl){
      this.apiUrl = window.location.protocol+"//"+window.location.hostname.toLowerCase()+':5001';
    }
  }
 
  getCustomViews(): Observable<CustomView[]>{
    return this.http.get<CustomView[]>(`${this.apiUrl}/custom-views`);
  }
 
  getCustomViewsFromUserId(userId: string): Observable<CustomView[]>{
    return this.http.get<CustomView[]>(`${this.apiUrl}/users/${userId}/custom-views`);
  }
 
  getCustomViewById(customViewId: string): Observable<CustomView>{
    return this.http.get<CustomView>(`${this.apiUrl}/custom-views/${customViewId}`);
  }
 
  createCustomView(customView: CustomView): Observable<CustomView>{
    const options = { headers: new HttpHeaders().set('Content-type', 'application/json') };
    return this.http.post<CustomView>(`${this.apiUrl}/custom-views`, {"name": customView.name, "user_id": customView.user_id, "configuration": customView.configuration}, options);
  }
 
  updateCustomView(customView: CustomView): Observable<CustomView>{
    const options = { headers: new HttpHeaders().set('Content-type', 'application/json') };
    return this.http.patch<CustomView>(`${this.apiUrl}/custom-views/${customView.id}`, {"name": customView.name, "user_id": customView.user_id, "configuration": customView.configuration}, options);
  }
 
  deleteCustomView(customViewId: string): Observable<boolean>{
    return this.http.delete<boolean>(`${this.apiUrl}/custom-views/${customViewId}`);
  }
}