RegionService
internal.internal.RegionService
Provides layer to manipulate regions.
Properties
__configModule__
Record<string, unknown>__container__
anyRequired__moduleDeclaration__
Record<string, unknown>manager_
EntityManagerRequiredtransactionManager_
undefined | EntityManagerRequiredEvents
objectRequiredEvents.CREATED
stringRequiredEvents.DELETED
stringRequiredEvents.UPDATED
stringRequiredAccessors
activeManager_
Protected
get
activeManager_(): EntityManager
Returns
EntityManager
EntityManager
EntityManagerRequiredInherited from
TransactionBaseService.activeManager_
Methods
addCountry
addCountry(regionId
, code
): Promise
<Region
>
Adds a country to the region.
Parameters
regionId
stringRequiredcode
stringRequiredReturns
Promise
<Region
>
the updated Region
addFulfillmentProvider
addFulfillmentProvider(regionId
, providerId
): Promise
<Region
>
Adds a fulfillment provider that is available in the region. Fails if the provider doesn't exist.
Parameters
regionId
stringRequiredproviderId
stringRequiredReturns
Promise
<Region
>
the updated Region
addPaymentProvider
addPaymentProvider(regionId
, providerId
): Promise
<Region
>
Adds a payment provider that is available in the region. Fails if the provider doesn't exist.
Parameters
regionId
stringRequiredproviderId
stringRequiredReturns
Promise
<Region
>
the updated Region
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.
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>RequiredInherited from
TransactionBaseService.atomicPhase_
create
create(data
): Promise
<Region
>
Creates a region.
Parameters
Returns
Promise
<Region
>
the newly created region
delete
delete(regionId
): Promise
<void
>
Deletes a region.
Parameters
regionId
stringRequiredReturns
Promise
<void
>
Promise
Promise<void>Requiredlist
list(selector?
, config?
): Promise
<Region
[]>
Lists all regions based on a query
Parameters
config
FindConfig<Region>Returns
Promise
<Region
[]>
result of the find operation
listAndCount
listAndCount(selector?
, config?
): Promise
<[Region
[], number
]>
Lists all regions based on a query and returns them along with count
Parameters
config
FindConfig<Region>Returns
Promise
<[Region
[], number
]>
result of the find operation
removeCountry
removeCountry(regionId
, code
): Promise
<Region
>
Removes a country from a Region.
Parameters
regionId
stringRequiredcode
stringRequiredReturns
Promise
<Region
>
the updated Region
removeFulfillmentProvider
removeFulfillmentProvider(regionId
, providerId
): Promise
<Region
>
Removes a fulfillment provider from a region. Is idempotent.
Parameters
regionId
stringRequiredproviderId
stringRequiredReturns
Promise
<Region
>
the updated Region
removePaymentProvider
removePaymentProvider(regionId
, providerId
): Promise
<Region
>
Removes a payment provider from a region. Is idempotent.
Parameters
regionId
stringRequiredproviderId
stringRequiredReturns
Promise
<Region
>
the updated Region
retrieve
retrieve(regionId
, config?
): Promise
<Region
>
Retrieves a region by its id.
Parameters
regionId
stringRequiredconfig
FindConfig<Region>Returns
Promise
<Region
>
the region
retrieveByCountryCode
retrieveByCountryCode(code
, config?
): Promise
<Region
>
Retrieve a region by country code.
Parameters
code
stringRequiredconfig
FindConfig<Region>Returns
Promise
<Region
>
a Region with country code
retrieveByName
retrieveByName(name
): Promise
<Region
>
Retrieves a region by name.
Parameters
name
stringRequiredReturns
Promise
<Region
>
region with the matching name
shouldRetryTransaction_
Protected
shouldRetryTransaction_(err
): boolean
Parameters
err
Record<string, unknown> | { code: string }RequiredReturns
boolean
boolean
booleanInherited from
TransactionBaseService.shouldRetryTransaction_
update
update(regionId
, update
): Promise
<Region
>
Updates a region
Parameters
regionId
stringRequiredReturns
Promise
<Region
>
the result of the update operation
validateCountry
Protected
validateCountry(code
, regionId
): Promise
<Country
>
Validates a country code. Will normalize the code before checking for existence.
Parameters
code
stringRequiredregionId
stringRequiredReturns
Promise
<Country
>
the validated 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<T
>(regionData
, id?
): Promise
<DeepPartial
<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
>>
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
taxRate
numberRequiredReturns
void
void
voidThrows
if the tax rate isn't number between 0-100
withTransaction
withTransaction(transactionManager?
): RegionService
Parameters
transactionManager
EntityManager