Skip to content

Commit

Permalink
Merge pull request #68 from andela/bg-follower-list-169723358
Browse files Browse the repository at this point in the history
#169723358 Improve follower and following response
  • Loading branch information
harerakalex committed Nov 13, 2019
2 parents 2799a34 + 5276bce commit d888ade
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
44 changes: 28 additions & 16 deletions src/controllers/followController.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,20 @@ class Following {
});
}

await Promise.all(followingList.map(async (follower) => {
const userInfo = await User.findOne({ where: { id: follower.following } });
userList.push({
id: userInfo.dataValues.id,
username: userInfo.dataValues.userName,
});
return userList;
}));
await Promise.all(
followingList.map(async (follower) => {
const userInfo = await User.findOne({ where: { id: follower.following } });
userList.push({
id: userInfo.dataValues.id,
username: userInfo.dataValues.userName,
firstName: userInfo.dataValues.firstName,
lastName: userInfo.dataValues.lastName,
image: userInfo.dataValues.image,
bio: userInfo.dataValues.bio
});
return userList;
})
);
return res.status(200).json({
data: userList
});
Expand Down Expand Up @@ -151,14 +157,20 @@ class Following {
});
}

await Promise.all(followersList.map(async (follower) => {
const userInfo = await User.findOne({ where: { id: follower.follower } });
userList.push({
id: userInfo.dataValues.id,
username: userInfo.dataValues.userName,
});
return userList;
}));
await Promise.all(
followersList.map(async (follower) => {
const userInfo = await User.findOne({ where: { id: follower.follower } });
userList.push({
id: userInfo.dataValues.id,
username: userInfo.dataValues.userName,
firstName: userInfo.dataValues.firstName,
lastName: userInfo.dataValues.lastName,
image: userInfo.dataValues.image,
bio: userInfo.dataValues.bio
});
return userList;
})
);
return res.status(200).json({
data: userList
});
Expand Down
4 changes: 2 additions & 2 deletions src/tests/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ describe('GET /api/v1/profiles/:userName/following', () => {
expect(res).to.be.an('object');
expect(res.body).to.have.keys('data');
expect(res.body.data).to.be.an('array');
expect(res.body.data[0]).to.have.keys('id', 'username');
expect(res.body.data[0]).to.have.keys('id', 'username', 'bio', 'firstName', 'image', 'lastName');
done();
});
});
Expand All @@ -836,7 +836,7 @@ describe('GET /api/v1/profiles/:userName/followers', () => {
expect(res).to.be.an('object');
expect(res.body).to.have.keys('data');
expect(res.body.data).to.be.an('array');
expect(res.body.data[0]).to.have.keys('id', 'username');
expect(res.body.data[0]).to.have.keys('id', 'username', 'bio', 'firstName', 'image', 'lastName');
done();
});
});
Expand Down

0 comments on commit d888ade

Please sign in to comment.