sending emails when new post to profiles

This commit is contained in:
Adolfo Reyna
2021-09-14 11:19:44 -07:00
parent f92aa70621
commit f2ebec71aa
6 changed files with 92 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ var router = express.Router()
const DB = require("./../mongoDB.js");
const Post = require("./../def/post.js");
const Notifications = require("./../notifications.js")
DB.getDB.then((DB)=>{
@@ -29,9 +30,13 @@ DB.getDB.then((DB)=>{
}
post.toProfile = post.toProfile ? DB.ObjectID(post.toProfile) : undefined;
let postObj = new Post(post);
let dbr = await DB.newPost(postObj)
let dbr = await DB.newPost(postObj);
post = postObj.toObj();
post._id = dbr.insertedId;
if(post.toProfile && post.toProfile != post.profileid){
//send email notification
Notifications.youGotANewPost(post.toProfile, post.profileid, post.content)
}
return res.json({
status: "ok",
...post