File

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

Index

Methods

Constructor

constructor(base: string)
Parameters :
Name Type Optional
base string No

Methods

Static buildURL
buildURL(absolute: boolean, ...segments: string[])
Parameters :
Name Type Optional
absolute boolean No
segments string[] No
Returns : string
Private Static concatURLSegments
concatURLSegments(segments: string[])
Parameters :
Name Type Optional
segments string[] No
Returns : string
getAdd
getAdd(absolute)
Parameters :
Name Optional Default value
absolute No true
Returns : string
getCreate
getCreate(absolute)
Parameters :
Name Optional Default value
absolute No true
Returns : string
getDelete
getDelete(absolute)
Parameters :
Name Optional Default value
absolute No true
Returns : string
getEdit
getEdit(item: string, absolute)
Parameters :
Name Type Optional Default value
item string No
absolute No true
Returns : string
getRemove
getRemove(absolute)
Parameters :
Name Optional Default value
absolute No true
Returns : string
getUpdate
getUpdate(item: string, absolute)
Parameters :
Name Type Optional Default value
item string No
absolute No true
Returns : string
Private getURL
getURL(verb: URLVerbs, absolute, ...segments: string[])
Parameters :
Name Type Optional Default value
verb URLVerbs No
absolute No true
segments string[] No
Returns : string
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, absolute = true, ...segments: string[]): string {
    return URLBuilderService.buildURL(absolute, this.base, verb, ...segments);
  }

  getCreate(absolute = true): string {
    return this.getURL(URLVerbs.CREATE, absolute);
  }
  getDelete(absolute = true): string {
    return this.getURL(URLVerbs.DELETE, absolute);
  }

  getEdit(item: string, absolute = 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);
  }
}

result-matching ""

    No results matching ""