diff options
| author | nanalelfe <nargiza.nosirova@mail.utoronto.ca> | 2016-08-28 05:50:33 +0000 |
|---|---|---|
| committer | nanalelfe <nargiza.nosirova@mail.utoronto.ca> | 2016-08-28 05:50:33 +0000 |
| commit | 5d0305e8f284fe9ce0ec47325a6fd56508ce65f4 (patch) | |
| tree | e7c434eb54d985e29cbf71caa42a9e4fea0bb68a /node_simple.js | |
| parent | d94aad5042d2fd09242581f11415de4a978168be (diff) | |
Integrated socketst.io and setup the notification function
Diffstat (limited to 'node_simple.js')
| -rw-r--r-- | node_simple.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/node_simple.js b/node_simple.js index 7ff70c6..c2e3564 100644 --- a/node_simple.js +++ b/node_simple.js @@ -1392,3 +1392,48 @@ exports.getMail = function (username, callback) { }); }; + +/** + * 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 |
