Skip to main content
Skip to main content

GiftCardService

Provides layer to manipulate gift cards.

Constructors

constructor

**new GiftCardService**(«destructured»)

Parameters

__namedParametersInjectedDependenciesRequired

Properties

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

Default: "gift_card.created"

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**(giftCard): Promise&#60;[GiftCard](/references/services/classes/GiftCard)&#62;

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&#60;string&#62;

Parameters

Returns

Promise<string>

PromisePromise<string>Required

delete

**delete**(giftCardId): Promise&#60;void \| [GiftCard](/references/services/classes/GiftCard)&#62;

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&#60;[GiftCard](/references/services/classes/GiftCard)[]&#62;

Parameters

selectorQuerySelector<GiftCard>Required
the query object for find

Default: {}

configFindConfig<GiftCard>Required
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&#60;[[GiftCard](/references/services/classes/GiftCard)[], number]&#62;

Parameters

selectorQuerySelector<GiftCard>Required
the query object for find

Default: {}

configFindConfig<GiftCard>Required
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&#60;[GiftCard](/references/services/classes/GiftCard)&#62;

Gets a gift card by id.

Parameters

giftCardIdstringRequired
id of gift card to retrieve
configFindConfig<GiftCard>Required
optional values to include with gift card query

Default: {}

Returns

Promise<GiftCard>

PromisePromise<GiftCard>Required
the gift card

retrieveByCode

**retrieveByCode**(code, config?): Promise&#60;[GiftCard](/references/services/classes/GiftCard)&#62;

Parameters

codestringRequired
configFindConfig<GiftCard>Required

Default: {}

Returns

Promise<GiftCard>

PromisePromise<GiftCard>Required

retrieve_

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

Parameters

selectorSelector<GiftCard>Required
configFindConfig<GiftCard>Required

Default: {}

Returns

Promise<GiftCard>

PromisePromise<GiftCard>Required

shouldRetryTransaction_

Protected **shouldRetryTransaction_**(err): boolean

Parameters

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

Returns

boolean

booleanboolean

update

**update**(giftCardId, update): Promise&#60;[GiftCard](/references/services/classes/GiftCard)&#62;

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](/references/services/classes/GiftCardService)

Parameters

transactionManagerEntityManager

Returns

GiftCardService

GiftCardServiceGiftCardServiceRequired

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
A region holds settings specific to a geographical location, including the currency, tax rates, and fulfillment and payment providers. A Region can consist of multiple countries to accomodate common shopping settings across countries.

Returns

null | number

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