mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 02:08:47 +00:00
Code for removing user from db still in progress (commented out)
This commit is contained in:
parent
45f88861c8
commit
eea2f56b49
@ -15,29 +15,28 @@ exports.putPost = (req, res) => {
|
||||
};
|
||||
|
||||
admin.firestore().collection('posts').add(newPost)
|
||||
.then((doc) => {
|
||||
const resPost = newPost;
|
||||
resPost.postId = doc.id;
|
||||
return res.status(200).json(resPost);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: 'something is wrong'});
|
||||
});
|
||||
.then((doc) => {
|
||||
const resPost = newPost;
|
||||
resPost.postId = doc.id;
|
||||
return res.status(200).json(resPost);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: 'something is wrong'});
|
||||
});
|
||||
};
|
||||
|
||||
exports.getallPostsforUser = (req, res) => {
|
||||
|
||||
admin.firestore().collection('posts').where('userHandle', '==', 'new user' ).get()
|
||||
.then((data) => {
|
||||
let posts = [];
|
||||
data.forEach(function(doc) {
|
||||
posts.push(doc.data());
|
||||
});
|
||||
return res.status(200).json(posts);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
return res.status(500).json({error: 'Failed to fetch all posts written by specific user.'})
|
||||
})
|
||||
}
|
||||
.then((data) => {
|
||||
let posts = [];
|
||||
data.forEach(function(doc) {
|
||||
posts.push(doc.data());
|
||||
});
|
||||
return res.status(200).json(posts);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
return res.status(500).json({error: 'Failed to fetch all posts written by specific user.'})
|
||||
})
|
||||
};
|
||||
|
||||
@ -151,19 +151,33 @@ exports.deleteUser = (req, res) => {
|
||||
firebase.auth().onAuthStateChanged(function(user) {
|
||||
currentUser = user;
|
||||
if (currentUser) {
|
||||
/*db.collection("users").doc(`${currentUser.handle}`).delete()
|
||||
.then(function() {
|
||||
res.status(200).send("Removed user from database.");
|
||||
return;
|
||||
})
|
||||
.catch(function(err) {
|
||||
res.status(500).send("Failed to remove user from database.", err);
|
||||
});*/
|
||||
|
||||
//let ref = db.collection('users');
|
||||
//let userDoc = ref.where('userId', '==', currentUser.uid).get();
|
||||
//userDoc.ref.delete();
|
||||
|
||||
currentUser.delete()
|
||||
.then(function() {
|
||||
console.log("User successfully deleted!");
|
||||
console.log("User successfully deleted.");
|
||||
res.status(200).send("Deleted user.");
|
||||
return;
|
||||
})
|
||||
.catch(function(error) {
|
||||
.catch(function(err) {
|
||||
console.log("Error deleting user.", err);
|
||||
res.status(500).send("Failed to delete user.");
|
||||
});
|
||||
} else {
|
||||
console.log("Cannot get user");
|
||||
res.status(500).send("Cannot get user");
|
||||
}
|
||||
else {
|
||||
console.log("Cannot get user.");
|
||||
res.status(500).send("Cannot get user.");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@ -7,7 +7,7 @@ import Button from "@material-ui/core/Button";
|
||||
import withStyles from "@material-ui/core/styles/withStyles";
|
||||
|
||||
// Redux stuff
|
||||
import { deleteUser } from "../redux/actions/userActions";
|
||||
import { logoutUser } from "../redux/actions/userActions";
|
||||
import { connect } from "react-redux";
|
||||
|
||||
const styles = {
|
||||
@ -32,7 +32,7 @@ const styles = {
|
||||
export class Delete extends Component {
|
||||
|
||||
componentDidMount() {
|
||||
this.props.deleteUser();
|
||||
this.props.logoutUser();
|
||||
this.props.history.push('/');
|
||||
}
|
||||
|
||||
@ -45,10 +45,10 @@ const mapStateToProps = (state) => ({
|
||||
user: state.user
|
||||
});
|
||||
|
||||
const mapActionsToProps = { deleteUser };
|
||||
const mapActionsToProps = { logoutUser };
|
||||
|
||||
Delete.propTypes = {
|
||||
deleteUser: PropTypes.func.isRequired,
|
||||
logoutUser: PropTypes.func.isRequired,
|
||||
user: PropTypes.object.isRequired,
|
||||
classes: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user