diff options
| author | HumairAK <humair88@hotmail.com> | 2016-09-18 21:02:07 +0000 |
|---|---|---|
| committer | HumairAK <humair88@hotmail.com> | 2016-09-18 21:02:07 +0000 |
| commit | 541341598d5ed0e5c8ef9b2325dc6bbec958463a (patch) | |
| tree | 2b52efc8b69bd787e16cc523b12d2a54caabd405 /node_simple.js | |
| parent | d181c175009ef9b3523f025a28c678ae83be024e (diff) | |
| parent | 535d6cfc7a66f174e6f9c656766bee9c15964c48 (diff) | |
Merged conflict
Diffstat (limited to 'node_simple.js')
| -rw-r--r-- | node_simple.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/node_simple.js b/node_simple.js index 0b39620..2f49360 100644 --- a/node_simple.js +++ b/node_simple.js @@ -1366,3 +1366,73 @@ exports.removeToken = function(token, callback) { }; +/** + * Check if the user with the given username has mail. + * If the user does, then send the mail that falls within the specified page range. + * + * @param {object} username object + * @param {function} callback of the form (<boolean1>, <boolean2>, <array of objects>, <string>) + * - callback(error, success, mail, message) + * */ +exports.getMail = function (username, callback) { + + 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 { + // Mail retrieved + callback(true, false, data, 'Retrieved inbox'); + } + + }); + +}; + +/** + * Adds a notification to a user. + * @param email + * @param notification + * @param callback + */ + +exports.addNotification = function(email, notification, callback) { + + var notif = db.collection('notifications'); + notification['email'] = email; + + notif.insertOne(notification, function (err) { + if (err) { + //callback(error, message) + callback(true, "Error : Notification has not been added."); + } + + else { + callback(false, "Notification has been added"); + } + }); +} + +/** + * Retrieves a list of all notifications related to a user's email. + * @param email + * @param callback + */ +exports.getNotifications = function(email, callback) { + var notif = db.collection('notifications'); + + notif.find({email: email}).toArray(function (err, data) { + if (err) { + callback(false, true, null, 'Error: could not retrieve notifications.'); + } else if (!data) { + callback(false, false, null, 'No notifications.'); + } else { + callback(true, false, data, 'Retrieved notifications'); + } + + }); + +}
\ No newline at end of file |
