post by user
This commit is contained in:
@@ -77,8 +77,9 @@ postDB = (DB)=>{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
DB.getPosts = (userObj) => {
|
DB.getPosts = (userid) => {
|
||||||
return DB.postCols.find().sort({_id: -1}).toArray().catch((err)=>{
|
let query = userid ? {userid} : {};
|
||||||
|
return DB.postCols.find(query).sort({_id: -1}).toArray().catch((err)=>{
|
||||||
console.log(err);
|
console.log(err);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,6 +16,12 @@ DB.getDB.then((DB)=>{
|
|||||||
return res.json(posts)
|
return res.json(posts)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get("/usr/:id", async (req, res) => {
|
||||||
|
const userid = req.params.id;
|
||||||
|
const posts = await DB.getPosts(userid);
|
||||||
|
return res.json(posts)
|
||||||
|
});
|
||||||
|
|
||||||
router.get("/new", async (req, res) => {
|
router.get("/new", async (req, res) => {
|
||||||
let post = {
|
let post = {
|
||||||
userid: getUserId(req),
|
userid: getUserId(req),
|
||||||
@@ -46,7 +52,8 @@ DB.getDB.then((DB)=>{
|
|||||||
r = await DB.newComment(postid, comment);
|
r = await DB.newComment(postid, comment);
|
||||||
console.log(r)
|
console.log(r)
|
||||||
return res.json({
|
return res.json({
|
||||||
status: "ok"
|
status: "ok",
|
||||||
|
...comment
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user