All files / src/app/shared/services url-builder.service.ts

74.36% Statements 29/39
30% Branches 6/20
61.54% Functions 8/13
81.48% Lines 22/27

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 47 48 49 50 5118x   18x   18x 34x   18x 109x     438x 109x     216x 107x     210x 105x     18x 1x     18x       18x 1x   18x       18x     18x         18x     18x  
import { Location } from '@angular/common';
 
import { URLVerbs } from '../constants/app.constants';
 
export class URLBuilderService {
  constructor(readonly base: string) {}
 
  private static concatURLSegments(segments: string[]): string {
    return segments.reduce(Location.joinWithSlash);
  }
 
  static buildURL(absolute: boolean, ...segments: string[]): string {
    return URLBuilderService.concatURLSegments([...(absolute ? ['/'] : []), ...segments]);
  }
 
  private getURL(verb: URLVerbs, Iabsolute = true, ...segments: string[]): string {
    return URLBuilderService.buildURL(absolute, this.base, verb, ...segments);
  }
 
  getCreate(Eabsolute = true): string {
    return this.getURL(URLVerbs.CREATE, absolute);
  }
 
  getCreateFrom(item: string, Eabsolute = true): string {
    return this.getURL(URLVerbs.CREATE, absolute, item);
  }
 
  getDelete(absolute = true): string {
    return this.getURL(URLVerbs.DELETE, absolute);
  }
 
  getEdit(item: string, Eabsolute = true): string {
    return this.getURL(URLVerbs.EDIT, absolute, item);
  }
  getUpdate(item: string, absolute = true): string {
    return this.getURL(URLVerbs.UPDATE, absolute, item);
  }
 
  getAdd(absolute = true): string {
    return this.getURL(URLVerbs.ADD, absolute);
  }
  getRemove(absolute = true): string {
    return this.getURL(URLVerbs.REMOVE, absolute);
  }
 
  // Prometheus wording
  getRecreate(item: string, absolute = true): string {
    return this.getURL(URLVerbs.RECREATE, absolute, item);
  }
}