getUserDetail returns only user handle

This commit is contained in:
Leon Liang 2019-10-24 16:27:22 -04:00
parent bdad36957c
commit 570866ff40

View File

@ -178,37 +178,18 @@ exports.updateProfileInfo = (req, res) => {
exports.getUserDetails = (req, res) => { exports.getUserDetails = (req, res) => {
let userData = {}; let userData = {};
db.doc(`/users/${req.params.handle}`) db.doc(`/getUser/${req.params.handle}`)
.get() .get()
.then((doc) => { .then((doc) => {
if (doc.exists) { if (doc.exists) {
userData.user = doc.data(); userData.credentials = doc.data();
return db return res.status(200).json({userData});
.collection("post")
.where("userHandle", "==", req.params.handle)
.orderBy("createdAt", "desc")
.get();
} else { } else {
return res.status(404).json({ return res.status(400).json({
error: "User not found" error: "User not found"
}); });
} }
}) })
.then((data) => {
userData.posts = [];
data.forEach((doc) => {
userData.posts.push({
body: doc.data().body,
createAt: doc.data().createAt,
userHandle: doc.data().userHandle,
userImage: doc.data().userImage,
likeCount: doc.data().likeCount,
commentCount: doc.data().commentCount,
postId: doc.id
});
});
return res.json(userData);
})
.catch((err) => { .catch((err) => {
console.error(err); console.error(err);
return res.status(500).json({ error: err.code }); return res.status(500).json({ error: err.code });
@ -231,3 +212,5 @@ exports.getAuthenticatedUser = (req, res) => {
return res.status(500).json({ error: err.code }); return res.status(500).json({ error: err.code });
}); });
}; };