Notifications module for Mono
Installation
npm install --save mono-notifications
Usage
Mono notifications library manage your users feed notifications
//Control the notifications workflow (create, read, count, list)const monoNotification =
Mono notifications also expose the notifications as REST routes
All rest calls need a session that specify the user notifications
Routes
Method | URI | Query params | Body | Action |
---|---|---|---|---|
GET |
/notifications | markRead , limit , offset , read |
Return the notifications | |
GET |
/notifications/count | Return the number of unread notifications | ||
PUT |
/notifications/read | [notificationId1, ...] |
Set the notifications as read | |
PUT |
/notifications/:id/read | Set the specified notification as read |
Query params:
markRead
: Boolean (true, false
) Set the notifications as readlimit
: Number. Limit the returned notificationsoffset
: String (ASC
orDESC
). Sort the returned notificationsread
: Boolean (true, false
) Get notifications as read or unread
Methods
add
: Promise<void>
Insert a new notification for a specific userId with a specific payload
// Add a new notification of the userId '59c0de2dfe8fa448605b1d89' with a specific payloadconst notification = monoNotification
count
: Promise<Number>
Return the number of notifications (all, read or unread) for a specific userId
// Return all notifications of the userId '59c0de2dfe8fa448605b1d89'const notifications = monoNotification
// Return all unread notifications of the userId '59c0de2dfe8fa448605b1d89'const notifications = monoNotification
// Return all read notifications of the userId '59c0de2dfe8fa448605b1d89'const notifications = monoNotification
read
: Promise<void>
Set a notification or a list of notifications as read
// Set the notification as read that match '59c0de2dfe8fa448605b1d89' of the userId '59c0de2dfe8fa448605b1d90'const result = await monoNotification
// Set the notifications as read that match ['59c0de2dfe8fa448605b1d89','59c0de2dfe8fa448605b1d87'] of the userId '59c0de2dfe8fa448605b1d90'const result = await monoNotification
list
: Promise<Array<notification>>
Return all notifications (all, read or unread) for a specific userId
// Get all notifications of the userId '59c0de2dfe8fa448605b1d89'const notifications = await monoNotification
// Get all unread notifications of the userId '59c0de2dfe8fa448605b1d89'const notifications = await monoNotification
// Get all read notifications of the userId '59c0de2dfe8fa448605b1d89'const notifications = await monoNotification