0

I have a route:

router.get('/:bar', (req, res) => {
    Style.distinct('id', {'foo': req.params.bar })
    .then(ids => 
         // [00001, 00002, 00003, 00004, ... 99999]]
         // get Style
         // get Config
         // etc..
    });
});

In distinct then function, I would like to replace id 00001 with it's object & configuration (to do it, I have to query the Schema):

Style.find({'id', id})
Config.find({'id', id})

I'm stuck in callback hell. I am trying to achieve the following output:

{
  00001 : {
    style: {}
    config: {}
  },
  00002 : {
    style: {}
    config: {}
  },
  00003 : {
    style: {}
    config: {}
  }
}

However, I am unsure how to return the response of two concurrent API calls in an object, and return an array of objects when complete.

Moshe
  • 2,583
  • 4
  • 27
  • 70
  • 1
    Are you using any Promise library like `bluebird`? – MarkoCen Jun 19 '17 at 17:44
  • @MarkoCen I do have bluebird installed, but I am not familiar, can you elaborate further? Thank you for your response! – Moshe Jun 19 '17 at 17:50
  • I believe this question has been answered on Stackoverflow, for example [this one](https://stackoverflow.com/questions/26305267/best-way-to-handle-nested-promises-bluebird) – MarkoCen Jun 19 '17 at 18:07

0 Answers0