UNPKG

ns2-front-module-common

Version:
117 lines 4.7 kB
import { Injectable } from '@angular/core'; import { URLSearchParams } from '@angular/http'; // Services import { HttpService } from './http.service'; import { NotificationUrls } from '../urls/notification-urls.model'; // RxJS import { Observable } from 'rxjs'; var NotificationService = (function () { function NotificationService(httpService) { this.httpService = httpService; } NotificationService.prototype.getInfo = function () { var _this = this; return new Promise(function (resolve, reject) { var url = NotificationUrls.messages; _this.httpService.get(url) .map(function (response) { return response.json(); }) .map(function (response) { return response.data; }) .subscribe(resolve, reject); }); }; /** * Получает список обработанных уведомлений * @param {any} query Параметры запроса * @returns {Promise<ResponseListModel<NotificationItemModel>>} */ NotificationService.prototype.getProcessedList = function (query) { var _this = this; return new Promise(function (resolve, reject) { var url = NotificationUrls.processedList; var params = new URLSearchParams(); if (query) { var keys = Object.keys(query); for (var i = 0; i < keys.length; i++) { var key = keys[i]; params.set(key, query[key]); } } _this.httpService.get(url, { params: params }) .map(function (response) { return response.json(); }) .map(function (response) { return response.data; }) .subscribe(resolve, reject); }); }; /** * Получает список необработанных уведомлений * @param {any} query Параметры запроса * @returns {Promise<ResponseListModel<NotificationItemModel>>} */ NotificationService.prototype.getUnProcessedList = function (query) { var _this = this; return new Promise(function (resolve, reject) { var url = NotificationUrls.unProcessedList; var params = new URLSearchParams(); if (query) { var keys = Object.keys(query); for (var i = 0; i < keys.length; i++) { var key = keys[i]; params.set(key, query[key]); } } _this.httpService.get(url, { params: params }) .map(function (response) { return response.json(); }) .map(function (response) { return response.data; }) .subscribe(resolve, reject); }); }; /** * Принять уведомление * @param {string} operation_guid Guid операции * @returns {Observable<IResponse<any>>} */ NotificationService.prototype.acceptNotification = function (operation_guid) { var _this = this; var url = NotificationUrls.actionWithNotification + "/" + operation_guid; var params = new URLSearchParams(); return new Observable(function (observer) { _this.httpService.post(url, { params: params }) .map(function (response) { return response.json(); }) .subscribe(function (response) { observer.next(response.data); observer.complete(); }, function (err) { observer.error(err); }); }); }; /** * Отклонить уведомление * @param {string} operation_guid Guid операции * @returns {Observable<IResponse<any>>} */ NotificationService.prototype.declineNotification = function (operation_guid) { var _this = this; var url = NotificationUrls.actionWithNotification + "/" + operation_guid; return new Observable(function (observer) { _this.httpService.delete(url) .map(function (response) { return response.json(); }) .subscribe(function (response) { observer.next(response.data); observer.complete(); }, function (err) { observer.error(err); }); }); }; return NotificationService; }()); export { NotificationService }; NotificationService.decorators = [ { type: Injectable }, ]; /** @nocollapse */ NotificationService.ctorParameters = function () { return [ { type: HttpService, }, ]; }; //# sourceMappingURL=notification.service.js.map