import { Injectable } from '@angular/core'; import { HttpClient, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs'; import { catchError, tap } from 'rxjs/operators'; import { HttpErrorHandler, HandleError } from '../../../src/auth/http-error-handler.service'; import { AuthService } from '../../../src/auth/auth.service'; import { AppConfig } from '../../../src/AppConfig/AppConfig'; import { BaseService } from '../../../src/baseclass/BaseService'; import { SyncResponseErrorHandleService } from '../../../src/route/SyncResponseErrorHandle'; import { NotificationClass, Notification } from '../../interface/Notification'; import { NotificationSummary, NotificationSummaryClass } from '../../interface/NotificationSummary'; @Injectable() export class NotificationService extends BaseService { public handleError: HandleError; constructor( public syncResponseErrorHandleService: SyncResponseErrorHandleService, public authService: AuthService, public http: HttpClient, public httpErrorHandler: HttpErrorHandler) { super(authService, httpErrorHandler, http, AppConfig.settings.apiserviceurl, 'NotificationClass', '', syncResponseErrorHandleService); this.handleError = httpErrorHandler.createHandleError('NotificationService'); } apiserviceurl = AppConfig.settings.ipmsbaseurl; apiUrl = 'api/Notification/'; GetByRecipient(userName: string): Observable { return this.http.get(this.apiserviceurl + this.apiUrl + 'GetByRecipient/' + userName, { headers: this.GetHeaders(), }) .pipe( catchError(this.handleError('GetByRecipient', [])) ); } GetByRecipientAndModule(userName: string, moduleName: string): Observable { return this.http.get(this.apiserviceurl + this.apiUrl + 'GetByRecipientAndModule/' + userName + '/' + moduleName, { headers: this.GetHeaders(), }) .pipe( catchError(this.handleError('GetByRecipientAndModule', [])) ); } GetNotificationSummary(userName: string): Observable { return this.http.get(this.apiserviceurl + this.apiUrl + 'GetNotificationSummary/' + userName, { headers: this.GetHeaders(), }) .pipe( catchError(this.handleError('GetNotificationSummary', null)) ); } BulkRead(notificationList: NotificationClass[]): Observable { return this.http.post(this.apiserviceurl + this.apiUrl + 'BulkRead', notificationList, { headers: this.GetHeaders(), }) .pipe( tap(r => { this.syncResponseErrorHandleService.SyncResponseErrorHandle(r); }), catchError(this.handleError('BulkRead', null)) ); } BulkDelete(notificationList: NotificationClass[]): Observable { return this.http.post(this.apiserviceurl + this.apiUrl + 'BulkDelete', notificationList, { headers: this.GetHeaders(), }) .pipe( tap(r => { this.syncResponseErrorHandleService.SyncResponseErrorHandle(r); }), catchError(this.handleError('BulkDelete', null)) ); } }