Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.1 kB
1
Indexable
Never
private getRequestObservables(caseIds, prefillInfo, componentHistory) {
    const observables = {};
    if (!caseIds.aggregateIdentifier && prefillInfo) {
      this.toastNotif.showNotification(ToastSeverityList.Warn, `WRONG CONFIGURATION!! You want prefill with a data which is unavailable`)
      return of({});
    }
    Object.keys(prefillInfo).forEach((key) => {
      if(key==='GeneralInformation' || key === 'GENERAL_INFORMATION'){
        observables[key] = this.formService
          .getCaseGeneralInformation(this.aggregateIdentifier).pipe(
            map(caseGeneralInfo=>caseGeneralInfo.Payload)
          )
      } else {
        const workflowComponent = componentHistory.find(history=>history.WorkflowComponentCode === key);
        if(!workflowComponent){
          this.toastNotif.showNotification(ToastSeverityList.Warn, "You want to prefill from a component which is not found in the workflow history. I still try to prefill it from the subprocess.")
        }
        observables[key] = this.getCaseInformation(
          workflowComponent?.AggregateIdentifier || caseIds.aggregateIdentifier,
          workflowComponent?.SubProcessIdentifier || caseIds.subProcessId,
          key,
        ).pipe(
          map((command) => {
            if(!command?.Payload?.Data?.length){
              return this.formService.tryToLoadOldTableDate(caseIds.aggregateIdentifier, caseIds.subProcessId, key, this.formId);
            }else{
              return command.Payload.Data
            }
          }),
          catchError((error) => {
            return this.formService.tryToLoadOldTableDate(caseIds.aggregateIdentifier, caseIds.subProcessId, key, this.formId);
          }),
          catchError((err) => {
            this.toastNotif.showNotification(
              ToastSeverityList.Warn,
              `The prefill from the form ${key} is not possible, because the endpoint is not reachable`,
            );
            return of({});
          }),
        );
      }
    });
    return Object.keys(observables).length ? forkJoin(observables).pipe(catchError((error) => of({}))) : of({});
  }