import { Injectable } from '@angular/core' ; import { HttpRequest , HttpHandler , HttpEvent , HttpInterceptor } from '@angular/common/http' ; import { Observable } from 'rxjs' ; import { Store } from './../services/store.service' ; import { filter } from 'rxjs/operators' ; import { UntilDestroy , untilDestroyed } from '@ngneat/until-destroy' ; import { RequestMethodEnum } from '@gauzy/contracts' ; @ UntilDestroy ( ) @ Injectable ( ) export class TenantInterceptor implements HttpInterceptor { constructor ( private store ) { } intercept ( request , next ) { this . store . user$ . pipe ( untilDestroyed ( this ) , filter ( ( user ) => ! ! user ) ) . subscribe ( ( user ) => { const tenantId = user . tenantId ; if ( request . method === RequestMethodEnum . DELETE ) { const params = { tenantId } ; request = request . clone ( { setParams : params } ) ; } request = request . clone ( { setHeaders : { 'Tenant-Id' : `${ tenantId }` } } ) ; } ) ; return next . handle ( request ) ; } }