Skip to main content

ICommissionModuleService Reference

This section of the documentation provides a reference to the ICommissionModuleService interface’s methods. This is the interface developers use to use the functionalities provided by the Commission Module.
You should only use the methods in this reference when implementing complex customizations. For common cases, check out available workflows instead.
The main service interface for the Commission Module.

Methods

Commission Rule Methods

Commission Rate Methods

Commission Line Methods

Custom Methods


selectCommissionForProductLine

This section provides a reference to the selectCommissionForProductLine method. This belongs to the Commission Module. This method selects the applicable commission rule for a given product line item based on the commission rule priority system. It searches through rules in priority order and returns the first matching active rule.

Priority Order

  1. seller+product_type (highest priority)
  2. seller+product_category
  3. seller
  4. product_type
  5. product_category
  6. site (lowest priority/default)

Example

const rule = await commissionModuleService.selectCommissionForProductLine({
  seller_id: "sel_123",
  product_type_id: "ptyp_456",
  product_category_id: "pcat_789",
})

Parameters

ctx
CommissionCalculationContext
required
The calculation context containing product and seller information.

Returns

Promise
Promise<CommissionRuleDTO | null>
The first applicable commission rule found, or null if no rule matches.

createCommissionRules

This section provides a reference to the createCommissionRules method. This belongs to the Commission Module.

createCommissionRules(data, sharedContext?): Promise<CommissionRuleDTO[]>

This method creates commission rules.

Example

const rules = await commissionModuleService.createCommissionRules([
  {
    name: "Default Site Commission",
    reference: "site",
    reference_id: "",
    is_active: true,
    rate: {
      type: "percentage",
      percentage_rate: 10,
      include_tax: false,
    },
  },
])

Parameters

data
CreateCommissionRuleDTO[]
required
The commission rules to be created.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<CommissionRuleDTO[]>
The created commission rules.

createCommissionRules(data, sharedContext?): Promise<CommissionRuleDTO>

This method creates a commission rule.

Example

const rule = await commissionModuleService.createCommissionRules({
  name: "Electronics Category Commission",
  reference: "product_category",
  reference_id: "pcat_electronics",
  is_active: true,
  rate: {
    type: "percentage",
    percentage_rate: 15,
    include_tax: false,
  },
})

Parameters

data
CreateCommissionRuleDTO
required
The commission rule to be created.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<CommissionRuleDTO>
The created commission rule.

updateCommissionRules

This section provides a reference to the updateCommissionRules method. This belongs to the Commission Module.

updateCommissionRules(id, data, sharedContext?): Promise<CommissionRuleDTO>

This method updates an existing commission rule.

Example

const rule = await commissionModuleService.updateCommissionRules("com_rule_123", {
  name: "Updated Commission Rule",
  is_active: false,
})

Parameters

id
string
required
The ID of the commission rule.
data
UpdateCommissionRuleDTO
required
The attributes to update in the commission rule.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<CommissionRuleDTO>
The updated commission rule.

deleteCommissionRules

This section provides a reference to the deleteCommissionRules method. This belongs to the Commission Module.

deleteCommissionRules(ids, sharedContext?): Promise<void>

This method deletes commission rules by their IDs.

Example

await commissionModuleService.deleteCommissionRules(["com_rule_123", "com_rule_321"])

Parameters

ids
string[]
required
The IDs of the commission rules.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<void>
Resolves when the commission rules are deleted successfully.

deleteCommissionRules(id, sharedContext?): Promise<void>

This method deletes a commission rule by its ID.

Example

await commissionModuleService.deleteCommissionRules("com_rule_123")

Parameters

id
string
required
The ID of the commission rule.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<void>
Resolves when the commission rule is deleted successfully.

retrieveCommissionRule

This section provides a reference to the retrieveCommissionRule method. This belongs to the Commission Module. This method retrieves a commission rule by its ID.

Example

