mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2026-03-10 13:15:05 +00:00
Merge branch 'master' into auth-backend-3
This commit is contained in:
@@ -226,37 +226,18 @@ exports.updateProfileInfo = (req, res) => {
|
||||
|
||||
exports.getUserDetails = (req, res) => {
|
||||
let userData = {};
|
||||
db.doc(`/users/${req.params.handle}`)
|
||||
db.doc(`/users/${req.body.handle}`)
|
||||
.get()
|
||||
.then((doc) => {
|
||||
if (doc.exists) {
|
||||
userData.user = doc.data();
|
||||
return db
|
||||
.collection("post")
|
||||
.where("userHandle", "==", req.params.handle)
|
||||
.orderBy("createdAt", "desc")
|
||||
.get();
|
||||
userData = doc.data();
|
||||
return res.status(200).json({userData});
|
||||
} else {
|
||||
return res.status(404).json({
|
||||
return res.status(400).json({
|
||||
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) => {
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: err.code });
|
||||
@@ -279,3 +260,5 @@ exports.getAuthenticatedUser = (req, res) => {
|
||||
return res.status(500).json({ error: err.code });
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ app.post("/login", login);
|
||||
//Deletes user account
|
||||
app.delete("/delete", deleteUser);
|
||||
|
||||
app.get("/getUser/:handle", getUserDetails);
|
||||
app.get("/getUser", fbAuth, getUserDetails);
|
||||
|
||||
// Returns all profile data of the currently logged in user
|
||||
app.get("/getProfileInfo", fbAuth, getProfileInfo);
|
||||
|
||||
@@ -32,6 +32,7 @@ module.exports = (req, res, next) => {
|
||||
.then((data) => {
|
||||
req.user.handle = data.docs[0].data().handle; // Save username
|
||||
req.user.imageUrl = data.docs[0].data().imageUrl;
|
||||
req.userData = data.docs[0].data(); // Stores all user data from the database
|
||||
return next();
|
||||
})
|
||||
.catch((err) => {
|
||||
|
||||
Reference in New Issue
Block a user