mirror of
https://github.com/wassname/talk.git
synced 2026-07-29 11:28:24 +08:00
Convert from promises to array
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user