import { Injectable } from '@angular/core' ; import { HttpClient , HttpParams } from '@angular/common/http' ; import { Observable } from 'rxjs' ; import { catchError , finalize , map , retry } from 'rxjs/operators' ; import { EntityService , IPagination } from '@ngx-starter-kit/shared' ; import { environment } from '@env/environment' ; import { AppNotification } from '@ngx-starter-kit/notifications' ; @ Injectable ( { providedIn : 'root' , } ) export class NotificationService extends EntityService < AppNotification > { public baseUrl = environment . API_BASE_URL ; readonly entityPath = 'notifications' ; constructor ( httpClient ) { super ( httpClient ) ; } getAll ( ) { const params = new HttpParams ( ) . set ( 'order' , 'ASC' ) . set ( 'read' , 'false' ) ; this . loadingSubject . next ( true ) ; return this . httpClient . get < IPagination < AppNotification > > ( `${ this . baseUrl }/${ this . entityPath }` , { params } ) . pipe ( retry ( 3 ) , catchError ( this . handleError ) , finalize ( ( ) => this . loadingSubject . next ( false ) ) , map ( ( data ) => data . items ) ) ; } delete ( id ) { this . loadingSubject . next ( true ) ; return this . httpClient . delete ( `${ this . baseUrl }/${ this . entityPath }/${ id }` ) . pipe ( catchError ( this . handleError ) , finalize ( ( ) => this . loadingSubject . next ( false ) ) ) ; } send ( id ) { this . loadingSubject . next ( true ) ; return this . httpClient . post ( `${ this . baseUrl }/${ this . entityPath }/send` , { id } ) . pipe ( catchError ( this . handleError ) , finalize ( ( ) => this . loadingSubject . next ( false ) ) ) ; } }