mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 10:18:48 +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)
|
admin.firestore().collection('posts').add(newPost)
|
||||||
.then((doc) => {
|
.then((doc) => {
|
||||||
const resPost = newPost;
|
const resPost = newPost;
|
||||||
resPost.postId = doc.id;
|
resPost.postId = doc.id;
|
||||||
return res.status(200).json(resPost);
|
return res.status(200).json(resPost);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).json({ error: 'something is wrong'});
|
return res.status(500).json({ error: 'something is wrong'});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getallPostsforUser = (req, res) => {
|
exports.getallPostsforUser = (req, res) => {
|
||||||
|
|
||||||
admin.firestore().collection('posts').where('userHandle', '==', 'new user' ).get()
|
admin.firestore().collection('posts').where('userHandle', '==', 'new user' ).get()
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
let posts = [];
|
let posts = [];
|
||||||
data.forEach(function(doc) {
|
data.forEach(function(doc) {
|
||||||
posts.push(doc.data());
|
posts.push(doc.data());
|
||||||
});
|
});
|
||||||
return res.status(200).json(posts);
|
return res.status(200).json(posts);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).json({error: 'Failed to fetch all posts written by specific user.'})
|
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) {
|
firebase.auth().onAuthStateChanged(function(user) {
|
||||||
currentUser = user;
|
currentUser = user;
|
||||||
if (currentUser) {
|
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()
|
currentUser.delete()
|
||||||
.then(function() {
|
.then(function() {
|
||||||
console.log("User successfully deleted!");
|
console.log("User successfully deleted.");
|
||||||
res.status(200).send("Deleted user.");
|
res.status(200).send("Deleted user.");
|
||||||
return;
|
return;
|
||||||
})
|
})
|
||||||
.catch(function(error) {
|
.catch(function(err) {
|
||||||
console.log("Error deleting user.", err);
|
console.log("Error deleting user.", err);
|
||||||
res.status(500).send("Failed to delete user.");
|
res.status(500).send("Failed to delete user.");
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
console.log("Cannot get user");
|
else {
|
||||||
res.status(500).send("Cannot get user");
|
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";
|
import withStyles from "@material-ui/core/styles/withStyles";
|
||||||
|
|
||||||
// Redux stuff
|
// Redux stuff
|
||||||
import { deleteUser } from "../redux/actions/userActions";
|
import { logoutUser } from "../redux/actions/userActions";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
@ -32,7 +32,7 @@ const styles = {
|
|||||||
export class Delete extends Component {
|
export class Delete extends Component {
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.deleteUser();
|
this.props.logoutUser();
|
||||||
this.props.history.push('/');
|
this.props.history.push('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,10 +45,10 @@ const mapStateToProps = (state) => ({
|
|||||||
user: state.user
|
user: state.user
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapActionsToProps = { deleteUser };
|
const mapActionsToProps = { logoutUser };
|
||||||
|
|
||||||
Delete.propTypes = {
|
Delete.propTypes = {
|
||||||
deleteUser: PropTypes.func.isRequired,
|
logoutUser: PropTypes.func.isRequired,
|
||||||
user: PropTypes.object.isRequired,
|
user: PropTypes.object.isRequired,
|
||||||
classes: PropTypes.object.isRequired
|
classes: PropTypes.object.isRequired
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user