File

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

Description

Service to fetch badges

Index

Properties
Methods

Constructor

constructor(config: ConfigService, learner: LearnerService)

constructor

Parameters :
Name Type Optional Description
config ConfigService No

ConfigService reference

learner LearnerService No

LearnerService reference

Methods

Public getAllBadgeList
getAllBadgeList(req)

method to fetch badges from server.

Parameters :
Name Optional
req No
Returns : any
Public getDetailedBadgeAssertions
getDetailedBadgeAssertions(req, assertions)
Parameters :
Name Optional
req No
assertions No
Returns : any
Public initialize
initialize()
Returns : void

Properties

Private _badges$
Default value : new BehaviorSubject<any>(undefined)

BehaviorSubject Containing badges.

Private badges
Type : any

local variable Containing badges.

Public Readonly badges$
Type : Observable<any>
Default value : this._badges$.asObservable()

Read only observable Containing badges.

Public config
Type : ConfigService

reference of config service.

Public learner
Type : LearnerService

reference of lerner service.

import { ConfigService } from '@sunbird/shared';
import { LearnerService } from './../learner/learner.service';
import { Injectable } from '@angular/core';
import { Observable ,  BehaviorSubject } from 'rxjs';
import * as _ from 'lodash-es';
/**
 * Service to fetch badges
 */
@Injectable({
  providedIn: 'root'
})
export class BadgesService {
  /**
   * BehaviorSubject Containing badges.
   */
  private _badges$ = new BehaviorSubject<any>(undefined);
  /**
   * Read only observable Containing badges.
   */
  public readonly badges$: Observable<any> = this._badges$.asObservable();
  /**
   * local variable Containing badges.
   */
  private badges: any;
  /**
   * reference of config service.
   */
  public config: ConfigService;
  /**
   * reference of lerner service.
   */
  public learner: LearnerService;
  /**
   * constructor
   * @param {ConfigService} config ConfigService reference
   * @param {LearnerService} learner LearnerService reference
   */
  constructor(config: ConfigService, learner: LearnerService) {
    this.config = config;
    this.learner = learner;
  }
  public initialize() {
  }
  /**
   * method to fetch badges from server.
  */
  public getAllBadgeList(req) {
    const option = {
      url: this.config.urlConFig.URLS.BADGE.BADGE_CLASS_SEARCH,
      data: req
    };
    return this.learner.post(option);
  }

  public getDetailedBadgeAssertions(req, assertions) {
    return Observable.create(observer => {
      const option = {
        url: this.config.urlConFig.URLS.BADGE.BADGE_CLASS_SEARCH,
        data: req
      };
      this.learner.post(option).subscribe((badgeSearchResponse) => {
        if (badgeSearchResponse) {
          const detailedAssertions: any[] = assertions;
          for (const detailedAssertion of detailedAssertions) {
            const badgeFound: any = _.find(badgeSearchResponse.result.badges, { 'badgeId': detailedAssertion.badgeId });
            if (badgeFound) {
              detailedAssertion.description = badgeFound.description;
            }
            observer.next(detailedAssertion);
          }
          observer.complete();
        }
      });
    });
  }
}

results matching ""

    No results matching ""