Convert from promises to array

This commit is contained in:
gaba
2016-11-04 14:13:22 -07:00
parent ea93687f89
commit 23ea7025ea
+7 -1
View File
@@ -7,11 +7,17 @@ const Action = require('../../../models/action');
const router = express.Router();
router.get('/', (req, res, next) => {
const comments = Comment.findByAssetId(req.query.asset_id) || [];
const users = User.findByIdArray(comments.map((comment) => comment.author_id));
const actions = Action.findByItemIdArray(comments.map((comment) => comment.id));
res.json(comments.concat(users).concat(actions)).catch(next);
Promise.all([comments, users, actions]).then(([comments, users, actions]) => {
res.json(comments.concat(users).concat(actions));
}).catch(error => {
next(error);
});
});
module.exports = router;