diff --git a/routes/api/stream/index.js b/routes/api/stream/index.js index 321794823..a7eb13e0b 100644 --- a/routes/api/stream/index.js +++ b/routes/api/stream/index.js @@ -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;