@dracul/notification-backend

1.35.0 • Public • Published

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


Queries y mutations

Types

NotificationsPaginated

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.

Notification

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.

ResponseNotification

type ResponseNotification{
    success: Int
}
Name Type Description
success Integer Returns 0 if the operation was successful, 1 if it failed.

Queries

fetchNotifications

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


notificationsPaginateFilter

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.


Mutations

createNotification

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



markAsReadOrNotRead

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


markAllReadOrNotRead

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


Subscription

notification

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".

Available services

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

createNotificationService

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.

fetchNotificationsService

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.

notificationsPaginateFilterService

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.

markAsReadOrNotReadService

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.

markAllReadOrNotReadService

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.

deleteNotificationsService

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.

Package Sidebar

Install

npm i @dracul/notification-backend

Weekly Downloads

14

Version

1.35.0

License

ISC

Unpacked Size

78.9 kB

Total Files

27

Last publish

Collaborators

  • cincarnato