Skip to main content
Skip to main content

GiftCardService

internal.internal.GiftCardService

Provides layer to manipulate gift cards.

Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
eventBus_EventBusServiceRequired
giftCardRepository_Repository<GiftCard> & { listGiftCardsAndCount: Method listGiftCardsAndCount }Required
giftCardTransactionRepo_Repository<GiftCardTransaction>Required
manager_EntityManagerRequired
regionService_RegionServiceRequired
transactionManager_undefined | EntityManagerRequired
EventsobjectRequired
Events.CREATEDstringRequired

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_


create

create(giftCard): Promise<GiftCard>

Creates a gift card with provided data given that the data is validated.

Parameters

giftCardCreateGiftCardInputRequired
the gift card data to create

Returns

Promise<GiftCard>

PromisePromise<GiftCard>Required
the result of the create operation

createTransaction

createTransaction(data): Promise<string>

Parameters

Returns

Promise<string>

PromisePromise<string>Required

delete

delete(giftCardId): Promise<void | GiftCard>

Deletes a gift card idempotently

Parameters

giftCardIdstringRequired
id of gift card to delete

Returns

Promise<void | GiftCard>

PromisePromise<void | GiftCard>Required
the result of the delete operation

list

list(selector?, config?): Promise<GiftCard[]>

Parameters

the query object for find
the configuration used to find the objects. contains relations, skip, and take.

Returns

Promise<GiftCard[]>

PromisePromise<GiftCard[]>Required
the result of the find operation

listAndCount

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

Parameters

the query object for find
the configuration used to find the objects. contains relations, skip, and take.

Returns

Promise<[GiftCard[], number]>

PromisePromise<[GiftCard[], number]>Required
the result of the find operation

retrieve

retrieve(giftCardId, config?): Promise<GiftCard>

Gets a gift card by id.

Parameters

giftCardIdstringRequired
id of gift card to retrieve
optional values to include with gift card query

Returns

Promise<GiftCard>

PromisePromise<GiftCard>Required
the gift card

retrieveByCode

retrieveByCode(code, config?): Promise<GiftCard>

Parameters

codestringRequired

Returns

Promise<GiftCard>

PromisePromise<GiftCard>Required

retrieve_

Protected retrieve_(selector, config?): Promise<GiftCard>

Parameters

selectorSelector<GiftCard>Required

Returns

Promise<GiftCard>

PromisePromise<GiftCard>Required

shouldRetryTransaction_

Protected shouldRetryTransaction_(err): boolean

Parameters

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

Returns

boolean

booleanboolean

Inherited from

TransactionBaseService.shouldRetryTransaction_


update

update(giftCardId, update): Promise<GiftCard>

Updates a giftCard.

Parameters

giftCardIdstringRequired
giftCard id of giftCard to update
updateUpdateGiftCardInputRequired
the data to update the giftCard with

Returns

Promise<GiftCard>

PromisePromise<GiftCard>Required
the result of the update operation

withTransaction

withTransaction(transactionManager?): GiftCardService

Parameters

transactionManagerEntityManager

Returns

GiftCardService

GiftCardServiceGiftCardServiceRequired

Inherited from

TransactionBaseService.withTransaction


generateCode

Static generateCode(): string

Generates a 16 character gift card code

Returns

string

stringstring
the generated gift card code

resolveTaxRate

Static Protected resolveTaxRate(giftCardTaxRate, region): null | number

The tax_rate of the giftcard can depend on whether regions tax gift cards, an input provided by the user or the tax rate. Based on these conditions, tax_rate changes.

Parameters

giftCardTaxRatenull | numberRequired
regionRegionRequired

Returns

null | number

``null`` \| numbernull | number
the tax rate for the gift card
Was this section helpful?