RegionService
Provides layer to manipulate regions.
Constructors
constructor
**new RegionService**(«destructured»)
Parameters
Properties
__configModule__
Record<string, unknown>__container__
anyRequired__moduleDeclaration__
Record<string, unknown>manager_
EntityManagerRequiredtransactionManager_
undefined | EntityManagerRequiredEvents
objectRequiredEvents.CREATED
stringRequiredDefault: "region.created"
Events.DELETED
stringRequiredDefault: "region.deleted"
Events.UPDATED
stringRequiredDefault: "region.updated"
Accessors
activeManager_
Protected get**activeManager_**(): EntityManager
Returns
EntityManager
EntityManager
EntityManagerRequiredMethods
addCountry
**addCountry**(regionId, code): Promise<[Region](/references/services/classes/Region)>
Adds a country to the region.
Parameters
regionId
stringRequiredcode
stringRequiredReturns
Promise<Region>
addFulfillmentProvider
**addFulfillmentProvider**(regionId, providerId): Promise<[Region](/references/services/classes/Region)>
Adds a fulfillment provider that is available in the region. Fails if the provider doesn't exist.
Parameters
regionId
stringRequiredproviderId
stringRequiredReturns
Promise<Region>
addPaymentProvider
**addPaymentProvider**(regionId, providerId): Promise<[Region](/references/services/classes/Region)>
Adds a payment provider that is available in the region. Fails if the provider doesn't exist.
Parameters
regionId
stringRequiredproviderId
stringRequiredReturns
Promise<Region>
atomicPhase_
Protected **atomicPhase_**<TypeParameter TResult, TypeParameter 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.
TResult
objectRequiredTError
objectRequiredParameters
work
(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandler
IsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail
(error: TError) => Promise<void | TResult>Returns
Promise<TResult>
Promise
Promise<TResult>Requiredcreate
**create**(data): Promise<[Region](/references/services/classes/Region)>
Creates a region.
Parameters
Returns
Promise<Region>
delete
**delete**(regionId): Promise<void>
Deletes a region.
Parameters
regionId
stringRequiredReturns
Promise<void>
Promise
Promise<void>Requiredlist
**list**(selector?, config?): Promise<[Region](/references/services/classes/Region)[]>
Lists all regions based on a query
Parameters
Default: {}
Returns
Promise<Region[]>
listAndCount
**listAndCount**(selector?, config?): Promise<[[Region](/references/services/classes/Region)[], number]>
Lists all regions based on a query and returns them along with count
Parameters
Default: {}
Returns
Promise<[Region[], number]>
removeCountry
**removeCountry**(regionId, code): Promise<[Region](/references/services/classes/Region)>
Removes a country from a Region.
Parameters
regionId
stringRequiredcode
stringRequiredReturns
Promise<Region>
removeFulfillmentProvider
**removeFulfillmentProvider**(regionId, providerId): Promise<[Region](/references/services/classes/Region)>
Removes a fulfillment provider from a region. Is idempotent.
Parameters
regionId
stringRequiredproviderId
stringRequiredReturns
Promise<Region>
removePaymentProvider
**removePaymentProvider**(regionId, providerId): Promise<[Region](/references/services/classes/Region)>
Removes a payment provider from a region. Is idempotent.
Parameters
regionId
stringRequiredproviderId
stringRequiredReturns
Promise<Region>
retrieve
**retrieve**(regionId, config?): Promise<[Region](/references/services/classes/Region)>
Retrieves a region by its id.
Parameters
regionId
stringRequiredDefault: {}
Returns
Promise<Region>
retrieveByCountryCode
**retrieveByCountryCode**(code, config?): Promise<[Region](/references/services/classes/Region)>
Retrieve a region by country code.
Parameters
code
stringRequiredDefault: {}
Returns
Promise<Region>
retrieveByName
**retrieveByName**(name): Promise<[Region](/references/services/classes/Region)>
Retrieves a region by name.
Parameters
name
stringRequiredReturns
Promise<Region>
shouldRetryTransaction_
Protected **shouldRetryTransaction_**(err): boolean
Parameters
err
Record<string, unknown> | { code: string }RequiredReturns
boolean
boolean
booleanupdate
**update**(regionId, update): Promise<[Region](/references/services/classes/Region)>
Updates a region
Parameters
regionId
stringRequiredReturns
Promise<Region>
validateCountry
Protected **validateCountry**(code, regionId): Promise<[Country](/references/services/classes/Country)>
Validates a country code. Will normalize the code before checking for existence.
Parameters
code
stringRequiredregionId
stringRequiredReturns
Promise<Country>
validateCurrency
Protected **validateCurrency**(currencyCode): Promise<void>
Validates a currency code. Will throw if the currency code doesn't exist.
Parameters
currencyCode
stringRequiredReturns
Promise<void>
Promise
Promise<void>RequiredThrows
if the provided currency code is invalid
validateFields
Protected **validateFields**<TypeParameter T>(regionData, id?): Promise<DeepPartial<[Region](/references/services/classes/Region)>>
Validates fields for creation and updates. If the region already exists the id can be passed to check that country updates are allowed.
Parameters
id
T extends UpdateRegionInput ? string : undefinedReturns
Promise<DeepPartial<Region>>
validateTaxRate
Protected **validateTaxRate**(taxRate): void
Validates a tax rate. Will throw if the tax rate is not between 0 and 1.
Parameters
taxRate
numberRequiredReturns
void
void
voidThrows
if the tax rate isn't number between 0-100
withTransaction
**withTransaction**(transactionManager?): [RegionService](/references/services/classes/RegionService)
Parameters
transactionManager
EntityManager