firebase - AngularFire2 Observables - Merging 4 tables together into one list to return to Angular 2 component -


i'm starting hang of firebase observables, utilizing angularfire 2, i'm trying seems pretty complex "query" i'm taking data 4 different tables , merging them 1 object. problem final object returns observables, when want return actual returned results calling such observables.

basically, need user's role project, there, need requests associated project, after that, need actual request data while grabbing "state" request in role of user. finally, once of calls have happened, i'd combine of array of objects.

here tables:

"projects" : {     "projectid1" : {       "name" : "fun project",       "users" : {         "useruid1" : {           "role" : "admin"         }       }     }   }  "project_requests" : {     "projectid1" : {       "requestid1" : {         "timestamp" : -1491578120857       },       "requestid2" : {         "timestamp" : -1491578287618       }     }   },  "check_request_states" : {     {   "requestid1" : {     "admin" : {       "last_updated" : "2017-04-07t15:52:49.367z",       "status" : "pending",       "timestamp" : -1491580369367     } }   }, 

here function:

getallprojectrequests(projectid) {     let currentuser = this._auth.getcurrentuser();      // project requests     return this._af.database.object(`/projects/${projectid}/users/${currentuser.uid}`)       .switchmap(user => {         let role = user.role;          return this._af.database.object(`/project_requests/${projectid}/`)           .switchmap(requests => {              if(requests) {               let projectrequests = object.keys(requests);               console.log('projectrequests', projectrequests);               // each request, grab based on timestamp               return observable.combinelatest(                     projectrequests.map((request) => {                       if(request['$value'] !== null) {                         return this._af.database.object(`/check_request_states/${request['$key']}/${role}`)                       }                     }),                     projectrequests.map((request) => {                       if(request['$value'] !== null) {                         return this._af.database.list(`/check_requests/${projectid}/${request['$key']}`)                       }                     }),                     (requestsstate, requestsdata) => {                       console.log('requestsstate', requestsstate);                       console.log('requestsdata', requestsdata);                        return [];                     })             }           })       })     } 

the final array i'm trying looks like:

[    requestid1: {       ...<request data>...,       status: "pending"    },    requestid2: {       ...<request data>...,       status: "pending"    } ] 

is possible?

maybe i'm not getting observables or something, shouldn't switchmap serve way "go observable"? there's lot of instances i'm trying merge multiple tree tables together, figuring 1 out me in number of other instances.

thanks in advance!


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -