File

src/app/modules/org-management/services/org-type/org-type.service.ts

Description

Service to manage organisation type http calls

Index

Properties
Methods

Constructor

constructor(learner: LearnerService, config: ConfigService)

Default method of class GeoExplorerService

Parameters :
Name Type Optional Description
learner LearnerService No

Contains learner service reference

config ConfigService No

Contains config service reference

Methods

addOrgType
addOrgType(orgName: string)

Function to add organisation type

Parameters :
Name Type Optional
orgName string No
getOrgTypes
getOrgTypes()

Function to get organisation types

Returns : void
updateOrgType
updateOrgType(orgDetails)

Function to update organisation type

Parameters :
Name Optional
orgDetails No

Properties

Private _orgTypeData$
Default value : new BehaviorSubject<IorgTypeData>(undefined)

BehaviorSubject containing organisation listing data.

Public config
Type : ConfigService

Contains config service reference

Public learner
Type : LearnerService

Contains learner service reference

Public Readonly orgTypeData$
Type : Observable<IorgTypeData>
Default value : this._orgTypeData$.asObservable()

Read only observable containing organisation listing data.

orgTypeUpdateEvent
Default value : new EventEmitter()

To listen event after organisation type update

import {map} from 'rxjs/operators';
import { Injectable, EventEmitter } from '@angular/core';
import { LearnerService } from '@sunbird/core';
import { ConfigService, ServerResponse } from '@sunbird/shared';
import { Observable ,  BehaviorSubject } from 'rxjs';
import { IorgTypeData } from './../../interfaces';

/**
 * Service to manage organisation type http calls
 */
@Injectable()

/**
 * @class OrgTypeService to manage organisation type http call
 */
export class OrgTypeService {

  /**
  * BehaviorSubject containing organisation listing data.
  */
  private _orgTypeData$ = new BehaviorSubject<IorgTypeData>(undefined);

  /**
   * Read only observable containing organisation listing data.
   */
  public readonly orgTypeData$: Observable<IorgTypeData> = this._orgTypeData$.asObservable();

  /**
  * To listen event after organisation type update
  */
  orgTypeUpdateEvent = new EventEmitter();

  /**
   * Contains config service reference
   */
  public config: ConfigService;

  /**
   * Contains learner service reference
   */
  public learner: LearnerService;

  /**
   * Default method of class GeoExplorerService
   *
   * @param {LearnerService} learner Contains learner service reference
   * @param {ConfigService} config Contains config service reference
   */
  constructor(learner: LearnerService, config: ConfigService) {
    this.config = config;
    this.learner = learner;
  }

  /**
   * Function to get organisation types
   */
  getOrgTypes(): void {
    const option = {
      url: this.config.urlConFig.URLS.ORG_TYPE.GET
    };
    this.learner.get(option).subscribe(
      (data: ServerResponse) => {
        this._orgTypeData$.next({ orgTypeData: data, err: null });
      },
      (err: ServerResponse) => {
        this._orgTypeData$.next({ orgTypeData: null, err: err });
      }
    );
  }

  /**
   * Function to add organisation type
   */
  addOrgType(orgName: string): Observable<ServerResponse> {
    const option = {
      url: this.config.urlConFig.URLS.ORG_TYPE.ADD,
      data: {
        'request': {
          'name': orgName
        }
      }
    };
    return this.learner.post(option).pipe(map(data => {
      this.getOrgTypes();
      return data;
    }));
  }

  /**
   * Function to update organisation type
   */
  updateOrgType(orgDetails): Observable<ServerResponse> {
    const option = {
      url: this.config.urlConFig.URLS.ORG_TYPE.UPDATE,
      data: {
        'request': orgDetails
      }
    };
    return this.learner.patch(option).pipe(map(data => {
      this.orgTypeUpdateEvent.emit(orgDetails);
      return data;
    }));
  }
}

results matching ""

    No results matching ""