13 KiB
Class: DiscountService
Provides layer to manipulate discounts.
implements {BaseService}
Hierarchy
-
"medusa-interfaces"↳
DiscountService
Constructors
constructor
• new DiscountService(__namedParameters)
Parameters
| Name | Type |
|---|---|
__namedParameters |
Object |
Overrides
BaseService.constructor
Defined in
Properties
discountConditionRepository_
• Private discountConditionRepository_: typeof DiscountConditionRepository
Defined in
discountConditionService_
• Private discountConditionService_: DiscountConditionService
Defined in
discountRepository_
• Private discountRepository_: typeof DiscountRepository
Defined in
discountRuleRepository_
• Private discountRuleRepository_: typeof DiscountRuleRepository
Defined in
eventBus_
• Private eventBus_: EventBusService
Defined in
giftCardRepository_
• Private giftCardRepository_: typeof GiftCardRepository
Defined in
manager_
• Private manager_: EntityManager
Defined in
productService_
• Private productService_: ProductService
Defined in
regionService_
• Private regionService_: RegionService
Defined in
totalsService_
• Private totalsService_: TotalsService
Defined in
Methods
addRegion
▸ addRegion(discountId, regionId): Promise<Discount>
Adds a region to the discount regions array.
Parameters
| Name | Type | Description |
|---|---|---|
discountId |
string |
id of discount |
regionId |
string |
id of region to add |
Returns
Promise<Discount>
the result of the update operation
Defined in
calculateDiscountForLineItem
▸ calculateDiscountForLineItem(discountId, lineItem, cart): Promise<number>
Parameters
| Name | Type |
|---|---|
discountId |
string |
lineItem |
LineItem |
cart |
Cart |
Returns
Promise<number>
Defined in
canApplyForCustomer
▸ canApplyForCustomer(discountRuleId, customerId): Promise<boolean>
Parameters
| Name | Type |
|---|---|
discountRuleId |
string |
customerId |
undefined | string |
Returns
Promise<boolean>
Defined in
create
▸ create(discount): Promise<Discount>
Creates a discount with provided data given that the data is validated. Normalizes discount code to uppercase.
Parameters
| Name | Type | Description |
|---|---|---|
discount |
CreateDiscountInput |
the discount data to create |
Returns
Promise<Discount>
the result of the create operation
Defined in
createDynamicCode
▸ createDynamicCode(discountId, data): Promise<Discount>
Creates a dynamic code for a discount id.
Parameters
| Name | Type | Description |
|---|---|---|
discountId |
string |
the id of the discount to create a code for |
data |
CreateDynamicDiscountInput |
the object containing a code to identify the discount by |
Returns
Promise<Discount>
the newly created dynamic code
Defined in
delete
▸ delete(discountId): Promise<void>
Deletes a discount idempotently
Parameters
| Name | Type | Description |
|---|---|---|
discountId |
string |
id of discount to delete |
Returns
Promise<void>
the result of the delete operation
Defined in
deleteDynamicCode
▸ deleteDynamicCode(discountId, code): Promise<void>
Deletes a dynamic code for a discount id.
Parameters
| Name | Type | Description |
|---|---|---|
discountId |
string |
the id of the discount to create a code for |
code |
string |
the code to identify the discount by |
Returns
Promise<void>
the newly created dynamic code
Defined in
hasExpired
▸ hasExpired(discount): boolean
Parameters
| Name | Type |
|---|---|
discount |
Discount |
Returns
boolean
Defined in
hasNotStarted
▸ hasNotStarted(discount): boolean
Parameters
| Name | Type |
|---|---|
discount |
Discount |
Returns
boolean
Defined in
hasReachedLimit
▸ hasReachedLimit(discount): boolean
Parameters
| Name | Type |
|---|---|
discount |
Discount |
Returns
boolean
Defined in
isDisabled
▸ isDisabled(discount): boolean
Parameters
| Name | Type |
|---|---|
discount |
Discount |
Returns
boolean
Defined in
isValidForRegion
▸ isValidForRegion(discount, region_id): Promise<boolean>
Parameters
| Name | Type |
|---|---|
discount |
Discount |
region_id |
string |
Returns
Promise<boolean>
Defined in
list
▸ list(selector?, config?): Promise<Discount[]>
Parameters
| Name | Type | Description |
|---|---|---|
selector |
FilterableDiscountProps |
the query object for find |
config |
FindConfig<Discount> |
the config object containing query settings |
Returns
Promise<Discount[]>
the result of the find operation
Defined in
listAndCount
▸ listAndCount(selector?, config?): Promise<[Discount[], number]>
Parameters
| Name | Type | Description |
|---|---|---|
selector |
FilterableDiscountProps |
the query object for find |
config |
FindConfig<Discount> |
the config object containing query settings |
Returns
Promise<[Discount[], number]>
the result of the find operation
Defined in
removeRegion
▸ removeRegion(discountId, regionId): Promise<Discount>
Removes a region from the discount regions array.
Parameters
| Name | Type | Description |
|---|---|---|
discountId |
string |
id of discount |
regionId |
string |
id of region to remove |
Returns
Promise<Discount>
the result of the update operation
Defined in
retrieve
▸ retrieve(discountId, config?): Promise<Discount>
Gets a discount by id.
Parameters
| Name | Type | Description |
|---|---|---|
discountId |
string |
id of discount to retrieve |
config |
FindConfig<Discount> |
the config object containing query settings |
Returns
Promise<Discount>
the discount
Defined in
retrieveByCode
▸ retrieveByCode(discountCode, config?): Promise<Discount>
Gets a discount by discount code.
Parameters
| Name | Type | Description |
|---|---|---|
discountCode |
string |
discount code of discount to retrieve |
config |
FindConfig<Discount> |
the config object containing query settings |
Returns
Promise<Discount>
the discount document
Defined in
update
▸ update(discountId, update): Promise<Discount>
Updates a discount.
Parameters
| Name | Type | Description |
|---|---|---|
discountId |
string |
discount id of discount to update |
update |
UpdateDiscountInput |
the data to update the discount with |
Returns
Promise<Discount>
the result of the update operation
Defined in
validateDiscountForCartOrThrow
▸ validateDiscountForCartOrThrow(cart, discount): Promise<void>
Parameters
| Name | Type |
|---|---|
cart |
Cart |
discount |
Discount |
Returns
Promise<void>
Defined in
validateDiscountForProduct
▸ validateDiscountForProduct(discountRuleId, productId): Promise<boolean>
Parameters
| Name | Type |
|---|---|
discountRuleId |
string |
productId |
undefined | string |
Returns
Promise<boolean>
Defined in
validateDiscountRule_
▸ validateDiscountRule_<T>(discountRule): T
Creates a discount rule with provided data given that the data is validated.
Type parameters
| Name | Type |
|---|---|
T |
extends Object |
Parameters
| Name | Type | Description |
|---|---|---|
discountRule |
T |
the discount rule to create |
Returns
T
the result of the create operation
Defined in
withTransaction
▸ withTransaction(transactionManager): DiscountService
Parameters
| Name | Type |
|---|---|
transactionManager |
EntityManager |