Skip to main content
Skip to main content

RegionService

Provides layer to manipulate regions.

Constructors

constructor

**new RegionService**(«destructured»)

Parameters

__namedParametersInjectedDependenciesRequired

Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
countryRepository_Repository<Country>Required
currencyRepository_Repository<Currency>Required
eventBus_EventBusServiceRequired
featureFlagRouter_FlagRouterRequired
fulfillmentProviderRepository_Repository<FulfillmentProvider>Required
fulfillmentProviderService_FulfillmentProviderServiceRequired
manager_EntityManagerRequired
paymentProviderRepository_Repository<PaymentProvider>Required
paymentProviderService_PaymentProviderServiceRequired
regionRepository_Repository<Region>Required
storeService_StoreServiceRequired
taxProviderRepository_Repository<TaxProvider>Required
transactionManager_undefined | EntityManagerRequired
EventsobjectRequired
Events.CREATEDstringRequired

Default: "region.created"

Events.DELETEDstringRequired

Default: "region.deleted"

Events.UPDATEDstringRequired

Default: "region.updated"

Accessors

activeManager_

Protected get**activeManager_**(): EntityManager

Returns

EntityManager

EntityManagerEntityManagerRequired

Methods

addCountry

**addCountry**(regionId, code): Promise&#60;[Region](/references/services/classes/Region)&#62;

Adds a country to the region.

Parameters

regionIdstringRequired
the region to add a country to
codestringRequired
a 2 digit alphanumeric ISO country code.

Returns

Promise<Region>

PromisePromise<Region>Required
the updated Region

addFulfillmentProvider

**addFulfillmentProvider**(regionId, providerId): Promise&#60;[Region](/references/services/classes/Region)&#62;

Adds a fulfillment provider that is available in the region. Fails if the provider doesn't exist.

Parameters

regionIdstringRequired
the region to add the provider to
providerIdstringRequired
the provider to add to the region

Returns

Promise<Region>

PromisePromise<Region>Required
the updated Region

addPaymentProvider

**addPaymentProvider**(regionId, providerId): Promise&#60;[Region](/references/services/classes/Region)&#62;

Adds a payment provider that is available in the region. Fails if the provider doesn't exist.

Parameters

regionIdstringRequired
the region to add the provider to
providerIdstringRequired
the provider to add to the region

Returns

Promise<Region>

PromisePromise<Region>Required
the updated Region

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

Creates a region.

Parameters

dataCreateRegionInputRequired
the unvalidated region

Returns

Promise<Region>

PromisePromise<Region>Required
the newly created region

delete

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

Deletes a region.

Parameters

regionIdstringRequired
the region to delete

Returns

Promise<void>

PromisePromise<void>Required
the result of the delete operation

list

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

Lists all regions based on a query

Parameters

selectorSelector<Region>Required
query object for find

Default: {}

configFindConfig<Region>Required
configuration settings

Returns

Promise<Region[]>

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

listAndCount

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

Lists all regions based on a query and returns them along with count

Parameters

selectorSelector<Region>Required
query object for find

Default: {}

configFindConfig<Region>Required
configuration settings

Returns

Promise<[Region[], number]>

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

removeCountry

**removeCountry**(regionId, code): Promise&#60;[Region](/references/services/classes/Region)&#62;

Removes a country from a Region.

Parameters

regionIdstringRequired
the region to remove from
codestringRequired
a 2 digit alphanumeric ISO country code to remove

Returns

Promise<Region>

PromisePromise<Region>Required
the updated Region

removeFulfillmentProvider

**removeFulfillmentProvider**(regionId, providerId): Promise&#60;[Region](/references/services/classes/Region)&#62;

Removes a fulfillment provider from a region. Is idempotent.

Parameters

regionIdstringRequired
the region to remove the provider from
providerIdstringRequired
the provider to remove from the region

Returns

Promise<Region>

PromisePromise<Region>Required
the updated Region

removePaymentProvider

**removePaymentProvider**(regionId, providerId): Promise&#60;[Region](/references/services/classes/Region)&#62;

Removes a payment provider from a region. Is idempotent.

Parameters

regionIdstringRequired
the region to remove the provider from
providerIdstringRequired
the provider to remove from the region

Returns

Promise<Region>

PromisePromise<Region>Required
the updated Region

retrieve

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

Retrieves a region by its id.

Parameters

regionIdstringRequired
the id of the region to retrieve
configFindConfig<Region>Required
configuration settings

Default: {}

Returns

Promise<Region>

PromisePromise<Region>Required
the region

retrieveByCountryCode

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

Retrieve a region by country code.

Parameters

codestringRequired
a 2 digit alphanumeric ISO country code
configFindConfig<Region>Required
region find config

Default: {}

Returns

Promise<Region>

PromisePromise<Region>Required
a Region with country code

retrieveByName

**retrieveByName**(name): Promise&#60;[Region](/references/services/classes/Region)&#62;

Retrieves a region by name.

Parameters

namestringRequired
the name of the region to retrieve

Returns

Promise<Region>

PromisePromise<Region>Required
region with the matching name

shouldRetryTransaction_

Protected **shouldRetryTransaction_**(err): boolean

Parameters

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

Returns

boolean

booleanboolean

update

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

Updates a region

Parameters

regionIdstringRequired
the region to update
updateUpdateRegionInputRequired
the data to update the region with

Returns

Promise<Region>

PromisePromise<Region>Required
the result of the update operation

validateCountry

Protected **validateCountry**(code, regionId): Promise&#60;[Country](/references/services/classes/Country)&#62;

Validates a country code. Will normalize the code before checking for existence.

Parameters

codestringRequired
a 2 digit alphanumeric ISO country code
regionIdstringRequired
the id of the current region to check against

Returns

Promise<Country>

PromisePromise<Country>Required
the validated Country

validateCurrency

Protected **validateCurrency**(currencyCode): Promise&#60;void&#62;

Validates a currency code. Will throw if the currency code doesn't exist.

Parameters

currencyCodestringRequired
an ISO currency code

Returns

Promise<void>

PromisePromise<void>Required
void

Throws

if the provided currency code is invalid


validateFields

Protected **validateFields**<TypeParameter T>(regionData, id?): Promise&#60;DeepPartial&#60;[Region](/references/services/classes/Region)&#62;&#62;

Validates fields for creation and updates. If the region already exists the id can be passed to check that country updates are allowed.

Parameters

regionDataOmit<T, "metadata" | "currency_code">Required
the region data to validate
idT extends UpdateRegionInput ? string : undefined
optional id of the region to check against

Returns

Promise<DeepPartial<Region>>

PromisePromise<DeepPartial<Region>>Required
the validated region data

validateTaxRate

Protected **validateTaxRate**(taxRate): void

Validates a tax rate. Will throw if the tax rate is not between 0 and 1.

Parameters

taxRatenumberRequired
a number representing the tax rate of the region

Returns

void

voidvoid
void

Throws

if the tax rate isn't number between 0-100


withTransaction

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

Parameters

transactionManagerEntityManager

Returns

RegionService

RegionServiceRegionServiceRequired
Was this section helpful?