1.25.0 • Published 5 months ago

@dracul/notification-backend v1.25.0

Weekly downloads
10
License
ISC
Repository
github
Last release
5 months ago

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]
}
NameTypeDescription
totalItemsIntegerThe number of items to return.
pageIntegerThe page number to return.
itemsArray of Notification typeNotifications from that page.
type Notification{
    id: ID
    user: ID
    title: String
    content: String
    read: Boolean
    creationDate: String
    type: String
    icon: String
    readDate: String
}
NameTypeDescription
idIDNotification ID.
userIDID of the user who owns the notification.
titleStringThe title of the notification.
contentStringThe content of the notification.
readBoolean'true' if the notification is read. 'false' if the notification is not read.
creationDateStringCreation date.
typeStringNotification category.
iconStringNotification icon.
readDateStringDate of reading.
type ResponseNotification{
    success: Int
}
NameTypeDescription
successIntegerReturns 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

NameTypeRequiredDescription
limitIntegerNoRepresents the number of limit notifications you want to get. By default it gets all user notifications.
isReadBooleanYes'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.
typeStringNoJust 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

NameTypeRequiredDescription
limitIntegerNoRepresents the number of limit notifications you want to get. By default it gets all user notifications.
isReadBooleanYes'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.
typeStringNoJust 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

NameTypeRequiredDescription
titleStringYesIt will be used as the title of the notice.
contentStringYesIt will be used as the content of the notification.
typeStringYesIt will be used as the category of the notification.
iconStringYesIt 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

NameTypeRequiredDescription
idIDYesID notification that will be marked as read or unread.
isReadBooleanYes'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

NameTypeRequiredDescription
idUserAuthIDYesThe ID of the user to whom all notifications will be marked as read or unread.
readValueBooleanYes'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

NameTypeRequiredDescription
userIDYesThe 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

NameTypeRequiredDescription
userIdIDYesThe ID user to whom the notification will be created.
titleStringYesWill be used as the notification title.
contentStringYesWill be used as the notification content.
typeStringYesIt will be used to categorize the notifications.
iconStringYesWill 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

NameTypeRequiredDescription
userIdIDYesThe user ID to get their notifications.
limitIntegerNoThe number of notifications you want to get. By default it returns all.
isReadBooleanYes'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.
typeStringNoIf 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

NameTypeRequiredDescription
userIdIDYesThe user ID to get their notifications.
limitIntegerNoThe number of notifications you want to get. By default it returns all.
pageNumberIntegerNo(Use it for the paging of notifications), the page number you want to obtain. by default returns page 1.
isReadBooleanYes'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.
typeStringYesIf 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

NameTypeRequiredDescription
idNotificationIDYesID notification that will be marked as read or unread.
readValueBooleanYes'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

NameTypeRequiredDescription
idUserAuthIDYesuser ID to whom all notifications will be marked as read or unread.
readValueBooleanYes'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

NameTypeRequiredDescription
userIdIDYesThe ID of the user whose notifications will be removed.
numberOfDaysIntegerNoThe number of days old a notification must be in order to be deleted. By default it removes notifications 30 days or more old.

1.25.0

5 months ago

1.24.0

6 months ago

1.23.1

9 months ago

1.20.11

12 months ago

1.18.1

1 year ago

1.16.3

1 year ago

1.18.0

1 year ago

1.15.0

1 year ago

1.11.4

2 years ago

1.11.3

2 years ago

1.11.2

2 years ago

1.11.1

2 years ago

1.10.4

2 years ago

1.10.3

2 years ago

1.10.0

2 years ago

1.8.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.8.6

2 years ago

1.7.22

2 years ago

1.7.23

2 years ago

1.7.24

2 years ago

1.9.2

2 years ago

1.7.12

2 years ago

1.7.11

2 years ago

1.7.0

2 years ago

1.6.4

2 years ago

1.6.3

2 years ago

1.6.2

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.4.0

2 years ago

1.0.105

3 years ago

1.0.104

3 years ago

1.0.103

3 years ago

1.0.98

3 years ago

1.0.69

3 years ago

1.0.68

3 years ago

1.0.61

3 years ago

1.0.59

3 years ago

1.0.50

3 years ago

1.0.48

3 years ago

1.0.47

3 years ago