Mark Notification as read by key alone

This commit is contained in:
Shane Kilkelly 2016-08-11 14:04:11 +01:00
parent 3cec6affab
commit 826295167f
3 changed files with 27 additions and 2 deletions

View file

@ -3,6 +3,8 @@ NotificationsHandler = require("./NotificationsHandler")
module.exports =
# Note: notification keys should be url-safe
groupPlan: (user, licence)->
key : "join-sub-#{licence.subscription_id}"
create: (callback = ->)->
@ -26,4 +28,4 @@ module.exports =
logger.log {user_id: user._id, project_id: project._id, invite_id: invite._id, key: @key}, "creating project invite notification for user"
NotificationsHandler.createNotification user._id, @key, "notification_project_invite", messageOpts, callback
read: (callback=()->) ->
NotificationsHandler.markAsReadWithKey user._id, @key, callback
NotificationsHandler.markAsReadByKeyOnly @key, callback

View file

@ -61,3 +61,13 @@ module.exports =
timeout:oneSecond
logger.log user_id:user_id, notification_id:notification_id, "sending mark notification as read to notifications api"
makeRequest opts, callback
# removes notification by key, without regard for user_id,
# should not be exposed to user via ui/router
markAsReadByKeyOnly: (key, callback)->
opts =
uri: "#{settings.apis.notifications?.url}/notification/key/#{key}"
method: "DELETE"
timeout: oneSecond
logger.log {key:key}, "sending mark notification as read with key-only to notifications api"
makeRequest opts, callback

View file

@ -68,4 +68,17 @@ describe 'NotificationsHandler', ->
args.timeout.should.equal 1000
expectedJson = {key:@key, templateKey:@templateKey, messageOpts:@messageOpts}
assert.deepEqual(args.json, expectedJson)
done()
done()
describe "markAsReadByKeyOnly", ->
beforeEach ->
@key = "some key here"
it 'should send a delete request when a delete has been received to mark a notification', (done)->
@handler.markAsReadByKeyOnly @key, =>
opts =
uri: "#{notificationUrl}/notification/key/#{@key}"
timeout:1000
method: "DELETE"
@request.calledWith(opts).should.equal true
done()