const rule = await commissionModuleService.retrieveCommissionRule("com_rule_123")
To retrieve with the rate:
const rule = await commissionModuleService.retrieveCommissionRule(
  "com_rule_123",
  {
    relations: ["rate"],
  }
)

Parameters

id
string
required
The ID of the commission rule.
config
FindConfig<CommissionRuleDTO>
The configurations determining how the commission rule is retrieved.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<CommissionRuleDTO>
The retrieved commission rule.

listCommissionRules

This section provides a reference to the listCommissionRules method. This belongs to the Commission Module. This method retrieves a paginated list of commission rules based on optional filters and configuration.

Example

To retrieve active commission rules:
const rules = await commissionModuleService.listCommissionRules({
  is_active: true,
})
To retrieve rules for a specific seller:
const rules = await commissionModuleService.listCommissionRules({
  reference: "seller",
  reference_id: "sel_123",
})
By default, only the first 15 records are retrieved. You can control pagination:
const rules = await commissionModuleService.listCommissionRules(
  {
    is_active: true,
  },
  {
    take: 20,
    skip: 2,
    relations: ["rate"],
  }
)

Parameters

filters
FilterableCommissionRuleProps
The filters to apply on the retrieved commission rules.
config
FindConfig<CommissionRuleDTO>
The configurations determining how the commission rule is retrieved.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<CommissionRuleDTO[]>
The list of commission rules.

listAndCountCommissionRules

This section provides a reference to the listAndCountCommissionRules method. This belongs to the Commission Module. This method retrieves a paginated list of commission rules along with the total count of available commission rules satisfying the provided filters.

Example

const [rules, count] = await commissionModuleService.listAndCountCommissionRules({
  is_active: true,
})

Parameters

filters
FilterableCommissionRuleProps
The filters to apply on the retrieved commission rules.
config
FindConfig<CommissionRuleDTO>
The configurations determining how the commission rule is retrieved.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<[CommissionRuleDTO[], number]>
The list of commission rules along with their total count.

softDeleteCommissionRules

This section provides a reference to the softDeleteCommissionRules method. This belongs to the Commission Module. This method soft deletes commission rules by their IDs.

Example

await commissionModuleService.softDeleteCommissionRules([
  "com_rule_123",
  "com_rule_321",
])

Parameters

commissionRuleIds
string[]
required
The IDs of the commission rules.
config
SoftDeleteReturn<TReturnableLinkableKeys>
An object that is used to specify an entity’s related entities that should be soft-deleted when the main entity is soft-deleted.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<void | Record<string, string[]>>
An object that includes the IDs of related records that were also soft deleted. If there are no related records, the promise resolves to void.

restoreCommissionRules

This section provides a reference to the restoreCommissionRules method. This belongs to the Commission Module. This method restores soft deleted commission rules by their IDs.

Example

await commissionModuleService.restoreCommissionRules(["com_rule_123", "com_rule_321"])

Parameters

commissionRuleIds
string[]
required
The IDs of the commission rules.
config
RestoreReturn<TReturnableLinkableKeys>
Configurations determining which relations to restore along with each of the commission rule.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<void | Record<string, string[]>>
An object that includes the IDs of related records that were restored. If there are no related records restored, the promise resolves to void.

createCommissionRates

This section provides a reference to the createCommissionRates method. This belongs to the Commission Module.

createCommissionRates(data, sharedContext?): Promise<CommissionRateDTO[]>

This method creates commission rates.

Example

const rates = await commissionModuleService.createCommissionRates([
  {
    type: "percentage",
    percentage_rate: 10,
    include_tax: false,
  },
])

Parameters

data
CreateCommissionRateDTO[]
required
The commission rates to be created.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<CommissionRateDTO[]>
The created commission rates.

updateCommissionRates

This section provides a reference to the updateCommissionRates method. This belongs to the Commission Module.

updateCommissionRates(id, data, sharedContext?): Promise<CommissionRateDTO>

This method updates an existing commission rate.

Example

const rate = await commissionModuleService.updateCommissionRates("com_rate_123", {
  percentage_rate: 15,
})

