File

src/app/modules/learn/services/course-batch/course-batch.service.ts

Index

Properties
Methods

Constructor

constructor(searchService: SearchService, userService: UserService, content: ContentService, configService: ConfigService, learnerService: LearnerService)
Parameters :
Name Type Optional
searchService SearchService No
userService UserService No
content ContentService No
configService ConfigService No
learnerService LearnerService No

Methods

addUsersToBatch
addUsersToBatch(request, batchId)
Parameters :
Name Optional
request No
batchId No
Returns : any
batchSearch
batchSearch(requestParam: SearchParam)
Parameters :
Name Type Optional
requestParam SearchParam No
createBatch
createBatch(request)
Parameters :
Name Optional
request No
Returns : any
enrollToCourse
enrollToCourse(data)
Parameters :
Name Optional
data No
Returns : any
getAllBatchDetails
getAllBatchDetails(searchParams)
Parameters :
Name Optional
searchParams No
getBatchDetails
getBatchDetails(bathId)
Parameters :
Name Optional
bathId No
Returns : any
getcertificateDescription
getcertificateDescription(enrolledBatchInfo)
Parameters :
Name Optional
enrolledBatchInfo No
Returns : { isCertificate: boolean; description: string; }
getEnrolledBatchDetails
getEnrolledBatchDetails(batchId)
Parameters :
Name Optional
batchId No
Returns : any
getEnrollToBatchDetails
getEnrollToBatchDetails(bathId)
Parameters :
Name Optional
bathId No
Returns : any
getParticipantList
getParticipantList(data)
Parameters :
Name Optional
data No
Returns : any
getUpdateBatchDetails
getUpdateBatchDetails(bathId)
Parameters :
Name Optional
bathId No
Returns : any
getUserList
getUserList(requestParam: SearchParam)
Parameters :
Name Type Optional Default value
requestParam SearchParam No {}
removeUsersFromBatch
removeUsersFromBatch(batchId, request)
Parameters :
Name Optional
batchId No
request No
Returns : any
setEnrollToBatchDetails
setEnrollToBatchDetails(enrollBatchDetails: any)
Parameters :
Name Type Optional
enrollBatchDetails any No
Returns : void
setUpdateBatchDetails
setUpdateBatchDetails(enrollBatchDetails: any)
Parameters :
Name Type Optional
enrollBatchDetails any No
Returns : void
unenrollFromCourse
unenrollFromCourse(data)
Parameters :
Name Optional
data No
Returns : any
updateBatch
updateBatch(request)
Parameters :
Name Optional
request No
Returns : any

Properties

