UNPKG

fabric8-planner

Version:
67 lines 2.5 kB
import { Injectable } from '@angular/core'; import { throwError } from 'rxjs'; import { catchError, map } from 'rxjs/operators'; import { HttpClientService } from '../shared/http-module/http.service'; var CustomQueryService = /** @class */ (function () { function CustomQueryService(http) { this.http = http; } /** * getCustomQueries - Fetches all the available custom queries * @param apiUrl - The url to get list of all filters * @return Observable of FilterModel[] - Array of filters */ CustomQueryService.prototype.getCustomQueries = function (apiUrl) { var _this = this; return this.http .get(apiUrl) .pipe(map(function (r) { return r.data; }), catchError(function (e) { return _this.handleError(e, 'Fetch iteration API returned some error - '); })); }; /** * Usage: This method create a new item * adds the new item to the big list * resolve the users for the item * re build the ID-Index map * * @param: WorkItem - workItem (Item to be created) */ CustomQueryService.prototype.create = function (customQuery, apiUrl) { var _this = this; var payload = JSON.stringify({ data: customQuery }); return this.http .post(apiUrl, payload) .pipe(map(function (r) { return r.data; }), catchError(function (e) { return _this.handleError(e, 'Creating custom query failed.'); })); }; /** * Usage: This method deletes a custom query * @param apiUrl ulr to the custom query */ CustomQueryService.prototype.delete = function (apiUrl) { var _this = this; return this.http .delete(apiUrl) .pipe(catchError(function (e) { return _this.handleError(e, 'Delete custom query failed'); })); }; /** * Error handling */ CustomQueryService.prototype.handleError = function (error, str) { if (error.status === 401) { console.log('You have been logged out.', error); } else { console.log(str, error.message); } return throwError(new Error(error.message)); }; CustomQueryService.decorators = [ { type: Injectable }, ]; /** @nocollapse */ CustomQueryService.ctorParameters = function () { return [ { type: HttpClientService, }, ]; }; return CustomQueryService; }()); export { CustomQueryService }; //# sourceMappingURL=custom-query.service.js.map