DiscountService
Provides layer to manipulate discounts.
Implements
constructor
Parameters
__namedParameters
ObjectRequiredProperties
__configModule__
Record<string, unknown>__container__
anyRequired__moduleDeclaration__
Record<string, unknown>featureFlagRouter_
FlagRouterRequiredmanager_
EntityManagerRequiredtransactionManager_
undefined | EntityManagerRequiredAccessors
activeManager_
Returns
EntityManager
EntityManagerRequiredMethods
addRegion
Adds a region to the discount regions array.
Parameters
discountId
stringRequiredid of discount
regionId
stringRequiredid of region to add
Returns
the result of the update operation
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.
Type Parameters
TResult
objectRequiredTError
objectRequiredParameters
work
(transactionManager: EntityManager) => Promise<TResult>Requiredthe 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
Promise<TResult>Requiredthe result of the transactional work
calculateDiscountForLineItem
Parameters
discountId
stringRequiredcalculationContextData
CalculationContextDataRequiredReturns
Promise
Promise<number>RequiredcanApplyForCustomer
Parameters
discountRuleId
stringRequiredcustomerId
undefined | stringRequiredReturns
Promise
Promise<boolean>Requiredcreate
Creates a discount with provided data given that the data is validated. Normalizes discount code to uppercase.
Parameters
discount
CreateDiscountInputRequiredthe discount data to create
Returns
the result of the create operation
createDynamicCode
Creates a dynamic code for a discount id.
Parameters
discountId
stringRequiredthe id of the discount to create a code for
data
CreateDynamicDiscountInputRequiredthe object containing a code to identify the discount by
Returns
the newly created dynamic code
delete
Deletes a discount idempotently
Parameters
discountId
stringRequiredid of discount to delete
Returns
Promise
Promise<void>Requiredthe result of the delete operation
deleteDynamicCode
Deletes a dynamic code for a discount id.
Parameters
discountId
stringRequiredthe id of the discount to create a code for
code
stringRequiredthe code to identify the discount by
Returns
Promise
Promise<void>Requiredthe newly created dynamic code
hasCustomersGroupCondition
Parameters
Returns
boolean
booleanhasExpired
Parameters
Returns
boolean
booleanhasNotStarted
Parameters
Returns
boolean
booleanhasReachedLimit
Parameters
Returns
boolean
booleanisDisabled
Parameters
Returns
boolean
booleanisValidForRegion
Parameters
region_id
stringRequiredReturns
Promise
Promise<boolean>Requiredlist
Parameters
selector
FilterableDiscountPropsRequiredthe query object for find
Default: {}
the config object containing query settings
Returns
the result of the find operation
listAndCount
Parameters
selector
FilterableDiscountPropsRequiredthe query object for find
Default: {}
the config object containing query settings
Returns
the result of the find operation
listByCodes
List all the discounts corresponding to the given codes
Parameters
discountCodes
string[]Requireddiscount codes of discounts to retrieve
the config object containing query settings
Default: {}
Returns
the discounts
removeRegion
Removes a region from the discount regions array.
Parameters
discountId
stringRequiredid of discount
regionId
stringRequiredid of region to remove
Returns
the result of the update operation
retrieve
Gets a discount by id.
Parameters
discountId
stringRequiredid of discount to retrieve
the config object containing query settings
Default: {}
Returns
the discount
retrieveByCode
Gets the discount by discount code.
Parameters
discountCode
stringRequireddiscount code of discount to retrieve
the config object containing query settings
Default: {}
Returns
the discount
shouldRetryTransaction_
Parameters
err
Record<string, unknown> | objectRequired