Merge pull request #113 from ClaytonWWilson/admin-delete

Admin delete
This commit is contained in:
Clayton Wilson 2019-12-06 12:56:40 -05:00 committed by GitHub
commit ff7677bfb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1287 additions and 48 deletions

View File

@ -1,7 +1,7 @@
/* eslint-disable prefer-arrow-callback */
/* eslint-disable promise/always-return */
const admin = require("firebase-admin");
const { db } = require("../util/admin");
const { admin, db } = require("../util/admin");
exports.putPost = (req, res) => {
const newPost = {
@ -33,6 +33,18 @@ exports.putPost = (req, res) => {
});
};
exports.deletePost = (req, res) => {
let posts = db.collection("posts")
.where("userHandle", "==", req.user.handle)
.get()
.then((query) => {
query.forEach((snap) => {
snap.ref.delete();
});
return;
})
};
exports.getallPostsforUser = (req, res) => {
var post_query = admin
.firestore()
@ -62,6 +74,23 @@ exports.getallPostsforUser = (req, res) => {
});
};
exports.hidePost = (req, res) => {
/* db
.collection("posts")
.doc(${req.params.postId}) */
const postId = req.body.postId;
db.doc(`/posts/${postId}`)
.update({
hidden: true
})
.then(() => {
return res.status(200).json({message: "ok"});
})
.catch((error) => {
return res.status(500).json(error);
})
};
exports.getallPosts = (req, res) => {
let posts = [];
let users = {};
@ -148,6 +177,11 @@ exports.getOtherUsersPosts = (req, res) => {
.firestore()
.collection("posts")
.where("userHandle", "==", req.body.handle);
post_query += admin
.firestore()
.collection("posts")
.where("microBlogTitle", "==", "Alert").where("userHandle", "==", "Admin");
post_query
.get()

View File

@ -104,10 +104,12 @@ app.post("/removeSub", fbAuth, removeSub);
* handlers/post.js *
*------------------------------------------------------------------*/
const {
getallPostsforUser,
getallPosts,
putPost,
hidePost,
likePost,
unlikePost,
getLikes,
@ -122,6 +124,9 @@ app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
app.get("/getallPosts", getallPosts);
//Hides Post
app.post("/hidePost", fbAuth, hidePost);
// Adds one post to the database
app.post("/putPost", fbAuth, putPost);

File diff suppressed because it is too large Load Diff

View File

@ -86,8 +86,22 @@ class Home extends Component {
});
}
handleClickLikeButton = event => {
// Need the ternary if statement because the user can click on the text or body of the
flagPost = (event) => {
// Flags a post
let postId = event.target.dataset.key ? event.target.dataset.key : event.target.parentNode.dataset.key;
console.log(postId);
axios.post(`/hidePost`, {postId})
.then((res) => {
console.log(res.data);
})
.catch(err => {
console.error(err);
});
// event.preventDefault();
}
handleClickLikeButton = (event) => {
// Need the ternary if statement because the user can click on the text or body of the
// Button and they are two different html elements
let postId = event.target.dataset.key
? event.target.dataset.key
@ -119,51 +133,50 @@ class Home extends Component {
let authenticated = this.props.user.authenticated;
let { classes } = this.props;
let username = this.props.user.credentials.handle;
console.log(this.state.following);
console.log(username);
var hiddenBool = true;
if (username === "Admin") {
hiddenBool = false;
}
console.log(hiddenBool);
let postMarkup = this.state.posts ? (
this.state.posts.map(post =>
this.state.following ? (
this.state.following.includes(post.userHandle) ? (
// <<<<<<< admin-delete
this.state.posts.map(post => !post.hidden && this.state.following && this.state.following.includes(post.userHandle) ? (
<Card className={classes.card} key={post.postId}>
<CardContent>
<Typography>
{/* {
this.state.imageUrl ? (<img src={this.state.imageUrl} height="50" width="50" />) :
(<img src={noImage} height="50" width="50"/>)
} */}
{post.profileImage ? (
<img src={post.profileImage} height="50" width="50" />
) : (
<img src={noImage} height="50" width="50" />
)}
</Typography>
<Typography variant="h5">
<b>{post.userHandle}</b>
</Typography>
<Typography variant="body2" color={"textSecondary"}>
{this.formatDate(post.createdAt)}
this.state.imageUrl ? (<img src={this.state.imageUrl} height="50" width="50" />) :
(<img src={noImage} height="50" width="50"/>)
} */}
{
post.profileImage ? (<img src={post.profileImage} height="50" width="50" />) :
(<img src={noImage} height="50" width="50"/>)
}
</Typography>
<Typography variant="h5"><b>{post.userHandle}</b></Typography>
<Typography variant="body2" color={"textSecondary"}>{this.formatDate(post.createdAt)}</Typography>
<br />
<Typography variant="body1">
<b>{post.microBlogTitle}</b>
</Typography>
<Typography variant="body1"><b>{post.microBlogTitle}</b></Typography>
<Typography variant="body2">{post.quoteBody}</Typography>
<br />
<Typography variant="body2">{post.body}</Typography>
<br />
<Typography variant="body2">
<b>Topics:</b> {post.microBlogTopics.join(", ")}
</Typography>
<Typography variant="body2"><b>Topics:</b> {post.microBlogTopics.join(", ")}</Typography>
<br />
<Typography
id={post.postId}
data-likes={post.likeCount}
variant="body2"
color={"textSecondary"}
{!hiddenBool &&
<Button
onClick={this.flagPost}
data-key={post.postId}
variant = "contained"
color = "primary"
>
Likes {post.likeCount}
</Typography>
Hide Post
</Button>
}
<Typography id={post.postId} data-likes={post.likeCount} variant="body2" color={"textSecondary"}>Likes {post.likeCount}</Typography>
{/* <Like microBlog = {post.postId} count = {post.likeCount} name = {username}></Like> */}
<Button
onClick={this.handleClickLikeButton}
@ -171,23 +184,33 @@ class Home extends Component {
disabled={loading}
variant="outlined"
color="primary"
>
{this.state.likes && this.state.likes.includes(post.postId)
? "Unlike"
: "Like"}
</Button>
<Quote microblog={post.postId}></Quote>
>{
this.state.likes && this.state.likes.includes(post.postId) ? 'Unlike' : 'Like'
}</Button>
<Quote microblog = {post.postId}></Quote>
{/* <button>Quote</button> */}
<Typography variant="body2" color={"textSecondary"}>Likes {post.likeCount} Comments {post.commentCount}</Typography>
</CardContent>
</Card>
) : (
<p></p>
)
) : (
<p></p>
)
)
<p></p>
)
)
// =======
// this.state.posts.map(post =>
// this.state.following ? (
// this.state.following.includes(post.userHandle) ? (
// ) : (
// <p></p>
// )
// ) : (
// <p></p>
// )
// >>>>>>> master
) : (
<p>Loading post...</p>
);
@ -425,7 +448,7 @@ class Like extends Component {
});
}
handleClick() {
handleClick(){
this.setState({
like: !this.state.like
});