diff options
| author | HumairAK <humair88@hotmail.com> | 2016-07-24 05:52:36 +0000 |
|---|---|---|
| committer | HumairAK <humair88@hotmail.com> | 2016-07-24 05:52:36 +0000 |
| commit | 5061681d90297671a034310e01170b1357053257 (patch) | |
| tree | efb168108fc4c1ff66ce2c8add03b76e16495d87 /node_simple.js | |
| parent | cba46a33d60a2ccb42745e6cf3ad5858f1bf98a3 (diff) | |
| parent | 27dfe48c9d4f7cb224fe96082cfbe05be23c3a41 (diff) | |
resolved conflict
Diffstat (limited to 'node_simple.js')
| -rw-r--r-- | node_simple.js | 67 |
1 files changed, 64 insertions, 3 deletions
diff --git a/node_simple.js b/node_simple.js index af6f4ef..b8ada6b 100644 --- a/node_simple.js +++ b/node_simple.js @@ -161,7 +161,6 @@ exports.retrieveFollows = function (user_name, callback) { }); }; - // will add comments ASAP /* callback(success, data/message) => callback(boolean, object/String); * @@ -965,7 +964,7 @@ exports.addAdmin = function (admin_data, callback) { console.log("inside addAdmin"); - // Check if the admin username already exists. If it does, then we don't add the admin_data and return a message. + // Check if the admin username already exists. Also check for user username. If it does, then we don't add the admin_data and return a message. exports.adminExists( admin_data.username , function (error, exists, data, message) { console.log("adminExists: " + message); if (!exists && !error) { @@ -1022,6 +1021,69 @@ exports.adminExists = function (username, callback) { }; +/****************************** MAIL *********************************/ + +/* + * mail_data = { + * sender: sender_username, + * receiver: receiver_username, + * message: message, + * date: date, + * } + * + * callback(success, error, message) + * + */ + +exports.sendMail = function (mail_data, callback) { + exports.find_user_name(mail_data.receiver, function (exist){ + if (exist) { + mongoFactory.getConnection(uri).then(function(db) { + var mail = db.collection('mail'); + + mail.insertOne(mail_data, function(err) { + if (err) { + callback(false, true, 'Error: could not send message.'); + db.close(); + } + else { + callback(true, false, "Message sent."); + db.close(); + } + }); + }); + } else { + callback(false, false, 'The receiver\'s username is undefined.'); + } + }); +} + + +/* + * + * callback(success, error, data, message) + * Returns the user's inbox (array of message objects) + * + */ + +exports.checkMailbox = function (username, callback) { + + mongoFactory.getConnection(uri).then(function(db) { + + var mail = db.collection('mail'); + + mail.find({receiver: username}).toArray(function (err, data) { + if (err) { + callback(false, true, null, 'Error: could not retrieve inbox messages.'); + } else if (!data) { + callback(false, false, null, 'No inbox.'); + } else { + callback(true, false, data, 'Retrieved inbox'); + } + }); + }); + +} //testing exports.findUserByID = function (id, callback) { @@ -1043,7 +1105,6 @@ exports.findUserByID = function (id, callback) { - /* * userObj = {fs: fs, ls: ls, email: email, username: username, pass_hash: pass_hash, univ: univ, dept: dept} * |
