File

src/app/modules/core/services/tenant/tenant.service.ts

Description

This service returns the organization details.

Constructor

constructor(http: HttpClient, config: any)

The constructor

Parameters :
  • http : HttpClient

    Reference of HttpClient.

  • config : ConfigService

    Reference of ConfigService.

Methods

Public getTenantInfo
getTenantInfo(slug: string)

API call to gather organization details.

Parameters :
  • slug

    Organization details passed from main-header component.

Returns: void

Properties

Private _tenantData$
_tenantData$: BehaviorSubject<ITenantInfo>

BehaviorSubject containing tenant data.

config
config: any

reference of config service.

favicon
favicon: string

This variable holds favicon details.

http
http: HttpClient

reference of http.

tenantData
tenantData: ITenantData

Variable that holds tenant details.

Public tenantData$
tenantData$: Observable<ITenantInfo>

Read only observable containing tenant data.

import { ITenantData, ITenantInfo } from './interfaces';
import { ConfigService, ServerResponse } from '@sunbird/shared';
import { BehaviorSubject ,  Observable } from 'rxjs';
import { DataService } from '../data/data.service';
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { skipWhile } from 'rxjs/operators';

/**
 * This service returns the organization details.
 */

@Injectable({
  providedIn: 'root'
})
export class TenantService extends DataService {
  /**
   * BehaviorSubject containing tenant data.
   */
  private _tenantData$ = new BehaviorSubject<ITenantInfo>(undefined);
  /**
   * Read only observable containing tenant data.
   */
  public readonly tenantData$: Observable<ITenantInfo> = this._tenantData$.asObservable()
  .pipe(skipWhile(data => data === undefined || data === null));
  /**
   * reference of http.
   */
  http: HttpClient;
  /**
   * reference of config service.
   */
  config: ConfigService;
  /**
   * Variable that holds tenant details.
   */
  tenantData: ITenantData;
  /**
   * This variable holds favicon details.
   */
  favicon: string;

  /**
   * The constructor
   * @param {HttpClient} http Reference of HttpClient.
   * @param {ConfigService} config Reference of ConfigService.
   */
  constructor(http: HttpClient, config: ConfigService) {
    super(http);
    this.config = config;
    this.baseUrl = this.config.urlConFig.URLS.TENANT_PREFIX;
  }

  /**
   * API call to gather organization details.
   * @param slug Organization details passed from main-header component.
   */
  public getTenantInfo(slug?: string) {

    const url = `${this.config.urlConFig.URLS.TENANT.INFO + '/'}` + (slug ? slug : '');
    this.get({ url }).subscribe(
      (apiResponse: ServerResponse) => {
        this.tenantData = apiResponse.result;
        this._tenantData$.next({ err: null, tenantData: apiResponse.result });
      },
      (err: ServerResponse) => {
        this._tenantData$.next({ err: err, tenantData: undefined });
      }
    );
  }
}

results matching ""

    No results matching ""