0.1.3 • Published 8 years ago
mono-notifications v0.1.3
Notifications module for Mono
Installation
npm install --save mono-notificationsUsage
Mono notifications library manage your users feed notifications
//Control the notifications workflow (create, read, count, list)
const monoNotification = require('mono-notifications')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 (ASCorDESC). Sort the returned notificationsread: Boolean (true, false) Get notifications as read or unread
Methods
add
add(userId = string || ObjectID, payload = object): 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 payload
const notification = monoNotification.add('59c0de2dfe8fa448605b1d89', {
title: 'mono-notification',
description: 'mono notification description'
})count
count(userId = string || ObjectID, read = boolean): 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.count('59c0de2dfe8fa448605b1d89')// Return all unread notifications of the userId '59c0de2dfe8fa448605b1d89'
const notifications = monoNotification.count('59c0de2dfe8fa448605b1d89', false)// Return all read notifications of the userId '59c0de2dfe8fa448605b1d89'
const notifications = monoNotification.count('59c0de2dfe8fa448605b1d89', true)read
read(userId = string || ObjectID, notificationsId = string || Array<string>): 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.read('59c0de2dfe8fa448605b1d90', '59c0de2dfe8fa448605b1d89')// Set the notifications as read that match ['59c0de2dfe8fa448605b1d89','59c0de2dfe8fa448605b1d87'] of the userId '59c0de2dfe8fa448605b1d90'
const result = await monoNotification.read('59c0de2dfe8fa448605b1d90', ['59c0de2dfe8fa448605b1d89', '59c0de2dfe8fa448605b1d87'])list
list(userId = string || ObjectID, query = { limit, offset, sort, fields, read }): 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.list('59c0de2dfe8fa448605b1d89')// Get all unread notifications of the userId '59c0de2dfe8fa448605b1d89'
const notifications = await monoNotification.list('59c0de2dfe8fa448605b1d89', { read: false })// Get all read notifications of the userId '59c0de2dfe8fa448605b1d89'
const notifications = await monoNotification.list('59c0de2dfe8fa448605b1d89', { read: true })