Skip to main content
Skip to main content

NotificationService

Constructors

constructor

**new NotificationService**(container)

Parameters
containerInjectedDependenciesRequired

Properties

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

Default: null

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

Default: {}

transactionManager_undefined | EntityManagerRequired

Accessors

activeManager_

Protected activeManager_: [object Object]

Methods

atomicPhase_

Protected **atomicPhase_**<TypeParameter TResult, TypeParameter TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise&#60;TResult&#62;

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

Promise<TResult>

PromisePromise<TResult>Required
the result of the transactional work

handleEvent

**handleEvent**(eventName, data): Promise&#60;undefined \| void \| [Notification](/references/services/classes/Notification)[]&#62;

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

Promise<undefined | void | Notification[]>

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

list

**list**(selector, config?): Promise&#60;[Notification](/references/services/classes/Notification)[]&#62;

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

Promise<Notification[]>

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

listAndCount

**listAndCount**(selector, config?): Promise&#60;[[Notification](/references/services/classes/Notification)[], number]&#62;

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

Promise<[Notification[], number]>

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

registerAttachmentGenerator

**registerAttachmentGenerator**(service): void

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

void

voidvoid

registerInstalledProviders

**registerInstalledProviders**(providerIds): Promise&#60;void&#62;

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

Parameters
providerIdsstring[]Required
a list of provider ids
Returns

Promise<void>

PromisePromise<void>Required

resend

**resend**(id, config?): Promise&#60;[Notification](/references/services/classes/Notification)&#62;

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

Promise<Notification>

PromisePromise<Notification>Required
the newly created notification

retrieve

**retrieve**(id, config?): Promise&#60;[Notification](/references/services/classes/Notification)&#62;

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

Promise<Notification>

PromisePromise<Notification>Required
the notification

retrieveProvider_

Protected **retrieveProvider_**(id): [AbstractNotificationService](/references/services/classes/AbstractNotificationService)

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

AbstractNotificationService

AbstractNotificationServiceAbstractNotificationServiceRequired
the notification provider

send

**send**(event, eventData, providerId): Promise&#60;undefined \| [Notification](/references/services/classes/Notification)&#62;

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

Promise<undefined | Notification>

PromisePromise<undefined | Notification>Required
the created notification

shouldRetryTransaction_

Protected **shouldRetryTransaction_**(err): boolean

Parameters
errRecord<string, unknown> | { code: string }Required
Returns

boolean

booleanboolean

subscribe

**subscribe**(eventName, providerId): void

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

void

voidvoid

withTransaction

**withTransaction**(transactionManager?): [NotificationService](/references/services/classes/NotificationService)

Parameters
transactionManagerEntityManager
Returns

NotificationService

NotificationServiceNotificationServiceRequired
Was this section helpful?