File

src/app/manage-learn/core/services/survey-provider.service.ts

Index

Methods

Constructor

constructor(localStorage: LocalStorageService, ulsdp: UpdateLocalSchoolDataService, utils: UtilsService, httpClient: HttpClient, loader: LoaderService, assessmentService: AssessmentApiService, router: Router, modalCtrl: ModalController, dhiti: DhitiApiService, toast: ToastController, commonUtilService: CommonUtilService)
Parameters :
Name Type Optional
localStorage LocalStorageService No
ulsdp UpdateLocalSchoolDataService No
utils UtilsService No
httpClient HttpClient No
loader LoaderService No
assessmentService AssessmentApiService No
router Router No
modalCtrl ModalController No
dhiti DhitiApiService No
toast ToastController No
commonUtilService CommonUtilService No

Methods

createExpiryMsg
createExpiryMsg(survey)
Parameters :
Name Optional
survey No
Returns : any
Async getDetailsById
getDetailsById(surveyId, solutionId)
Parameters :
Name Optional
surveyId No
solutionId No
Returns : Promise<any>
Async getDetailsByLink
getDetailsByLink(link)
Parameters :
Name Optional
link No
Returns : Promise<any>
Async showMsg
showMsg(option, popToRoot)
Parameters :
Name Optional Default value
option No
popToRoot No false
Returns : any
storeSurvey
storeSurvey(submissionId, survey)
Parameters :
Name Optional
submissionId No
survey No
Returns : any
viewAllAns
viewAllAns(payload)
Parameters :
Name Optional
payload No
Returns : any
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { ModalController, ToastController } from '@ionic/angular';
import { rejects } from 'assert';
import { LoaderService, LocalStorageService, UtilsService } from '..';
import { urlConstants } from '../constants/urlConstants';
import { AssessmentApiService } from './assessment-api.service';
import { UpdateLocalSchoolDataService } from './update-local-school-data.service';
import { SurveyMsgComponent } from '../../shared/components/survey-msg/survey-msg.component';
import { storageKeys } from '../../storageKeys';
import { DhitiApiService } from './dhiti-api.service';
import * as moment from 'moment';
import { CommonUtilService } from '@app/services';

@Injectable({
  providedIn: 'root',
})
export class SurveyProviderService {
  constructor(
    private localStorage: LocalStorageService,
    private ulsdp: UpdateLocalSchoolDataService,
    private utils: UtilsService,
    private httpClient: HttpClient,
    private loader: LoaderService,
    private assessmentService: AssessmentApiService,
    private router: Router,
    private modalCtrl: ModalController,
    private dhiti: DhitiApiService,
    private toast: ToastController,
    private commonUtilService: CommonUtilService
  ) {}

  // get all list
  // getSurveyListing(): Promise<any> {
  //   const url = AppConfigs.surveyFeedback.surveyListing;
  //   return new Promise((resolve, reject) => {
  //     this.apiProvider.httpGet(
  //       url,
  //       (success) => {
  //         resolve(success.result);
  //       },
  //       (err) => {
  //         reject(err);
  //       }
  //     );
  //   });
  // }

  // pass the link which is present in deeplink(deeplink last param)
  async getDetailsByLink(link): Promise<any> {
    let payload = await this.utils.getProfileInfo();
    const config = {
      url: urlConstants.API_URLS.SURVEY_FEEDBACK.GET_DETAILS_BY_ID + '/' + link,
      payload: payload,
    };

    return new Promise((resolve, reject) => {
      this.assessmentService.post(config).subscribe(
        (success) => {
          resolve(success);
        },
        (error) => {
          rejects(error);
        }
      );
    });
  }

  async getDetailsById(surveyId, solutionId): Promise<any> {
    let payload = await this.utils.getProfileInfo();
    let url = urlConstants.API_URLS.SURVEY_FEEDBACK.GET_DETAILS_BY_ID;
    if (surveyId) {
      url = `${url}/${surveyId}`;
    }
    url = url + `?solutionId=${solutionId}`;
    const config = {
      url: url,
      payload: payload,
    };

    return new Promise((resolve, reject) => {
      this.assessmentService.post(config).subscribe(
        (success) => {
          resolve(success);
        },
        (error) => {
          rejects(error);
        }
      );
    });
  }

  storeSurvey(submissionId, survey) {
    return this.localStorage
      .getLocalStorage(storageKeys.submissionIdArray)
      .then((submissionArr) => {
        const x = submissionArr.includes(submissionId);
        if (!x) {
          survey['assessment']['evidences'][0].startTime = Date.now();
          survey['survey'] = true;
          this.localStorage.setLocalStorage(this.utils.getAssessmentLocalStorageKey(submissionId), survey);
          this.ulsdp.updateSubmissionIdArr(submissionId);
          return survey;
        } else {
          return survey;
        }
      })
      .catch((err) => {
        survey['assessment']['evidences'][0].startTime = Date.now();
        survey['survey'] = true;
        this.localStorage.setLocalStorage(this.utils.getAssessmentLocalStorageKey(submissionId), survey);
        this.ulsdp.updateSubmissionIdArr(submissionId);
        return survey;
      });
  }

  async showMsg(option, popToRoot = false) {
    popToRoot ? this.router.navigate(['']) : null;
    const modal = await this.modalCtrl.create({
      component: SurveyMsgComponent,
      componentProps: { option: option },
    });
    await modal.present();
  }

  viewAllAns(payload) {
    this.loader.startLoader();
    let url = urlConstants.API_URLS.SURVEY_FEEDBACK.GET_ALL_ANSWERS;
    const config = {
      url: url,
      payload: payload,
    };
    return new Promise((resolve, reject) => {
      this.dhiti.post(config).subscribe(
        (success) => {
          this.loader.stopLoader();
          resolve(success);
        },
        (error) => {
          this.toast.create(error.message);
          this.loader.stopLoader();
          reject();
        }
      );
    });
  }

  createExpiryMsg(survey) {
    const format = 'Do MMM YY';
    const today = Date.now();
    const expiryDate:any = new Date(survey.endDate);
    const diffTime = expiryDate - today;
    const diff = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
    if (diff == 1)
      return (survey.generatedExpMsg = this.commonUtilService.translateMessage('FRMELEMENTS_MSG_EXPIRE_IN_ONE_DAY'));
    if (diff == 2)
      return (survey.generatedExpMsg = this.commonUtilService.translateMessage('FRMELEMENTS_MSG_EXPIRE_IN_TWO_DAY'));
    if (diff > 2)
      return (survey.generatedExpMsg =
        this.commonUtilService.translateMessage('FRMELEMENTS_MSG_VALID_TILL') + ' ' + moment(survey.endDate).format(format));
    if (diff <= 0)
      return (survey.generatedExpMsg =
        this.commonUtilService.translateMessage('FRMELEMENTS_MSG_EXPIRED_ON') + ' ' + moment(survey.endDate).format(format));
  }
}

results matching ""

    No results matching ""