npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dracul/notification-backend

v1.25.0

Published

Modulo de notificaciones de usuario

Downloads

45

Readme

Contributors Stargazers

Dracul Notification Module

The Notification Module allows you to create and manage notifications with information about any action in your project..

This module allows:

  • Create notifications.
  • Mark notifications as read or unread.
  • Filter notifications by type or date both received and read.
  • Get notifications paginated.
  • Delete notifications based on their creation date.

Installation:

npm i @dracul/notification-backend

Table of Contents


type NotificationsPaginated{
    totalItems: Int
    page: Int
    items: [Notification]
}

Name | Type| Description | ------- | -------------| --------------| totalItems | Integer | The number of items to return.| page | Integer | The page number to return. | items | Array of Notification type |Notifications from that page. |

type Notification{
    id: ID
    user: ID
    title: String
    content: String
    read: Boolean
    creationDate: String
    type: String
    icon: String
    readDate: String
}

Name | Type| Description | ------- | -------------| --------------| id | ID | Notification ID. | user | ID| ID of the user who owns the notification. | title | String | The title of the notification. | content | String | The content of the notification. | read | Boolean | 'true' if the notification is read. 'false' if the notification is not read. | creationDate | String | Creation date. | type | String | Notification category. | icon | String | Notification icon. | readDate | String | Date of reading. |

type ResponseNotification{
    success: Int
}

Name | Type| Description | ------- | -------------| --------------| success | Integer | Returns 0 if the operation was successful, 1 if it failed.|


Definition and usage

Gets the notifications of a specific user. Delegates the task to the fetchNotificationsService service. Returns a promise.

Syntax


query: {
fetchNotifications( limit: Int,
isRead: Boolean,
type: String):[Notification]
}

type Notification{
id: ID,
user: ID,
title: String
content: String
read: Boolean
creationDate: String
type: String
icon: String
readDate: String
}

Parameters values

Name | Type | Required | Description | ------- | -------------|--------| --------------| limit | Integer | No | Represents the number of limit notifications you want to get. By default it gets all user notifications.| isRead | Boolean| Yes| 'true' if you want to get the notifications that have already been read. 'false' if you want to get only unread notifications. 'null' in case you want to get all the notifications regardless of their status.| type | String | No | Just in case you want to filter the notifications by type. |

Data returned by the service

Returns an Array of the type Notification. For more information go to the section Types


Definition and usage

Gets the paginated notifications of a certain user. Delegate the task to the service notificationsPaginateFilterService. Returns a promise.

Syntax

query: {
notificationsPaginateFilter(
limit: Int,
pageNumber: Int,
isRead: Boolean,
type: String): NotificationsPaginated
}

type NotificationsPaginated{
totalItems: Int
page: Int
items: [Notification]
}

type Notification{
id: ID,
user: ID,
title: String
content: String
read: Boolean
creationDate: String
type: String
icon: String
readDate: String
}

Parameters values

Name | Type | Required | Description | ------- | -------------|--------| --------------| limit | Integer | No | Represents the number of limit notifications you want to get. By default it gets all user notifications.| isRead | Boolean| Yes| 'true' if you want to get the notifications that have already been read. 'false' if you want to get only unread notifications. 'null' in case you want to get all the notifications regardless of their status.| type | String | No | Just in case you want to filter the notifications by type. |

Data returned by the service

Returns an Array of the type Notification. For more information go to the section Types.


Definition and usage

Create a notification. Delegates the task to the createNotificationService service. Returns a promise.

Syntax


mutation: {
createNotification(
title: String,
content: String,
type: String,
icon: String):Notification
}

type Notification{
id: ID,
user: ID,
title: String
content: String
read: Boolean
creationDate: String
type: String
icon: String
readDate: String
}

Parameters values

Name | Type | Required | Description | ------- | -------------|--------| --------------| title | String | Yes | It will be used as the title of the notice.| content | String| Yes| It will be used as the content of the notification.| type | String | Yes | It will be used as the category of the notification. | icon | String | Yes | It will be used as the icon that represents the notification.|

Data returned by the service

Returns the data of the created notification. For more information go to the section Types



Definition and usage

Allows you to mark a user notification as read or unread. Delegate the task to the service markAsReadOrNotReadService. Returns a promise.

Syntax


mutation: {
        markAsReadOrNotRead(id: ID, isRead: Boolean):Notification
}

type Notification{
id: ID,
user: ID,
title: String
content: String
read: Boolean
creationDate: String
type: String
icon: String
readDate: String
}

Parameters values

Name | Type | Required | Description | ------- | -------------|--------| --------------| id | ID | Yes | ID notification that will be marked as read or unread.| isRead | Boolean| Yes|'true' to mark the notification as read. 'false' to mark the notification as unread.|

Data returned by the service

Returns the data of the modified notification. For more information go to the section Types


