listAndCountRuleTypes - Pricing Module Reference
BetaThis documentation provides a reference to the listAndCountRuleTypes
method. This belongs to the Pricing Module.
This method is used to retrieve a paginated list of rule types along with the total count of available rule types satisfying the provided filters.
Example
To retrieve a list of rule types using their IDs:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveRuleTypes (ruleTypeId: string) {
const pricingService = await initializePricingModule()
const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({
id: [
ruleTypeId
]
})
// do something with the rule types or return them
}
To specify attributes that should be retrieved within the rule types:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveRuleTypes (ruleTypeId: string) {
const pricingService = await initializePricingModule()
const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({
id: [
ruleTypeId
]
}, {
select: ["name"]
})
// do something with the rule types or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveRuleTypes (ruleTypeId: string, skip: number, take: number) {
const pricingService = await initializePricingModule()
const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({
id: [
ruleTypeId
]
}, {
select: ["name"],
skip,
take
})
// do something with the rule types or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveRuleTypes (ruleTypeId: string[], name: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()
const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({
$and: [
{
id: ruleTypeId
},
{
name
}
]
}, {
select: ["name"],
skip,
take
})
// do something with the rule types or return them
}
Parameters
filters
FilterableRuleTypePropsThe filters to apply on the retrieved rule types.
filters
FilterableRuleTypePropsconfig
FindConfig<RuleTypeDTO>The configurations determining how the rule types are retrieved. Its properties, such as select
or relations
, accept the
attributes or relations associated with a rule type.
config
FindConfig<RuleTypeDTO>select
or relations
, accept the
attributes or relations associated with a rule type.sharedContext
ContextA context used to share resources, such as transaction manager, between the application and the module.
sharedContext
ContextReturns
The list of rule types along with their total count.
Was this section helpful?