NotificationService

Source: NotificationService.js:18

Service for managing notifications. Handles notification creation, delivery, and management.


Constructor

new NotificationService(): NotificationService

Instance Methods

getAll(UserId: UUID, options: Object): Promise.<Array>

Get all notifications for a user.

Parameters

  • UserId (UUID) — The user's UUID.
  • options (Object) — Options for fetching notifications.
    • options.all (boolean) — Whether to fetch all notifications.

Returns

  • Promise.<Array> — List of notifications.

findById(id: UUID, UserId: UUID): Promise.<(Object|null)>

Find a notification by ID.

Parameters

  • id (UUID) — Notification ID.
  • UserId (UUID) — The user's UUID.

Returns

  • Promise.<(Object|null)> — The notification object or null.

createForAll(title: string, message: string): Promise.<Array>

Create notifications for all users.

Parameters

  • title (string) — Notification title.
  • message (string) — Notification message.

Returns

  • Promise.<Array> — List of created notifications.

createOne( title: string, message: string, UserId: UUID, ): Promise.<Object>

Create a notification for a single user.

Parameters

  • title (string) — Notification title.
  • message (string) — Notification message.
  • UserId (UUID) — The user's UUID.

Returns

  • Promise.<Object> — The created notification object.

findOrCreate( title: string, message: string, UserId: UUID, ): Promise.<Array.<(Object|boolean)>>

Find or create a notification.

Parameters

  • title (string) — Notification title.
  • message (string) — Notification message.
  • UserId (UUID) — The user's UUID.

Returns

  • Promise.<Array.<(Object|boolean)>> — The notification object and a boolean indicating if the notification was created.

markRead(id: UUID, UserId: UUID): Promise.<Object>

Mark a notification as read.

Parameters

  • id (UUID) — Notification ID.
  • UserId (UUID) — The user's UUID.

Returns

  • Promise.<Object> — The updated notification object.

markUnread(id: UUID, UserId: UUID): Promise.<Object>

Mark a notification as unread.

Parameters

  • id (UUID) — Notification ID.
  • UserId (UUID) — The user's UUID.

Returns

  • Promise.<Object> — The updated notification object.

update(id: UUID, UserId: UUID, data: Object): Promise.<Object>

Update a notification.

Parameters

  • id (UUID) — Notification ID.
  • UserId (UUID) — The user's UUID.
  • data (Object) — Data to update.

Returns

  • Promise.<Object> — The updated notification object.

remove(id: UUID, UserId: UUID, options: Object): Promise.<void>

Remove a notification.

Parameters

  • id (UUID) — Notification ID.
  • UserId (UUID) — The user's UUID.
  • options (Object) — Options for removing notifications.
    • options.all (boolean) — Whether to remove all notifications.

Returns

  • Promise.<void> — Resolves if notification removed.

getReadPercentage(): Promise.<number>

Get the percentage of read notifications.

Returns

  • Promise.<number> — The percentage of read notifications.

getReadTrend(): Promise.<number>

Get the trend of read notifications.

Returns

  • Promise.<number> — The trend percentage of read notifications.