Admin User Stories

This commit is contained in:
Danny Voltz 2019-12-05 12:12:25 -05:00
parent 17c7e989ef
commit 96423cee8a
5 changed files with 1236 additions and 4 deletions

View File

@ -60,6 +60,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 = {};
@ -113,6 +130,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

@ -39,6 +39,7 @@ app.post("/login", login);
//Deletes user account
app.delete("/delete", fbAuth, deleteUser);
app.post("/getUserDetails", fbAuth, getUserDetails);
// Returns a list of all usernames
@ -82,13 +83,16 @@ app.post("/removeSub", fbAuth, removeSub);
* handlers/post.js *
*------------------------------------------------------------------*/
const { getallPostsforUser, getallPosts, putPost, likePost, unlikePost, getLikes, quoteWithPost, quoteWithoutPost, checkforLikePost, getOtherUsersPosts} = require("./handlers/post");
const { getallPostsforUser, getallPosts, putPost, hidePost, likePost, unlikePost, getLikes, quoteWithPost, quoteWithoutPost, checkforLikePost, getOtherUsersPosts} = require("./handlers/post");
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

@ -10,6 +10,7 @@
"axios": "^0.19.0",
"clsx": "^1.0.4",
"create-react-app": "^3.1.2",
"firebase-admin": "^8.8.0",
"fuse.js": "^3.4.6",
"install": "^0.13.0",
"jwt-decode": "^2.2.0",

View File

@ -59,6 +59,19 @@ class Home extends Component {
})
}
flagPost = (event) => {
// Flags a post
let postId = event.target.dataset.key ? event.target.dataset.key : event.target.parentNode.dataset.key;
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
@ -90,9 +103,15 @@ class Home extends Component {
let authenticated = this.props.user.authenticated;
let {classes} = this.props;
let username = this.props.user.credentials.handle;
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.posts.map(post => post.hidden ? null :
<Card className={classes.card} key={post.postId}>
<CardContent>
<Typography>
@ -115,6 +134,17 @@ class Home extends Component {
<br />
<Typography variant="body2"><b>Topics:</b> {post.microBlogTopics}</Typography>
<br />
{!hiddenBool &&
<Button
onClick={this.flagPost}
data-key={post.postId}
variant = "contained"
color = "primary"
>
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
@ -332,8 +362,6 @@ class Like extends Component {
})
}
handleClick(){