Skip to main content

Class: GiftCardService

Provides layer to manipulate gift cards.

Hierarchy​

  • TransactionBaseService

    ↳ GiftCardService

Constructors​

constructor​

• new GiftCardService(__namedParameters)

Parameters​

NameType
__namedParametersInjectedDependencies

Overrides​

TransactionBaseService.constructor

Defined in​

medusa/src/services/gift-card.ts:39

Properties​

__configModule__​

• Protected Optional Readonly __configModule__: Record<string, unknown>

Inherited from​

TransactionBaseService.__configModule__

Defined in​

medusa/src/interfaces/transaction-base-service.ts:14


__container__​

• Protected Readonly __container__: any

Inherited from​

TransactionBaseService.__container__

Defined in​

medusa/src/interfaces/transaction-base-service.ts:13


__moduleDeclaration__​

• Protected Optional Readonly __moduleDeclaration__: Record<string, unknown>

Inherited from​

TransactionBaseService.__moduleDeclaration__

Defined in​

medusa/src/interfaces/transaction-base-service.ts:15


eventBus_​

• Protected Readonly eventBus_: EventBusService

Defined in​

medusa/src/services/gift-card.ts:33


giftCardRepository_​

• Protected Readonly giftCardRepository_: Repository<GiftCard> & { listGiftCardsAndCount: (query: ExtendedFindConfig<GiftCard>, q?: string) => Promise<[GiftCard[], number]> }

Defined in​

medusa/src/services/gift-card.ts:29


giftCardTransactionRepo_​

• Protected Readonly giftCardTransactionRepo_: Repository<GiftCardTransaction>

Defined in​

medusa/src/services/gift-card.ts:31


manager_​

• Protected manager_: EntityManager

Inherited from​

TransactionBaseService.manager_

Defined in​

medusa/src/interfaces/transaction-base-service.ts:5


regionService_​

• Protected Readonly regionService_: RegionService

Defined in​

medusa/src/services/gift-card.ts:32


transactionManager_​

• Protected transactionManager_: undefined | EntityManager

Inherited from​

TransactionBaseService.transactionManager_

Defined in​

medusa/src/interfaces/transaction-base-service.ts:6


Events​

▪ Static Events: Object

Type declaration​

NameType
CREATEDstring

Defined in​

medusa/src/services/gift-card.ts:35

Accessors​

activeManager_​

• Protected get activeManager_(): EntityManager

Returns​

EntityManager

Inherited from​

TransactionBaseService.activeManager_

Defined in​

medusa/src/interfaces/transaction-base-service.ts:8

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.

Type parameters​

Name
TResult
TError

Parameters​

NameTypeDescription
work(transactionManager: EntityManager) => Promise<TResult>the transactional work to be done
isolationOrErrorHandler?IsolationLevel | (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>

the result of the transactional work

Inherited from​

TransactionBaseService.atomicPhase_

Defined in​

medusa/src/interfaces/transaction-base-service.ts:56


create​

▸ create(giftCard): Promise<GiftCard>

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

Parameters​

NameTypeDescription
giftCardCreateGiftCardInputthe gift card data to create

Returns​

Promise<GiftCard>

the result of the create operation

Defined in​

medusa/src/services/gift-card.ts:122


createTransaction​

▸ createTransaction(data): Promise<string>

Parameters​

NameType
dataCreateGiftCardTransactionInput

Returns​

Promise<string>

Defined in​

medusa/src/services/gift-card.ts:106


delete​

▸ delete(giftCardId): Promise<void | GiftCard>

Deletes a gift card idempotently

Parameters​

NameTypeDescription
giftCardIdstringid of gift card to delete

Returns​

Promise<void | GiftCard>

the result of the delete operation

Defined in​

medusa/src/services/gift-card.ts:295


list​

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

Parameters​

NameTypeDescription
selectorQuerySelector<GiftCard>the query object for find
configFindConfig<GiftCard>the configuration used to find the objects. contains relations, skip, and take.

Returns​

Promise<GiftCard[]>

the result of the find operation

Defined in​

medusa/src/services/gift-card.ts:98


listAndCount​

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

Parameters​

NameTypeDescription
selectorQuerySelector<GiftCard>the query object for find
configFindConfig<GiftCard>the configuration used to find the objects. contains relations, skip, and take.

Returns​

Promise<[GiftCard[], number]>

the result of the find operation

Defined in​

medusa/src/services/gift-card.ts:74


retrieve​

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

Gets a gift card by id.

Parameters​

NameTypeDescription
giftCardIdstringid of gift card to retrieve
configFindConfig<GiftCard>optional values to include with gift card query

Returns​

Promise<GiftCard>

the gift card

Defined in​

medusa/src/services/gift-card.ts:215


retrieveByCode​

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

Parameters​

NameType
codestring
configFindConfig<GiftCard>

Returns​

Promise<GiftCard>

Defined in​

medusa/src/services/gift-card.ts:229


retrieve_​

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

Parameters​

NameType
selectorSelector<GiftCard>
configFindConfig<GiftCard>

Returns​

Promise<GiftCard>

Defined in​

medusa/src/services/gift-card.ts:182


shouldRetryTransaction_​

▸ Protected shouldRetryTransaction_(err): boolean

Parameters​

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

Returns​

boolean

Inherited from​

TransactionBaseService.shouldRetryTransaction_

Defined in​

medusa/src/interfaces/transaction-base-service.ts:37


update​

▸ update(giftCardId, update): Promise<GiftCard>

Updates a giftCard.

Parameters​

NameTypeDescription
giftCardIdstringgiftCard id of giftCard to update
updateUpdateGiftCardInputthe data to update the giftCard with

Returns​

Promise<GiftCard>

the result of the update operation

Defined in​

medusa/src/services/gift-card.ts:249


withTransaction​

▸ withTransaction(transactionManager?): GiftCardService

Parameters​

NameType
transactionManager?EntityManager

Returns​

GiftCardService

Inherited from​

TransactionBaseService.withTransaction

Defined in​

medusa/src/interfaces/transaction-base-service.ts:20


generateCode​

▸ Static generateCode(): string

Generates a 16 character gift card code

Returns​

string

the generated gift card code

Defined in​

medusa/src/services/gift-card.ts:58


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​

NameType
giftCardTaxRatenull | number
regionRegion

Returns​

null | number

the tax rate for the gift card

Defined in​

medusa/src/services/gift-card.ts:161

Was this section helpful?