Parameters

id
string
required
The ID of the commission rate.
data
UpdateCommissionRateDTO
required
The attributes to update in the commission rate.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<CommissionRateDTO>
The updated commission rate.

deleteCommissionRates

This section provides a reference to the deleteCommissionRates method. This belongs to the Commission Module.

deleteCommissionRates(ids, sharedContext?): Promise<void>

This method deletes commission rates by their IDs.

Example

await commissionModuleService.deleteCommissionRates(["com_rate_123", "com_rate_321"])

Parameters

ids
string[]
required
The IDs of the commission rates.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<void>
Resolves when the commission rates are deleted successfully.

retrieveCommissionRate

This section provides a reference to the retrieveCommissionRate method. This belongs to the Commission Module. This method retrieves a commission rate by its ID.

Example

const rate = await commissionModuleService.retrieveCommissionRate("com_rate_123")

Parameters

id
string
required
The ID of the commission rate.
config
FindConfig<CommissionRateDTO>
The configurations determining how the commission rate is retrieved.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<CommissionRateDTO>
The retrieved commission rate.

listCommissionRates

This section provides a reference to the listCommissionRates method. This belongs to the Commission Module. This method retrieves a paginated list of commission rates based on optional filters and configuration.

Example

const rates = await commissionModuleService.listCommissionRates({
  type: "percentage",
})

Parameters

filters
FilterableCommissionRateProps
The filters to apply on the retrieved commission rates.
config
FindConfig<CommissionRateDTO>
The configurations determining how the commission rate is retrieved.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<CommissionRateDTO[]>
The list of commission rates.

listAndCountCommissionRates

This section provides a reference to the listAndCountCommissionRates method. This belongs to the Commission Module. This method retrieves a paginated list of commission rates along with the total count of available commission rates satisfying the provided filters.

Example

const [rates, count] = await commissionModuleService.listAndCountCommissionRates({
  type: "percentage",
})

Parameters

filters
FilterableCommissionRateProps
The filters to apply on the retrieved commission rates.
config
FindConfig<CommissionRateDTO>
The configurations determining how the commission rate is retrieved.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<[CommissionRateDTO[], number]>
The list of commission rates along with their total count.

softDeleteCommissionRates

This section provides a reference to the softDeleteCommissionRates method. This belongs to the Commission Module. This method soft deletes commission rates by their IDs.

Example

await commissionModuleService.softDeleteCommissionRates([
  "com_rate_123",
  "com_rate_321",
])

Parameters

commissionRateIds
string[]
required
The IDs of the commission rates.
config
SoftDeleteReturn<TReturnableLinkableKeys>
An object that is used to specify an entity’s related entities that should be soft-deleted when the main entity is soft-deleted.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<void | Record<string, string[]>>
An object that includes the IDs of related records that were also soft deleted. If there are no related records, the promise resolves to void.

restoreCommissionRates

This section provides a reference to the restoreCommissionRates method. This belongs to the Commission Module. This method restores soft deleted commission rates by their IDs.

Example

await commissionModuleService.restoreCommissionRates(["com_rate_123", "com_rate_321"])

Parameters

commissionRateIds
string[]
required
The IDs of the commission rates.
config
RestoreReturn<TReturnableLinkableKeys>
Configurations determining which relations to restore along with each of the commission rate.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<void | Record<string, string[]>>
An object that includes the IDs of related records that were restored. If there are no related records restored, the promise resolves to void.

createCommissionLines

This section provides a reference to the createCommissionLines method. This belongs to the Commission Module.

createCommissionLines(data, sharedContext?): Promise<CommissionLineDTO[]>

This method creates commission lines.

Example

const lines = await commissionModuleService.createCommissionLines([
  {
    item_line_id: "ordli_123",
    rule_id: "com_rule_123",
    currency_code: "usd",
    value: 500,
  },
])

Parameters

data
CreateCommissionLineDTO[]
required
The commission lines to be created.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<CommissionLineDTO[]>
The created commission lines.

