import { Injectable } from '@angular/core'; import { InAppNotification } from '@app/core/model/inapp-notification/inapp-notification.model'; import { InAppNotificationLookup } from '@app/core/query/inapp-notification.lookup'; import { BaseHttpParams } from '@common/http/base-http-params'; import { InterceptorType } from '@common/http/interceptors/interceptor-type'; import { QueryResult } from '@common/model/query-result'; import { Guid } from '@common/types/guid'; import { Observable, throwError } from 'rxjs'; import { catchError } from 'rxjs/operators'; import { BaseHttpV2Service } from '../http/base-http-v2.service'; import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class InAppNotificationService { constructor(private http: BaseHttpV2Service, private configurationService: ConfigurationService) { } private get apiBase(): string { return `${this.configurationService.notificationServiceAddress}api/inapp-notification`; } query(q: InAppNotificationLookup): Observable> { const url = `${this.apiBase}/query`; return this.http .post>(url, q).pipe( catchError((error: any) => throwError(error))); } getSingle(id: Guid, reqFields: string[] = []): Observable { const url = `${this.apiBase}/${id}`; const options = { params: { f: reqFields } }; return this.http .get(url, options).pipe( catchError((error: any) => throwError(error))); } read(id: Guid): Observable { const url = `${this.apiBase}/${id}/read`; return this.http .post(url, {}).pipe( catchError((error: any) => throwError(error))); } countUnread(): Observable { const url = `${this.apiBase}/count-unread`; const params = new BaseHttpParams(); params.interceptorContext = { excludedInterceptors: [InterceptorType.ProgressIndication] }; const options = { params: params }; return this.http .get(url, options).pipe( catchError((error: any) => throwError(error))); } readAll(): Observable { const url = `${this.apiBase}/read-all`; return this.http .post(url, {}).pipe( catchError((error: any) => throwError(error))); } delete(id: Guid): Observable { const url = `${this.apiBase}/${id}`; return this.http .delete(url).pipe( catchError((error: any) => throwError(error))); } }