DiscountService
Provides layer to manipulate discounts.
Implements
constructor
Parameters
__namedParameters
objectRequired__namedParameters.customerService
anyRequired__namedParameters.discountConditionRepository
anyRequired__namedParameters.discountConditionService
anyRequired__namedParameters.discountRepository
anyRequired__namedParameters.discountRuleRepository
anyRequired__namedParameters.eventBusService
anyRequired__namedParameters.featureFlagRouter
anyRequired__namedParameters.giftCardRepository
anyRequired__namedParameters.newTotalsService
anyRequired__namedParameters.productService
anyRequired__namedParameters.regionService
anyRequired__namedParameters.totalsService
anyRequiredProperties
__container__
anyRequiredfeatureFlagRouter_
FlagRouterRequiredmanager_
EntityManagerRequiredtransactionManager_
undefined | EntityManagerRequiredEvents
objectRequiredEvents.CREATED
stringRequiredDefault: "discount.created"
__configModule__
Record<string, unknown>__moduleDeclaration__
Record<string, unknown>Accessors
activeManager_
Returns
EntityManager
EntityManagerRequiredMethods
addRegion
Adds a region to the discount regions array.
Parameters
discountId
stringRequiredregionId
stringRequiredReturns
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>RequiredisolationOrErrorHandler
IsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail
(error: TError) => Promise<void | TResult>Returns
Promise
Promise<TResult>RequiredcalculateDiscountForLineItem
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
CreateDiscountInputRequiredReturns
createDynamicCode
Creates a dynamic code for a discount id.
Parameters
discountId
stringRequireddata
CreateDynamicDiscountInputRequiredReturns
delete
Deletes a discount idempotently
Parameters
discountId
stringRequiredReturns
Promise
Promise<void>RequireddeleteDynamicCode
Deletes a dynamic code for a discount id.
Parameters
discountId
stringRequiredcode
stringRequiredReturns
Promise
Promise<void>RequiredhasCustomersGroupCondition
Parameters
Returns
boolean
booleanRequiredhasExpired
Parameters
Returns
boolean
booleanRequiredhasNotStarted
Parameters
Returns
boolean
booleanRequiredhasReachedLimit
Parameters
Returns
boolean
booleanRequiredisDisabled
Parameters
Returns
boolean
booleanRequiredisValidForRegion
Parameters
region_id
stringRequiredReturns
Promise
Promise<boolean>Requiredlist
Parameters
selector
FilterableDiscountPropsRequiredDefault: {}
Returns
listAndCount
Parameters
selector
FilterableDiscountPropsRequiredDefault: {}
Returns
listByCodes
List all the discounts corresponding to the given codes
Parameters
discountCodes
string[]RequiredDefault: {}
Returns
removeRegion
Removes a region from the discount regions array.
Parameters
discountId
stringRequiredregionId
stringRequiredReturns
retrieve
Gets a discount by id.
Parameters
discountId
stringRequiredDefault: {}
Returns
retrieveByCode
Gets the discount by discount code.
Parameters
discountCode
stringRequiredDefault: {}
Returns
shouldRetryTransaction_
Parameters
err
Record<string, unknown> | objectRequiredReturns
boolean
booleanRequiredupdate
Updates a discount.
Parameters
discountId
stringRequiredupdate
UpdateDiscountInputRequiredReturns
validateDiscountForCartOrThrow
Parameters
Returns
Promise
Promise<void>RequiredvalidateDiscountForProduct
Parameters
discountRuleId
stringRequiredproductId
stringReturns
Promise
Promise<boolean>RequiredvalidateDiscountRule_
Creates a discount rule with provided data given that the data is validated.
Type Parameters
T
objectRequiredParameters
discountRule
TRequiredReturns
T
TRequiredwithTransaction
Parameters
transactionManager
EntityManagerReturns
DiscountService
objectRequired