Skip to main content
Skip to main content

listRuleTypes - Pricing Module Reference

Beta

This documentation provides a reference to the listRuleTypes method. This belongs to the Pricing Module.

This method is used to retrieve a paginated list of rule types based on optional filters and configuration.

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 = await pricingService.listRuleTypes({
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 = await pricingService.listRuleTypes({
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 = await pricingService.listRuleTypes({
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 = await pricingService.listRuleTypes({
$and: [
{
id: ruleTypeId
},
{
name
}
]
}, {
select: ["name"],
skip,
take
})

// do something with the rule types or return them
}

Parameters

The filters to apply on the retrieved rule types.
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.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<RuleTypeDTO[]>Required
The list of rule types.
Was this section helpful?