From f2ebec71aa35b5b95b1da457f548247f48955018 Mon Sep 17 00:00:00 2001
From: Adolfo Reyna
You got a new post:
+ +++${Message}
+
Blessings
+ +`; + this.sendEmail(user.username, subject, message) + } +} + +module.exports = Notifications \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 78f5a82..917f07b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,8 @@ "cors": "^2.8.5", "dotenv": "^8.2.0", "express": "^4.17.1", - "mongodb": "^3.6.3" + "mongodb": "^3.6.3", + "nodemailer": "^6.6.3" } }, "node_modules/@mapbox/node-pre-gyp": { @@ -775,6 +776,14 @@ "node": "4.x || >=6.0.0" } }, + "node_modules/nodemailer": { + "version": "6.6.3", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.6.3.tgz", + "integrity": "sha512-faZFufgTMrphYoDjvyVpbpJcYzwyFnbAMmQtj1lVBYAUSm3SOy2fIdd9+Mr4UxPosBa0JRw9bJoIwQn+nswiew==", + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/nopt": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz", @@ -1734,6 +1743,11 @@ "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" }, + "nodemailer": { + "version": "6.6.3", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.6.3.tgz", + "integrity": "sha512-faZFufgTMrphYoDjvyVpbpJcYzwyFnbAMmQtj1lVBYAUSm3SOy2fIdd9+Mr4UxPosBa0JRw9bJoIwQn+nswiew==" + }, "nopt": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz", diff --git a/package.json b/package.json index f9e2630..70a8b70 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "cors": "^2.8.5", "dotenv": "^8.2.0", "express": "^4.17.1", - "mongodb": "^3.6.3" + "mongodb": "^3.6.3", + "nodemailer": "^6.6.3" } } diff --git a/routes/post.js b/routes/post.js index 848c8dc..56679c9 100644 --- a/routes/post.js +++ b/routes/post.js @@ -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