Definition and usage

Allows you to mark all user notifications as read or unread. Delegate the task to the service markAllReadOrNotReadService. Returns a promise.

Syntax


mutation: {
        markAllReadOrNotRead(isRead: Boolean):ResponseNotification
}

type ResponseNotification{
        success: Int
}

Parameters values

Name | Type | Required | Description | ------- | -------------|--------| --------------| idUserAuth | ID | Yes | The ID of the user to whom all notifications will be marked as read or unread.| readValue | Boolean| Yes| 'true' to mark all notifications as read. 'false' to mark all notifications as unread.|

Data returned by the service

Returns the data of the modified notification. For more information go to the section Types


Definition and usage

Allows you to subscribe to websocket notifications. Delegates the task to the fetchNotificationsService service. Returns a promise.

Syntax

Subscription: {
        notification(user: ID!): Notification
}


type Notification{
        id: ID,
        user: ID,
        title: String
        content: String
        read: Boolean
        creationDate: String
        type: String
        icon: String
        readDate: String
}

Parameters values

Name | Type | Required | Description | ------- | -------------|--------| --------------| user | ID | Yes | The ID of the user whose notifications will be "listened to".|


The services are methods or functions that perform the operations of registration, cancellation and modification of notifications. So much queries and mutations delegate their responsibilities to these services. If you don't want to use queries and mutations defined, you can use the services independently.

Usage example:

Usage example for the createNotificationService method.

import {createNotificationService} from "@dracul/notification-backend"

let userId = "123" //some userId
let title = "Notification Title"
let content = "Notification content"
let type = "SomeType"
let icon =  "SomeIcon"

createNotificationService(
    userId,
    title,
    content,
    type,
    icon
)
.then(notificationDocument => {
    console.log("Notification created: ",notificationDocument)
})
.catch(error => {
    console.error(error)
})

Available methods

Definition and usage

Create an user notification. Return a promise.

Syntax

createNotificationService(userId, title, content, type, icon)

Parameters values

Name | Type | Required | Description | ------- | -------------|--------| --------------| userId | ID | Yes | The ID user to whom the notification will be created.| title |String |Yes | Will be used as the notification title. | content| String| Yes| Will be used as the notification content. | type|String |Yes | It will be used to categorize the notifications. | icon| String|Yes | Will be used as the notification icon.|


Definition and usage

Get notifications from a certain user. Return a promise.

Syntax

fetchNotificationsService(userId, limit, isRead, type)

Parameters values

Name | Type | Required | Description | ------- | -------------|--------| --------------| userId | ID | Yes | The user ID to get their notifications.| limit|Integer | No |The number of notifications you want to get. By default it returns all. | isRead|Boolean | Yes| 'true' if you want to get the notifications that have been read. 'false' if you want to get the notifications that were not read. 'null' wants to get all notifications regardless of status.| type|String | No | If you want to filter notifications by type field.|


Definition and usage

Get notifications filters paginate from a certain user. Return a promise.

Syntax

notificationsPaginateFilterService(userId, limit, pageNumber, isRead, type)

Parameters values

Name | Type | Required | Description | ------- | -------------|--------| --------------| userId | ID | Yes | The user ID to get their notifications.| limit| Integer| No| The number of notifications you want to get. By default it returns all.| pageNumber|Integer | No | (Use it for the paging of notifications), the page number you want to obtain. by default returns page 1.| isRead| Boolean| Yes | 'true' if you want to get the notifications that have been read. 'false' if you want to get the notifications that were not read. 'null' wants to get all notifications regardless of status.| type| String| Yes| If you want to filter notifications by type field.|


Definition and usage

Allows marking a notification as read or not read. Return a promise.

Syntax

markAsReadOrNotReadService(idNotification, readValue)

Parameters values

Name | Type | Required | Description | ------- | -------------|--------| --------------| idNotification | ID | Yes | ID notification that will be marked as read or unread.| readValue |Boolean | Yes| 'true' to mark the notification as read. 'false' to mark the notification as unread. |


Definition and usage

Allows marking all user notifications as read or not read. Return a promise.

Syntax

markAllReadOrNotReadService(idUserAuth, readValue)

Parameters values

Name | Type | Required | Description | ------- | -------------|--------| --------------| idUserAuth | ID | Yes | user ID to whom all notifications will be marked as read or unread.| readValue| Boolean| Yes |'true' to mark all the notifications as read. 'false' to mark all the notifications as unread. |


Definition and usage

Delete stored notifications for a certain user. Return a promise.

Syntax

deleteNotificationsService(userId, numberOfDays)

Parameters values

Name | Type | Required | Description | ------- | -------------|--------| --------------| userId | ID | Yes | The ID of the user whose notifications will be removed.| numberOfDays|Integer | No|The number of days old a notification must be in order to be deleted. By default it removes notifications 30 days or more old. |