Skip to main content
Skip to main content

NotificationService

internal.internal.NotificationService

Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
attachmentGenerator_unknownRequired
container_InjectedDependencies & {}Required
logger_LoggerRequired
manager_EntityManagerRequired
notificationProviderRepository_Repository<NotificationProvider>Required
notificationRepository_Repository<Notification>Required
subscribers_objectRequired
transactionManager_undefined | EntityManagerRequired

Accessors

activeManager_

Protected get activeManager_(): EntityManager

Returns

EntityManager

EntityManagerEntityManagerRequired

Inherited from

TransactionBaseService.activeManager_

Methods

atomicPhase_

Protected atomicPhase_<TResult, TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise<TResult>

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.

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

Inherited from

TransactionBaseService.atomicPhase_


handleEvent

handleEvent(eventName, data): Promise<undefined | void | Notification[]>

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<Notification[]>

Retrieves a list of notifications.

Parameters

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

Returns

Promise<Notification[]>

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

listAndCount

listAndCount(selector, config?): Promise<[Notification[], number]>

Retrieves a list of notifications and total count.

Parameters

selectorSelector<Notification>Required
the params to select the notifications by.
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<void>

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<Notification>

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

Parameters

idstringRequired
the id of the notification
any configuration that might override the previous send

Returns

Promise<Notification>

PromisePromise<Notification>Required
the newly created notification

retrieve

retrieve(id, config?): Promise<Notification>

Retrieves a notification with a given id

Parameters

idstringRequired
the id of the notification
the configuration to apply to the query

Returns

Promise<Notification>

PromisePromise<Notification>Required
the notification

retrieveProvider_

Protected retrieveProvider_(id): 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<undefined | Notification>

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

Inherited from

TransactionBaseService.shouldRetryTransaction_


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

Parameters

transactionManagerEntityManager

Returns

NotificationService

NotificationServiceNotificationServiceRequired

Inherited from

TransactionBaseService.withTransaction

Was this section helpful?