updateCommissionLines

This section provides a reference to the updateCommissionLines method. This belongs to the Commission Module.

updateCommissionLines(id, data, sharedContext?): Promise<CommissionLineDTO>

This method updates an existing commission line.

Example

const line = await commissionModuleService.updateCommissionLines("com_line_123", {
  value: 600,
})

Parameters

id
string
required
The ID of the commission line.
data
UpdateCommissionLineDTO
required
The attributes to update in the commission line.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<CommissionLineDTO>
The updated commission line.

deleteCommissionLines

This section provides a reference to the deleteCommissionLines method. This belongs to the Commission Module.

deleteCommissionLines(ids, sharedContext?): Promise<void>

This method deletes commission lines by their IDs.

Example

await commissionModuleService.deleteCommissionLines(["com_line_123", "com_line_321"])

Parameters

ids
string[]
required
The IDs of the commission lines.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<void>
Resolves when the commission lines are deleted successfully.

retrieveCommissionLine

This section provides a reference to the retrieveCommissionLine method. This belongs to the Commission Module. This method retrieves a commission line by its ID.

Example

const line = await commissionModuleService.retrieveCommissionLine("com_line_123")

Parameters

id
string
required
The ID of the commission line.
config
FindConfig<CommissionLineDTO>
The configurations determining how the commission line is retrieved.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<CommissionLineDTO>
The retrieved commission line.

listCommissionLines

This section provides a reference to the listCommissionLines method. This belongs to the Commission Module. This method retrieves a paginated list of commission lines based on optional filters and configuration.

Example

To retrieve commission lines for a specific order line item:
const lines = await commissionModuleService.listCommissionLines({
  item_line_id: "ordli_123",
})
To retrieve commission lines by rule:
const lines = await commissionModuleService.listCommissionLines({
  rule_id: "com_rule_123",
})

Parameters

filters
FilterableCommissionLineProps
The filters to apply on the retrieved commission lines.
config
FindConfig<CommissionLineDTO>
The configurations determining how the commission line is retrieved.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<CommissionLineDTO[]>
The list of commission lines.

listAndCountCommissionLines

This section provides a reference to the listAndCountCommissionLines method. This belongs to the Commission Module. This method retrieves a paginated list of commission lines along with the total count of available commission lines satisfying the provided filters.

Example

const [lines, count] = await commissionModuleService.listAndCountCommissionLines({
  item_line_id: "ordli_123",
})

Parameters

filters
FilterableCommissionLineProps
The filters to apply on the retrieved commission lines.
config
FindConfig<CommissionLineDTO>
The configurations determining how the commission line is retrieved.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<[CommissionLineDTO[], number]>
The list of commission lines along with their total count.

softDeleteCommissionLines

This section provides a reference to the softDeleteCommissionLines method. This belongs to the Commission Module. This method soft deletes commission lines by their IDs.

Example

await commissionModuleService.softDeleteCommissionLines([
  "com_line_123",
  "com_line_321",
])

Parameters

commissionLineIds
string[]
required
The IDs of the commission lines.
config
SoftDeleteReturn<TReturnableLinkableKeys>
An object that is used to specify an entity’s related entities that should be soft-deleted when the main entity is soft-deleted.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<void | Record<string, string[]>>
An object that includes the IDs of related records that were also soft deleted. If there are no related records, the promise resolves to void.

restoreCommissionLines

This section provides a reference to the restoreCommissionLines method. This belongs to the Commission Module. This method restores soft deleted commission lines by their IDs.

Example

await commissionModuleService.restoreCommissionLines(["com_line_123", "com_line_321"])

Parameters

commissionLineIds
string[]
required
The IDs of the commission lines.
config
RestoreReturn<TReturnableLinkableKeys>
Configurations determining which relations to restore along with each of the commission line.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<void | Record<string, string[]>>
An object that includes the IDs of related records that were restored. If there are no related records restored, the promise resolves to void.