1Surf
2 .find({user_id: {$in: userIds}})
3 .populate('user_id', 'name boards') // added boards
4 .populate('friends', 'name')
5 // .populate('board_id', 'name size') // can't do this as discussed
6 .exec(function (err, surfs) {
7 if (err) {
8 return handleError(res, err);
9 }
10
11 surfs.forEach(function (surf) {
12 surf.set('boardInfo', surf.user_id.boards.id(surf.board_id), {strict: false});
13 });
14 // TODO: now remove the surf.user_id.boards.
15 return res.json(200, surfs);
16 });
1exports.feed = function (req, res) {
2 var userIds = req.user.friends;
3
4 Surf
5 .find({user_id: {$in: userIds}})
6 .populate('user_id', 'name boards') // added boards
7 .populate('friends', 'name')
8 // .populate('board_id', 'name size') // can't do this as discussed
9 .exec(function (err, surfs) {
10 if (err) {
11 return handleError(res, err);
12 }
13
14 surfs.forEach(function (surf) {
15 surf.boardInfo = surf.user_id.boards.id(surf.board_id)
16 });
17 // TODO: now remove the surf.user_id.boards.
18 return res.json(200, surfs);
19 });
20
21};