daily pastebin goal
16%
SHARE
TWEET

Scheduler Service

a guest Nov 21st, 2017 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {Injectable} from '@angular/core';
  2. import {BaseRequestOptions, Http, Response, URLSearchParams} from '@angular/http';
  3. import {Observable} from 'rxjs/Rx';
  4. import {isNullOrUndefined} from "util";
  5. import {JhiDateUtils} from "ng-jhipster";
  6.  
  7. @Injectable()
  8. export class SchedulerService {
  9.  
  10.     private resourceUrl = 'api/scheduler';
  11.  
  12.     constructor(private http: Http,
  13.                 private dateUtils: JhiDateUtils) {
  14.     }
  15.  
  16.  
  17.     /**
  18.      * returns array of shedulers Objects
  19.      */
  20.     getSchedulers(req?: any): Observable<any> {
  21.         const options = this.createRequestOption(req);
  22.        
  23.         return this.http.get(`${this.resourceUrl}`)
  24.         .map((res: Response) => res)
  25.         .catch((error:any) => Observable.throw(error.json().error || 'Server error'));
  26.     }
  27.  
  28.     protected createRequestOption(req?: any): BaseRequestOptions {
  29.         const options: BaseRequestOptions = new BaseRequestOptions();
  30.         const params: URLSearchParams = new URLSearchParams();
  31.  
  32.         if (req) {
  33.             params.set('page', req.page);
  34.             params.set('size', req.size);
  35.             if (req.sort) {
  36.                 params.paramsMap.set('sort', req.sort);
  37.             }
  38.             params.set('query', req.query);
  39.  
  40.             options.search = params;
  41.         }
  42.         return options;
  43.     }
  44. }
RAW Paste Data
Top