posting and commenting
This commit is contained in:
61
index.js
61
index.js
@@ -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!")
|
||||
|
||||
Reference in New Issue
Block a user