0

This is older implementation and I wanted to get HeatingDesired value

//1st api call
this.siteService.getScheduleParamsByRoomRef('temp and air and desired and heating', this.refs.roomRef).subscribe(({ rows }) => {
       if (rows.length > 0) {
           rows.forEach((row) => {
               let pointId = this.helperService.stripHaystackTypeMapping(row['id']).split(' ')[0];
               //2nd api call
               this.siteService.getHisPointData(pointId, 'current').subscribe(({ rows, meta }) => {
                   let metaVal = meta;
                   if (rows.length > 0) {
                       let HeatingDesired = this.helperService.stripHaystackTypeMapping(rows[0].val);

                   }
               });
           });

       }

   });

==========================================================================

Now I am trying to use switchmap and subscribe to the final response

getDesiredHeatingTemp(eleId){
    //1st api call
    return this.siteService.getScheduleParamsByRoomRef('temp and air and desired and heating', eleId).pipe(
  switchMap((a)=>{
      a.forEach((m) => {
        let pointId = this.helperService.stripHaystackTypeMapping(m['id']).split(' ')[0];
        //2nd api call
        return this.siteService.getHisPointData(pointId, 'current')
      })
  }))
}

this.getDesiredHeatingTemp(eleId).subscribe((a) => console.log(a))

But is gives me error saying
Argument of type '(a: any) => void' is not assignable to parameter of type '(value: any, index: number) => ObservableInput<any>'.
Type 'void' is not assignable to type 'ObservableInput<any>'.

The 2nd api call expects parameter which I get from 1st api call

Update

The response which I get from 1st api call looks like

a=
cols: (23) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
meta: {ver: "2.0"}
rows: [{…}]

a=
 cols: (23) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
 meta: {ver: "2.0"}
 rows: Array(1)
      0:
       air: "m:"
       desired: "m:"
       id: "r:5d90685e647845530d95ad0a nizam346_2-VAV-9600-desiredTempHeating"
       kind: "Number"
       __proto__: Object
       length: 1
       __proto__: Array(0)

From the above response of 1st api call I want to get rows[0].id and pass it on to the 2nd api call.

I tried using map, foreach but on debugging the execution doesn't go inside const obs = a.forEach((m)=>{ let pointId = this.helperService.stripHaystackTypeMapping(m.rows[0]['id']).split(' ')[0];

getDesiredHeatingTemp(eleId){
    return this.siteService.getScheduleParamsByRoomRef('temp and air and desired and heating', eleId)
    .pipe(
    switchMap(a => {
      const obs = a.forEach((m)=>{
        let pointId = this.helperService.stripHaystackTypeMapping(m.rows[0]['id']).split(' ')[0];
        return this.siteService.getHisPointData(pointId, 'current')
      })
      return forkJoin(obs)
  }))
}
6
  • 1
    you need to return an observable to switchmap Commented Sep 30, 2019 at 5:53
  • @joyBlanks , where please explain Commented Sep 30, 2019 at 6:17
  • here switchMap((a)=>{ a.forEach((m) => { doesn't return anything you need to return and observable Commented Sep 30, 2019 at 6:18
  • are you want to use Api1 response or both the Api's in subscription.. Commented Sep 30, 2019 at 6:18
  • @joyBlanks So the response of 1st api call I want to pass on to 2nd api call an dthen I return it Commented Sep 30, 2019 at 6:20

1 Answer 1

2

swithmap must return an observable

getDesiredHeatingTemp(eleId){
    //1st api call
    return this.siteService.getScheduleParamsByRoomRef('temp and air and desired and heating', eleId).pipe(
  switchMap((a)=>{
     //you formed a unique observable using forkjoin
      const obs=a.map((m)=>{
        let pointId = this.helperService.stripHaystackTypeMapping(m['id']).split(' ')[0];
        return this.siteService.getHisPointData(pointId, 'current')
      })
      //in obj we has,e.g. [
      //   this.siteService.getHisPointData(1,'current'),
      //   this.siteService.getHisPointData(1,'current'),
      //   this.siteService.getHisPointData(1,'current')
      //  ]
      return forkJoin(obs)
  }))
}
Sign up to request clarification or add additional context in comments.

1 Comment

I have updated this post with your reply , could you please suggest , I am getting the response of 1st api call but when I try to get the id from the response of 1st api call it doesnt work using foreach,map

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.