0

I want to call an endpoint, then when the data is retrieved, call a function, using that data. As the data must be available to be used with that function!

I'm sorry if the code appears convoluted, it is a bit complex.

The function I want to call looks like this:

  potentialEventsData() {
    this.allEngagementTypes().subscribe(data => {
      const products = {};
      data.forEach(product => {
        products[product.id] = product.description;

    this.potentialForEvents(this.organization.id, product.id)
    .subscribe(potentialEventData => {
      console.log('consoling the potential event data' + potentialEventData) <---- this potential event data is what I want to use and parse!
    });
   });
  });
}

So this potentialEventData I want to parse into this function below: (apologies, its quite a big function)

I want to call the above function, or simply just call the code, then when I have the data returned, parse the potentialEventData into this function, Now actually what this function does is return an array for each item as its a for loop so really I need to concatenate that first (sorry just realised) then send that one array into the this.buildOrganization(updatedGraphTable, resolve) function as an extra parameter, I've tried many ways to do this but I haven't yet managed a way to do it!

 graph(id: string): Promise<boolean> {

this.organization.setValues(id);
return new Promise((resolve, reject) => {
  if (!this.reload) {
    resolve(false);
  } else {
    let areasLoaded = false;
    let root: IEngagementGraphNode;
    this.getAllProductGroups().then(() => {
      areasLoaded = true;
      this.buildOrganization(root, resolve);
    }).catch(() => {
      areasLoaded = true;
      this.buildOrganization(root, resolve);
    });

    Observable.zip(this.organizationEngagements(id, this.requestOptions()), this.organizationIndividuals(id, this.requestOptions()))
      .subscribe(([graphData, individualsData]) => {
        this.insight.orgsMainName = graphData.name


        if (areasLoaded) {    
          return this.buildOrganization(updatedGraphTable, resolve); <------ here!
        } else {
          root = updatedGraphTable;
        }
      }, error => reject(error));
  }
});
 }

Also the buildOrganization function:

  buildOrganization(root, resolve): void {
    if (root) {
      this.organization.clear();
      this.organization.setProperties(root, this.filterParams);
      this.focus = this.organization;
      if (this.userList.length === 0) {
        this.userList = this.organization.individuals;
      }
      this.reload = false;
      this.data();
      resolve(true);
    }
  }

If you can help that would be amazing, thank you!

Sparlarva
  • 790
  • 1
  • 8
  • 30

0 Answers0