getResultforSql()

in frontend/src/app/agent-chat/agent-chat.component.ts [66:98]


  getResultforSql() {
    this.resultLoader = true;
    // Subscribe to the response data observable
    this.homeService.runQuery(this.msg?.generate_sql.GeneratedSQL, this.homeService.getSelectedDbGrouping(), this.msg?.user_question, this.homeService.getSessionId())
      .pipe(takeUntil(this._destroy$)).subscribe((res: any) => {
        const data = JSON.parse(res.KnownDB);
        if (res && res.ResponseCode === 200) {
          if (data.length === 0) {
            this.emptyMsg = 'No data found';
          } else {
            this.emptyMsg = '';
            for (var obj in data) {
              if (data.hasOwnProperty(obj)) {
                for (var prop in data[obj]) {
                  if (data[obj].hasOwnProperty(prop)) {
                    if (this.displayedColumns.indexOf(prop) === -1) {
                      this.displayedColumns.push(prop);
                    }
                  }
                }
              }
            }
            // console.log(this.ind)
            this.updateLocalMessage(this.ind, res, data);
            this.dataSource = data;
          }
        } else {
          this.updateLocalMessage(this.ind, res, data);
          this.emptyMsg = res?.Error;
        }
        this.resultLoader = false;
      });
  }