https://github.com/mono-js/mono-notifications
Mono notifications library for node
https://github.com/mono-js/mono-notifications
mono mono-module notifications
Last synced: 4 months ago
JSON representation
Mono notifications library for node
- Host: GitHub
- URL: https://github.com/mono-js/mono-notifications
- Owner: mono-js
- License: mit
- Created: 2017-10-18T16:19:52.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-08-20T23:13:33.000Z (almost 7 years ago)
- Last Synced: 2025-02-20T21:17:19.075Z (4 months ago)
- Topics: mono, mono-module, notifications
- Language: JavaScript
- Size: 154 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
> Notifications module for [Mono](https://github.com/terrajs/mono)
[](https://www.npmjs.com/package/mono-notifications)
[](https://travis-ci.org/terrajs/mono-notifications)
[](https://codecov.io/gh/terrajs/mono-notifications.js)
[](https://github.com/terrajs/mono-notifications/blob/master/LICENSE)## Installation
```bash
npm install --save mono-notifications
```## Usage
Mono notifications library manage your users feed notifications
```js
//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 readQuery params:
- `markRead`: Boolean (`true, false`) Set the notifications as read
- `limit`: Number. Limit the returned notifications
- `offset`: String (`ASC` or `DESC`). Sort the returned notifications
- `read`: Boolean (`true, false`) Get notifications as read or unread## Methods
### add
```js
add(userId = string || ObjectID, payload = object): Promise
```Insert a new notification for a specific userId with a specific payload
```js
// 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
```js
count(userId = string || ObjectID, read = boolean): Promise
```Return the number of notifications (all, read or unread) for a specific userId
```js
// Return all notifications of the userId '59c0de2dfe8fa448605b1d89'
const notifications = monoNotification.count('59c0de2dfe8fa448605b1d89')
``````js
// Return all unread notifications of the userId '59c0de2dfe8fa448605b1d89'
const notifications = monoNotification.count('59c0de2dfe8fa448605b1d89', false)
``````js
// Return all read notifications of the userId '59c0de2dfe8fa448605b1d89'
const notifications = monoNotification.count('59c0de2dfe8fa448605b1d89', true)
```### read
```js
read(userId = string || ObjectID, notificationsId = string || Array): Promise
```Set a notification or a list of notifications as read
```js
// Set the notification as read that match '59c0de2dfe8fa448605b1d89' of the userId '59c0de2dfe8fa448605b1d90'
const result = await monoNotification.read('59c0de2dfe8fa448605b1d90', '59c0de2dfe8fa448605b1d89')
```
```js
// Set the notifications as read that match ['59c0de2dfe8fa448605b1d89','59c0de2dfe8fa448605b1d87'] of the userId '59c0de2dfe8fa448605b1d90'
const result = await monoNotification.read('59c0de2dfe8fa448605b1d90', ['59c0de2dfe8fa448605b1d89', '59c0de2dfe8fa448605b1d87'])
```### list
```js
list(userId = string || ObjectID, query = { limit, offset, sort, fields, read }): Promise>
```Return all notifications (all, read or unread) for a specific userId
```js
// Get all notifications of the userId '59c0de2dfe8fa448605b1d89'
const notifications = await monoNotification.list('59c0de2dfe8fa448605b1d89')
``````js
// Get all unread notifications of the userId '59c0de2dfe8fa448605b1d89'
const notifications = await monoNotification.list('59c0de2dfe8fa448605b1d89', { read: false })
``````js
// Get all read notifications of the userId '59c0de2dfe8fa448605b1d89'
const notifications = await monoNotification.list('59c0de2dfe8fa448605b1d89', { read: true })
```