posting and commenting

This commit is contained in:
Adolfo Reyna
2021-07-29 10:25:05 -07:00
parent 6904ad913e
commit 4069054117
4 changed files with 119 additions and 2 deletions

View File

@@ -147,8 +147,69 @@ DB.getDB.then((DB)=>{
return res.json({
status: "ok"
})
});
app.get("/post/newComment", sessionChecker, async (req, res) => {
let userid = getUserId(req);
let postid = req.query.postid;
let content = req.query.content;
let comment = {
userid: userid,
content: content,
createdAt: new Date(),
lastUpdated: new Date(),
reactions: {}
}
console.log("comment", postid, comment);
r = await DB.newComment(postid, comment);
console.log(r)
return res.json({
status: "ok"
})
});
app.get("/post/react", sessionChecker, async (req, res) => {
let userid = getUserId(req);
let postid = req.query.postid;
let reaction = {
type: "like",
createdAt: new Date()
};
console.log("reaction". postid, reaction);
r = await DB.newReaction(postid, userid, reaction);
console.log(r);
return res.json({
status: "ok"
});
})
app.get("/post/unreact", sessionChecker, async (req, res) => {
let userid = getUserId(req);
let postid = req.query.postid;
r = await DB.removeReaction(postid, userid);
console.log(r)
return res.json({
status: "ok"
})
});
app.get("/post/comment/react", sessionChecker, async (req, res) => {
let userid = getUserId(req);
let postid = req.query.postid;
let commentDate = new Date(req.query.commentDate);
let reaction = {
type: "like",
createdAt: new Date()
};
console.log(req.query)
console.log("comment reaction", postid, commentDate, reaction);
r = await DB.newCommentReaction(postid, commentDate, userid, reaction);
console.log(r)
return res.json({
status: "ok"
})
});
// route for handling 404 requests(unavailable routes)
app.use(function (req, res, next) {
res.status(404).send("Sorry can't find that!")