Tuesday 30 May 2017

How do I make a custom function that returns a promise?

I created a function that find documents in my db. It is a custom function and Im going to pass values to its parameter in my controller. Then I want to use .then() after. Here is my code.

custom function

  getProjectsList(userId) {
    const query = { users: { $in: [userId] }, isDeleted: false };
    Project.find(query);
  },

and in my controller

projectsList(req, res) {
  projectModule.getProjectsList(req.user.id)
    .then(() => {   // this is not recognized
         // do something here
    });
},

Please help. I tried something like this but it doesn't work

getProjectsList(userId) {
 return new Promise(() => {
  const query = { users: { $in: [userId] }, isDeleted: false };
  Project.find(query);
 });
},



via lawrence bacus

No comments:

Post a Comment