mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2026-03-10 21:25:04 +00:00
Merge branch 'master' into userline
This commit is contained in:
@@ -18,12 +18,11 @@ exports.putPost = (req, res) => {
|
||||
.then((doc) => {
|
||||
const resPost = newPost;
|
||||
resPost.postId = doc.id;
|
||||
res.json(resPost);
|
||||
|
||||
return res.status(200).json(resPost);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).json({ error: 'something is wrong'});
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: 'something is wrong'});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,51 @@
|
||||
const {db} = require('../util/admin');
|
||||
const {validateUpdateProfileInfo} = require('../util/validator');
|
||||
|
||||
exports.getProfileInfo = (req, res) => {
|
||||
// FIXME: Delete this after login is implemented
|
||||
req.user = {};
|
||||
req.user.handle = 'itsjimmy';
|
||||
|
||||
db.collection('users').doc(req.user.handle).get()
|
||||
.then((data) => {
|
||||
return res.status(200).json(data.data());
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
return res.status(500).json(err);
|
||||
});
|
||||
};
|
||||
|
||||
exports.updateProfileInfo = (req, res) => {
|
||||
// FIXME: Delete this after login is implemented
|
||||
req.user = {};
|
||||
req.user.handle = 'itsjimmy';
|
||||
|
||||
// TODO: Add functionality for adding/updating profile images
|
||||
|
||||
|
||||
// Data validation
|
||||
const {valid, errors, profileData} = validateUpdateProfileInfo(req.body);
|
||||
if (!valid) return res.status(400).json(errors);
|
||||
|
||||
|
||||
// Update the database entry for this user
|
||||
db.collection('users').doc(req.user.handle).set(profileData, {merge: true})
|
||||
.then(() => {
|
||||
console.log(`${req.user.handle}'s profile info has been updated.`)
|
||||
return res.status(201).json({general: `${req.user.handle}'s profile info has been updated.`});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
return res.status(500).json({
|
||||
error: 'Error updating profile data'
|
||||
});
|
||||
})
|
||||
};
|
||||
|
||||
exports.getUserDetails = (req, res) => {
|
||||
let userData = {};
|
||||
db.doc('/users/${req.params.handle}').get().then((doc) => {
|
||||
db.doc(`/users/${req.params.handle}`).get().then((doc) => {
|
||||
if (doc.exists) {
|
||||
userData.user = doc.data();
|
||||
return db.collection('post').where('userHandle', '==', req.params.handle)
|
||||
@@ -30,4 +75,4 @@ exports.getUserDetails = (req, res) => {
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: err.code});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user