Private _enrolledBatchDetails
Type : any
Private _enrollToBatchDetails
Type : any
Private _updateBatchDetails
Type : any
Public configService
Type : ConfigService
Public content
Type : ContentService
Private defaultUserList
Type : any
Public learnerService
Type : LearnerService
Public searchService
Type : SearchService
Public updateEvent
Default value : new EventEmitter()
Public userService
Type : UserService
import { of as observableOf, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { Injectable, EventEmitter } from '@angular/core';
import { ConfigService, ServerResponse } from '@sunbird/shared';
import { SearchParam, LearnerService, UserService, ContentService, SearchService } from '@sunbird/core';
import * as _ from 'lodash-es';

@Injectable({
  providedIn: 'root'
})
export class CourseBatchService {
  private _enrollToBatchDetails: any;
  private _updateBatchDetails: any;
  public updateEvent = new EventEmitter();
  private _enrolledBatchDetails: any;
  private defaultUserList: any;
  constructor(public searchService: SearchService, public userService: UserService, public content: ContentService,
    public configService: ConfigService,
    public learnerService: LearnerService) { }
  getAllBatchDetails(searchParams) {
    return this.batchSearch(searchParams);
  }
  batchSearch(requestParam: SearchParam): Observable<ServerResponse> {
    const option = {
      url: this.configService.urlConFig.URLS.BATCH.GET_BATCHS,
      param : {...requestParam.params},
      data: {
        request: {
          filters: requestParam.filters,
          limit: requestParam.limit,
          sort_by: requestParam.sort_by
        }
      }
    };
    return this.learnerService.post(option);
  }
  getUserList(requestParam: SearchParam = {}): Observable<ServerResponse> {
    if (_.isEmpty(requestParam) && this.defaultUserList) {
      return observableOf(this.defaultUserList);
    } else {
      const request = _.cloneDeep(requestParam);
      const option = {
        url: this.configService.urlConFig.URLS.ADMIN.USER_SEARCH,
        data: {
          request: {
            filters: requestParam.filters || {},
            query: requestParam.query || ''
          }
        }
      };
      if (requestParam.limit) {
        option.data.request['limit'] = requestParam.limit;
      }
      const mentorOrg = this.userService.userProfile.roleOrgMap['CONTENT_CREATOR'];
      if (mentorOrg && mentorOrg.includes(this.userService.rootOrgId)) {
        option.data.request.filters['rootOrgId'] = this.userService.rootOrgId;
      } else if (mentorOrg) {
        option.data.request.filters['organisations.organisationId'] = mentorOrg;
      }
      option.data.request.filters['organisations.roles'] = ['COURSE_MENTOR'];
      return this.learnerService.post(option).pipe(map((data) => {
        if (_.isEmpty(requestParam)) {
          this.defaultUserList = data;
        }
        return data;
      }));
    }
  }
  getBatchDetails(bathId) {
    const option = {
      url: `${this.configService.urlConFig.URLS.BATCH.GET_DETAILS}/${bathId}`
    };
    return this.learnerService.get(option);
  }
  setEnrollToBatchDetails(enrollBatchDetails: any) {
    this._enrollToBatchDetails = enrollBatchDetails;
  }
  setUpdateBatchDetails(enrollBatchDetails: any) {
    this._updateBatchDetails = enrollBatchDetails;
  }
  getEnrollToBatchDetails(bathId) {
    if (this._enrollToBatchDetails && bathId === this._enrollToBatchDetails.identifier) {
      return observableOf(this._enrollToBatchDetails);
    } else {
      return this.getBatchDetails(bathId).pipe(map((data) => {
        return data.result.response;
      }));
    }
  }
  getUpdateBatchDetails(bathId) {
    if (this._updateBatchDetails && bathId === this._updateBatchDetails.identifier) {
      return observableOf(this._updateBatchDetails);
    } else {
      return this.getBatchDetails(bathId).pipe(map((date) => {
        return date.result.response;
      }));
    }
  }

  getParticipantList(data) {
    const options = {
      url: this.configService.urlConFig.URLS.BATCH.GET_PARTICIPANT_LIST,
      data: data
    };
    return this.learnerService.post(options).pipe(map((response: any) => {
      return _.get(response, 'result.batch.participants') || [];
    }));
  }

  enrollToCourse(data) {
    const options = {
      url: this.configService.urlConFig.URLS.COURSE.ENROLL_USER_COURSE,
      data: data
    };
    return this.learnerService.post(options);
  }
  unenrollFromCourse(data) {
    const options = {
      url: this.configService.urlConFig.URLS.COURSE.UNENROLL_USER_COURSE,
      data: data
    };
    return this.learnerService.post(options);
  }
  createBatch(request) {
    const option = {
      url: this.configService.urlConFig.URLS.BATCH.CREATE,
      data: {
        request: request
      }
    };
    return this.learnerService.post(option);
  }
  updateBatch(request) {
    const option = {
      url: this.configService.urlConFig.URLS.BATCH.UPDATE,
      data: {
        request: request
      }
    };
    return this.learnerService.patch(option);
  }
  addUsersToBatch(request, batchId) {
    const option = {
      url: this.configService.urlConFig.URLS.BATCH.ADD_USERS + '/' + batchId,
      data: {
        request: request
      }
    };
    return this.learnerService.post(option);
  }

  removeUsersFromBatch(batchId, request) {
    const option = {
      url: this.configService.urlConFig.URLS.BATCH.REMOVE_USERS + '/' + batchId,
      data: request
    };
    return this.learnerService.post(option);
  }
  getEnrolledBatchDetails(batchId) {
    if (this._enrolledBatchDetails && this._enrolledBatchDetails.identifier === batchId) {
      return observableOf(this._enrolledBatchDetails);
    } else {
      return this.getBatchDetails(batchId).pipe(map((data) => {
        this._enrolledBatchDetails = data.result.response;
        return data.result.response;
      }));
    }
  }
  getcertificateDescription(enrolledBatchInfo) {
    let certificateDescription = {isCertificate: false, description: ''};
    const certificateTemplate = _.get(enrolledBatchInfo, 'cert_templates');
    if (certificateTemplate && Object.keys(certificateTemplate).length !== 0) {
      const templateKey = Object.keys(certificateTemplate);
      const description = certificateTemplate[templateKey[0]].description;
      if (description) {
        certificateDescription = {
          isCertificate: true,
          description: description
        };
      } else {
        certificateDescription = {
          isCertificate: true,
          description: ''
        };
      }
    }
    return certificateDescription;
  }
}

results matching ""

    No results matching ""