rename to profile, users are people

This commit is contained in:
Adolfo Reyna
2021-08-18 07:57:19 -07:00
parent 416c14d03b
commit 95a7bcb3ff
6 changed files with 46 additions and 33 deletions

View File

@@ -11,22 +11,27 @@ const getUserId = function(req){
DB.getDB.then((DB)=>{
const getProfileId = (req)=>{
return DB.ObjectID(req.cookies.profile_id);
}
router.get("/", async (req, res) => {
let posts = await DB.getPosts();
return res.json(posts)
});
router.get("/usr/:id", async (req, res) => {
const userid = req.params.id;
const posts = await DB.getPosts(userid);
const profileId = req.params.id;
const posts = await DB.getPosts(profileId);
return res.json(posts)
});
router.get("/new", async (req, res) => {
let post = {
userid: getUserId(req),
profileid: getProfileId(req),
...req.query
}
post.toProfile = post.toProfile ? DB.ObjectID(post.toProfile) : undefined;
let postObj = new Post(post);
let dbr = await DB.newPost(postObj)
post = postObj.toObj();
@@ -38,11 +43,11 @@ DB.getDB.then((DB)=>{
});
router.get("/newComment", async (req, res) => {
let userid = getUserId(req);
let profileid = getProfileId(req);
let postid = req.query.postid;
let content = req.query.content;
let comment = {
userid: userid,
profileid: profileid,
content: content,
createdAt: new Date(),
lastUpdated: new Date(),
@@ -58,7 +63,7 @@ DB.getDB.then((DB)=>{
});
router.get("/react", async (req, res) => {
let userid = getUserId(req);
let userid = getProfileId(req);
let postid = req.query.postid;
let reaction = {
type: "like",
@@ -73,7 +78,7 @@ DB.getDB.then((DB)=>{
})
router.get("/unreact", async (req, res) => {
let userid = getUserId(req);
let userid = getProfileId(req);
let postid = req.query.postid;
r = await DB.removeReaction(postid, userid);
console.log(r)
@@ -83,7 +88,7 @@ DB.getDB.then((DB)=>{
});
router.get("/comment/react", async (req, res) => {
let userid = getUserId(req);
let userid = getProfileId(req);
let postid = req.query.postid;
let commentDate = new Date(req.query.commentDate);
let reaction = {