Skip to main content
Skip to main content

NotificationService

constructor

Parameters

containerInjectedDependenciesRequired

Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
attachmentGenerator_unknownRequired

Default: null

container_InjectedDependencies & objectRequired
logger_LoggerRequired
manager_EntityManagerRequired
notificationProviderRepository_Repository<NotificationProvider>Required
notificationRepository_Repository<Notification>Required
subscribers_objectRequired

Default: {}

transactionManager_undefined | EntityManagerRequired

Accessors

activeManager_

Returns

EntityManagerEntityManagerRequired

Methods

atomicPhase_

Wraps some work within a transactional block. If the service already has a transaction manager attached this will be reused, otherwise a new transaction manager is created.

Type Parameters

TResultobjectRequired
TErrorobjectRequired

Parameters

work(transactionManager: EntityManager) => Promise<TResult>Required
the transactional work to be done
isolationOrErrorHandlerIsolationLevel | (error: TError) => Promise<void | TResult>
the isolation level to be used for the work.
maybeErrorHandlerOrDontFail(error: TError) => Promise<void | TResult>
Potential error handler

Returns

PromisePromise<TResult>Required
the result of the transactional work

handleEvent

Handles an event by relaying the event data to the subscribing providers. The result of the notification send will be persisted in the database in order to allow for resends. Will log any errors that are encountered.

Parameters

eventNamestringRequired
the event to handle
dataRecord<string, unknown>Required
the data the event was sent with

Returns

PromisePromise<undefined | void | Notification[]>Required
the result of notification subscribed

list

Retrieves a list of notifications.

Parameters

selectorSelector<Notification>Required
the params to select the notifications by.
configFindConfig<Notification>Required
the configuration to apply to the query

Returns

PromisePromise<Notification[]>Required
the notifications that satisfy the query.

listAndCount

Retrieves a list of notifications and total count.

Parameters

selectorSelector<Notification>Required
the params to select the notifications by.
configFindConfig<Notification>Required
the configuration to apply to the query

Returns

PromisePromise<[Notification[], number]>Required
the notifications that satisfy the query as well as the count.

registerAttachmentGenerator

Registers an attachment generator to the service. The generator can be used to generate on demand invoices or other documents.

Parameters

serviceunknownRequired
the service to assign to the attachmentGenerator

Returns

voidvoid

registerInstalledProviders

Takes a list of notification provider ids and persists them in the database.

Parameters

providerIdsstring[]Required
a list of provider ids

Returns

PromisePromise<void>Required

resend

Resends a notification by retrieving a prior notification and calling the underlying provider's resendNotification method.

Parameters

idstringRequired
the id of the notification
configFindConfig<Notification>Required
any configuration that might override the previous send

Default: {}

Returns

PromisePromise<Notification>Required
the newly created notification

retrieve

Retrieves a notification with a given id

Parameters

idstringRequired
the id of the notification
configFindConfig<Notification>Required
the configuration to apply to the query

Default: {}

Returns

PromisePromise<Notification>Required
the notification

retrieveProvider_

Finds a provider with a given id. Will throw a NOT_FOUND error if the resolution fails.

Parameters

idstringRequired
the id of the provider

Returns

AbstractNotificationServiceobjectRequired

send

Sends a notification, by calling the given provider's sendNotification method. Persists the Notification in the database.

Parameters

eventstringRequired
the name of the event
eventDataRecord<string, unknown>Required
the data the event was sent with
providerIdstringRequired
the provider that should handle the event.

Returns

PromisePromise<undefined | Notification>Required
the created notification

shouldRetryTransaction_

Parameters

errRecord<string, unknown> | objectRequired

Returns

booleanboolean

subscribe

Subscribes a given provider to an event.

Parameters

eventNamestringRequired
the event to subscribe to
providerIdstringRequired
the provider that the event will be sent to

Returns

voidvoid

withTransaction

Parameters

transactionManagerEntityManager

Returns

NotificationServiceobjectRequired
Was this section helpful?