Skip to main content
Skip to main content

NoteService

Constructors

constructor

**new NoteService**(«destructured»)

Parameters

__namedParametersInjectedDependenciesRequired

Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
eventBus_EventBusServiceRequired
manager_EntityManagerRequired
noteRepository_Repository<Note>Required
transactionManager_undefined | EntityManagerRequired
EventsobjectRequired
Events.CREATEDstringRequired

Default: "note.created"

Events.DELETEDstringRequired

Default: "note.deleted"

Events.UPDATEDstringRequired

Default: "note.updated"

Accessors

activeManager_

Protected get**activeManager_**(): EntityManager

Returns

EntityManager

EntityManagerEntityManagerRequired

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.

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

create

**create**(data, config?): Promise&#60;[Note](/references/services/classes/Note)&#62;

Creates a note associated with a given author

Parameters

dataCreateNoteInputRequired
the note to create
configobjectRequired
any configurations if needed, including meta data
config.metadataRecord<string, unknown>Required

Returns

Promise<Note>

PromisePromise<Note>Required
resolves to the creation result

delete

**delete**(noteId): Promise&#60;void&#62;

Deletes a given note

Parameters

noteIdstringRequired
id of the note to delete

Returns

Promise<void>

PromisePromise<void>Required

list

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

Fetches all notes related to the given selector

Parameters

selectorSelector<Note>Required
the query object for find
configFindConfig<Note>Required
the configuration used to find the objects. contains relations, skip, and take.

Returns

Promise<Note[]>

PromisePromise<Note[]>Required
notes related to the given search.

listAndCount

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

Fetches all notes related to the given selector

Parameters

selectorSelector<Note>Required
the query object for find
configFindConfig<Note>Required
the configuration used to find the objects. contains relations, skip, and take.

Returns

Promise<[Note[], number]>

PromisePromise<[Note[], number]>Required
notes related to the given search.

retrieve

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

Retrieves a specific note.

Parameters

noteIdstringRequired
the id of the note to retrieve.
configFindConfig<Note>Required
any options needed to query for the result.

Default: {}

Returns

Promise<Note>

PromisePromise<Note>Required
which resolves to the requested note.

shouldRetryTransaction_

Protected **shouldRetryTransaction_**(err): boolean

Parameters

errRecord<string, unknown> | &#123; code: string &#125;Required

Returns

boolean

booleanboolean

update

**update**(noteId, value): Promise&#60;[Note](/references/services/classes/Note)&#62;

Updates a given note with a new value

Parameters

noteIdstringRequired
the id of the note to update
valuestringRequired
the new value

Returns

Promise<Note>

PromisePromise<Note>Required
resolves to the updated element

withTransaction

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

Parameters

transactionManagerEntityManager

Returns

NoteService

NoteServiceNoteServiceRequired
Was this section helpful?