NotificationService
Constructors
constructor
**new NotificationService**(container)
Parameters
Properties
__configModule__Record<string, unknown>__container__anyRequired__moduleDeclaration__Record<string, unknown>attachmentGenerator_unknownRequiredDefault: null
manager_EntityManagerRequiredsubscribers_objectRequiredDefault: {}
transactionManager_undefined | EntityManagerRequiredAccessors
activeManager_
Protected get**activeManager_**(): EntityManager
Returns
EntityManager
EntityManagerEntityManagerRequiredMethods
atomicPhase_
Protected **atomicPhase_**<TypeParameter TResult, TypeParameter 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.
TResultobjectRequiredTErrorobjectRequiredParameters
work(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandlerIsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail(error: TError) => Promise<void | TResult>Returns
Promise<TResult>
PromisePromise<TResult>RequiredhandleEvent
**handleEvent**(eventName, data): Promise<undefined \| void \| [Notification](/references/services/classes/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
eventNamestringRequireddataRecord<string, unknown>RequiredReturns
Promise<undefined | void | Notification[]>
list
**list**(selector, config?): Promise<[Notification](/references/services/classes/Notification)[]>
Retrieves a list of notifications.
Parameters
Returns
Promise<Notification[]>
listAndCount
**listAndCount**(selector, config?): Promise<[[Notification](/references/services/classes/Notification)[], number]>
Retrieves a list of notifications and total count.
Parameters
Returns
Promise<[Notification[], number]>
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
serviceunknownRequiredReturns
void
voidvoidregisterInstalledProviders
**registerInstalledProviders**(providerIds): Promise<void>
Takes a list of notification provider ids and persists them in the database.
Parameters
providerIdsstring[]RequiredReturns
Promise<void>
PromisePromise<void>Requiredresend
**resend**(id, config?): Promise<[Notification](/references/services/classes/Notification)>
Resends a notification by retrieving a prior notification and calling the underlying provider's resendNotification method.
Parameters
idstringRequiredDefault: {}
Returns
Promise<Notification>
retrieve
**retrieve**(id, config?): Promise<[Notification](/references/services/classes/Notification)>
Retrieves a notification with a given id
Parameters
idstringRequiredDefault: {}
Returns
Promise<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
idstringRequiredReturns
send
**send**(event, eventData, providerId): Promise<undefined \| [Notification](/references/services/classes/Notification)>
Sends a notification, by calling the given provider's sendNotification method. Persists the Notification in the database.
Parameters
eventstringRequiredeventDataRecord<string, unknown>RequiredproviderIdstringRequiredReturns
Promise<undefined | Notification>
shouldRetryTransaction_
Protected **shouldRetryTransaction_**(err): boolean
Parameters
errRecord<string, unknown> | { code: string }RequiredReturns
boolean
booleanbooleansubscribe
**subscribe**(eventName, providerId): void
Subscribes a given provider to an event.
Parameters
eventNamestringRequiredproviderIdstringRequiredReturns
void
voidvoidwithTransaction
**withTransaction**(transactionManager?): [NotificationService](/references/services/classes/NotificationService)
Parameters
transactionManagerEntityManager