Skip to main content
Skip to main content

RegionService

Provides layer to manipulate regions.

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
Events.DELETEDstringRequired
Events.UPDATEDstringRequired

Accessors

activeManager_

Inherited from

TransactionBaseService.activeManager_

Methods

addCountry

Adds a country to the region.

Parameters
regionIdstringRequired
the region to add a country to
codestringRequired
a 2 digit alphanumeric ISO country code.
Returns
PromisePromise<Region>Required
the updated Region

addFulfillmentProvider

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
PromisePromise<Region>Required
the updated Region

addPaymentProvider

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
PromisePromise<Region>Required
the updated Region

atomicPhase_

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.

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
PromisePromise<TResult>Required
the result of the transactional work

create

Creates a region.

Parameters
dataCreateRegionInputRequired
the unvalidated region
Returns
PromisePromise<Region>Required
the newly created region

delete

Deletes a region.

Parameters
regionIdstringRequired
the region to delete
Returns
PromisePromise<void>Required
the result of the delete operation

list

Lists all regions based on a query

Parameters
selectorSelector<Region>
query object for find
configuration settings
Returns
PromisePromise<Region[]>Required
result of the find operation

listAndCount

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

Parameters
selectorSelector<Region>
query object for find
configuration settings
Returns
PromisePromise<[Region[], number]>Required
result of the find operation

removeCountry

Removes a country from a Region.

Parameters
regionIdstringRequired
the region to remove from
codestringRequired
a 2 digit alphanumeric ISO country code to remove
Returns
PromisePromise<Region>Required
the updated Region

removeFulfillmentProvider

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
PromisePromise<Region>Required
the updated Region

removePaymentProvider

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
PromisePromise<Region>Required
the updated Region

retrieve

Retrieves a region by its id.

Parameters
regionIdstringRequired
the id of the region to retrieve
configuration settings
Returns
PromisePromise<Region>Required
the region

retrieveByCountryCode

Retrieve a region by country code.

Parameters
codestringRequired
a 2 digit alphanumeric ISO country code
region find config
Returns
PromisePromise<Region>Required
a Region with country code

retrieveByName

Retrieves a region by name.

Parameters
namestringRequired
the name of the region to retrieve
Returns
PromisePromise<Region>Required
region with the matching name

shouldRetryTransaction_

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

update

Updates a region

Parameters
regionIdstringRequired
the region to update
updateUpdateRegionInputRequired
the data to update the region with
Returns
PromisePromise<Region>Required
the result of the update operation

validateCountry

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
PromisePromise<Country>Required
the validated Country

validateCurrency

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

Parameters
currencyCodestringRequired
an ISO currency code
Returns
PromisePromise<void>Required
void

Throws

if the provided currency code is invalid


validateFields

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
PromisePromise<DeepPartial<Region>>Required
the validated region data

validateTaxRate

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
voidvoid
void

Throws

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


withTransaction

Parameters
transactionManagerEntityManager
Returns
RegionServiceRegionServiceRequired
Was this section helpful?