Skip to content

Commit

Permalink
SWIK-1684 enable mark as unread
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaun committed Sep 19, 2017
1 parent 8c6b5e3 commit 81bd945
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
11 changes: 7 additions & 4 deletions application/controllers/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ let self = module.exports = {

//Create notification with new id and payload or return INTERNAL_SERVER_ERROR
newNotification: function(request, reply) {
request.payload.new = true;
if (!request.payload.new) {
request.payload.new = true;
}
return notificationsDB.insert(request.payload).then((inserted) => {
//console.log('inserted: ', inserted);
if (co.isEmpty(inserted.ops) || co.isEmpty(inserted.ops[0]))
Expand Down Expand Up @@ -68,18 +70,19 @@ let self = module.exports = {
},

//Mark notification as read (set new to false)
markAsReadNotification: function(request, reply) {
markNotification: function(request, reply) {
const markAsRead = request.query.read;
const query = {
_id: request.params.id//oid(request.params.id)
//encodeURIComponent(request.params.id)
};

return notificationsDB.partlyUpdate(query, {
$set: {
new: false
new: markAsRead
}
}).then(() => {
reply({'msg': 'notification is successfully marked as read...'});
reply({'msg': 'notification is successfully marked...'});
}).catch((error) => {
tryRequestLog(request, 'error', error);
reply(boom.badImplementation());
Expand Down
4 changes: 3 additions & 1 deletion application/database/notificationsDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ module.exports = {
.then((db) => db.collection(collectionName))
.then((col) => {
let valid = false;
notification.timestamp = new Date();
if (!notification.timestamp) {//if timestamp has not already been defined
notification.timestamp = new Date();
}
try {
valid = notificationModel(notification);
if (!valid) {
Expand Down
7 changes: 5 additions & 2 deletions application/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ module.exports = function(server) {
//Mark notification as read (set new to false)
server.route({
method: 'GET',
path: '/notification/markasread/{id}',
handler: handlers.markAsReadNotification,
path: '/notification/mark/{id}',
handler: handlers.markNotification,
config: {
validate: {
params: {
id: Joi.string().description('The id of the notification')
},
query: {
read: Joi.boolean().description('Set to true to mark the notification as read')
}
},
tags: ['api'],
Expand Down

0 comments on commit 81bd945

Please sign in to comment.