feat(pricing): pricing models are made soft deletable (#6732)

what:

- pricing models are made soft deletable
- adds missing timestamp attributes
- removes unwanted relationships + cascade cleanup
This commit is contained in:
Riqwan Thamir authored and GitHub committed 2024-03-20 16:03:17 +00:00
1 parent 70859397c0
commit 20243e22ee
36 files changed
+1006 -1729

No files matched your search

+1 -2
View File
@@ -1,8 +1,7 @@
export * from "./money-amount"
export * from "./price-list"
export * from "./price-rule"
export * from "./price-set"
export * from "./price-set-money-amount"
export * from "./price-set-money-amount-rules"
export * from "./price-set-rule-type"
export * from "./rule-type"
export * from "./price-list"
@@ -1,100 +0,0 @@
import { BaseFilterable } from "../../dal"
import { PriceSetMoneyAmountDTO } from "./price-set-money-amount"
import { RuleTypeDTO } from "./rule-type"
/**
* @interface
*
* A price set money amount rule's data.
*/
export interface PriceSetMoneyAmountRulesDTO {
/**
* The ID of the price set money amount.
*/
id: string
/**
* The associated price set money amount.
*
* @expandable
*/
price_set_money_amount: PriceSetMoneyAmountDTO
/**
* The associated rule type.
*
* @expandable
*/
rule_type: RuleTypeDTO
/**
* The value of the price set money amount rule.
*/
value: string
}
/**
* @interface
*
* The price set money amount rule to create.
*/
export interface CreatePriceSetMoneyAmountRulesDTO {
/**
* The ID of a price set money amount.
*/
price_set_money_amount: string
/**
* The ID of a rule type.
*/
rule_type: string
/**
* The value of the price set money amount rule.
*/
value: string
}
/**
* @interface
*
* The data to update in a price set money amount rule. The `id` is used to identify which money amount to update.
*/
export interface UpdatePriceSetMoneyAmountRulesDTO {
/**
* The ID of the price set money amount rule to update.
*/
id: string
/**
* The ID of a price set money amount.
*/
price_set_money_amount?: string
/**
* The ID of a rule type.
*/
rule_type?: string
/**
* The value of the price set money amount rule.
*/
value?: string
}
/**
* @interface
*
* Filters to apply on price set money amount rules.
*/
export interface FilterablePriceSetMoneyAmountRulesProps
extends BaseFilterable<FilterablePriceSetMoneyAmountRulesProps> {
/**
* The ID to filter price set money amount rules by.
*/
id?: string[]
/**
* The IDs to filter the price set money amount rule's associated rule type.
*/
rule_type_id?: string[]
/**
* The IDs to filter the price set money amount rule's associated price set money amount.
*/
price_set_money_amount_id?: string[]
/**
* The value to filter price set money amount rules by.
*/
value?: string[]
}
+26 -356
View File
@@ -8,14 +8,12 @@ import {
CreatePriceListRuleDTO,
CreatePriceRuleDTO,
CreatePriceSetDTO,
CreatePriceSetMoneyAmountRulesDTO,
CreateRuleTypeDTO,
FilterableMoneyAmountProps,
FilterablePriceListProps,
FilterablePriceListRuleProps,
FilterablePriceRuleProps,
FilterablePriceSetMoneyAmountProps,
FilterablePriceSetMoneyAmountRulesProps,
FilterablePriceSetProps,
FilterableRuleTypeProps,
MoneyAmountDTO,
@@ -24,7 +22,6 @@ import {
PriceRuleDTO,
PriceSetDTO,
PriceSetMoneyAmountDTO,
PriceSetMoneyAmountRulesDTO,
PricingContext,
PricingFilters,
RemovePriceListRulesDTO,
@@ -37,7 +34,6 @@ import {
UpdatePriceListRuleDTO,
UpdatePriceRuleDTO,
UpdatePriceSetDTO,
UpdatePriceSetMoneyAmountRulesDTO,
UpdateRuleTypeDTO,
} from "./common"
@@ -1697,272 +1693,6 @@ export interface IPricingModuleService extends IModuleService {
*/
deleteRuleTypes(ruleTypeIds: string[], sharedContext?: Context): Promise<void>
/**
* This method is used to a price set money amount rule by its ID based on the provided configuration.
*
* @param {string} id - The ID of the price set money amount rule to retrieve.
* @param {FindConfig<PriceSetMoneyAmountRulesDTO>} config -
* The configurations determining how the price set money amount rule is retrieved. Its properties, such as `select` or `relations`, accept the
* attributes or relations associated with a price set money amount rule.
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<PriceSetMoneyAmountRulesDTO>} The retrieved price set money amount rule.
*
* @example
* A simple example that retrieves a price set money amount rule by its ID:
*
* ```ts
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function retrievePriceSetMoneyAmountRule (id: string) {
* const pricingService = await initializePricingModule()
*
* const priceSetMoneyAmountRule = await pricingService.retrievePriceSetMoneyAmountRules(id)
*
* // do something with the price set money amount rule or return it
* }
* ```
*
* To specify relations that should be retrieved:
*
* ```ts
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function retrievePriceSetMoneyAmountRule (id: string) {
* const pricingService = await initializePricingModule()
*
* const priceSetMoneyAmountRule = await pricingService.retrievePriceSetMoneyAmountRules(id, {
* relations: ["price_set_money_amount"]
* })
*
* // do something with the price set money amount rule or return it
* }
* ```
*/
retrievePriceSetMoneyAmountRules(
id: string,
config?: FindConfig<PriceSetMoneyAmountRulesDTO>,
sharedContext?: Context
): Promise<PriceSetMoneyAmountRulesDTO>
/**
* This method is used to retrieve a paginated list of price set money amount rules based on optional filters and configuration.
*
* @param {FilterablePriceSetMoneyAmountRulesProps} filters - The filters to apply on the retrieved price set money amount rules.
* @param {FindConfig<PriceSetMoneyAmountRulesDTO>} config -
* The configurations determining how the price set money amount rules are retrieved. Its properties, such as `select` or `relations`, accept the
* attributes or relations associated with a price set money amount rule.
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<PriceSetMoneyAmountRulesDTO[]>} The list of price set money amount rules.
*
* @example
*
* To retrieve a list of price set money amount rules using their IDs:
*
* ```ts
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function retrievePriceSetMoneyAmountRules (id: string) {
* const pricingService = await initializePricingModule()
*
* const priceSetMoneyAmountRules = await pricingService.listPriceSetMoneyAmountRules({
* id: [id]
* })
*
* // do something with the price set money amount rules or return them
* }
* ```
*
* To specify relations that should be retrieved within the price set money amount rules:
*
* ```ts
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function retrievePriceSetMoneyAmountRules (id: string) {
* const pricingService = await initializePricingModule()
*
* const priceSetMoneyAmountRules = await pricingService.listPriceSetMoneyAmountRules({
* id: [id]
* }, {
* relations: ["price_set_money_amount"]
* })
*
* // do something with the price set money amount rules 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:
*
* ```ts
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function retrievePriceSetMoneyAmountRules (id: string, skip: number, take: number) {
* const pricingService = await initializePricingModule()
*
* const priceSetMoneyAmountRules = await pricingService.listPriceSetMoneyAmountRules({
* id: [id]
* }, {
* relations: ["price_set_money_amount"],
* skip,
* take
* })
*
* // do something with the price set money amount rules 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:
*
* ```ts
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function retrievePriceSetMoneyAmountRules (ids: string[], ruleTypeId: string[], skip: number, take: number) {
* const pricingService = await initializePricingModule()
*
* const priceSetMoneyAmountRules = await pricingService.listPriceSetMoneyAmountRules({
* $and: [
* {
* id: ids
* },
* {
* rule_type_id: ruleTypeId
* }
* ]
* }, {
* relations: ["price_set_money_amount"],
* skip,
* take
* })
*
* // do something with the price set money amount rules or return them
* }
* ```
*/
listPriceSetMoneyAmountRules(
filters?: FilterablePriceSetMoneyAmountRulesProps,
config?: FindConfig<PriceSetMoneyAmountRulesDTO>,
sharedContext?: Context
): Promise<PriceSetMoneyAmountRulesDTO[]>
/**
* This method is used to retrieve a paginated list of price set money amount rules along with the total count of
* available price set money amount rules satisfying the provided filters.
*
* @param {FilterablePriceSetMoneyAmountRulesProps} filters - The filters to apply on the retrieved price set money amount rules.
* @param {FindConfig<PriceSetMoneyAmountRulesDTO>} config -
* The configurations determining how the price set money amount rules are retrieved. Its properties, such as `select` or `relations`, accept the
* attributes or relations associated with a price set money amount rule.
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<[PriceSetMoneyAmountRulesDTO[], number]>} The list of price set money amount rules and their total count.
*
* @example
*
* To retrieve a list of price set money amounts using their IDs:
*
* ```ts
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function retrievePriceSetMoneyAmountRules (id: string) {
* const pricingService = await initializePricingModule()
*
* const [priceSetMoneyAmountRules, count] = await pricingService.listAndCountPriceSetMoneyAmountRules({
* id: [id]
* })
*
* // do something with the price set money amount rules or return them
* }
* ```
*
* To specify relations that should be retrieved within the price set money amount rules:
*
* ```ts
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function retrievePriceSetMoneyAmountRules (id: string) {
* const pricingService = await initializePricingModule()
*
* const [priceSetMoneyAmountRules, count] = await pricingService.listAndCountPriceSetMoneyAmountRules({
* id: [id]
* }, {
* relations: ["price_set_money_amount"],
* })
*
* // do something with the price set money amount rules 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:
*
* ```ts
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function retrievePriceSetMoneyAmountRules (id: string, skip: number, take: number) {
* const pricingService = await initializePricingModule()
*
* const [priceSetMoneyAmountRules, count] = await pricingService.listAndCountPriceSetMoneyAmountRules({
* id: [id]
* }, {
* relations: ["price_set_money_amount"],
* skip,
* take
* })
*
* // do something with the price set money amount rules 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:
*
* ```ts
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function retrievePriceSetMoneyAmountRules (ids: string[], ruleTypeId: string[], skip: number, take: number) {
* const pricingService = await initializePricingModule()
*
* const [priceSetMoneyAmountRules, count] = await pricingService.listAndCountPriceSetMoneyAmountRules({
* $and: [
* {
* id: ids
* },
* {
* rule_type_id: ruleTypeId
* }
* ]
* }, {
* relations: ["price_set_money_amount"],
* skip,
* take
* })
*
* // do something with the price set money amount rules or return them
* }
* ```
*/
listAndCountPriceSetMoneyAmountRules(
filters?: FilterablePriceSetMoneyAmountRulesProps,
config?: FindConfig<PriceSetMoneyAmountRulesDTO>,
sharedContext?: Context
): Promise<[PriceSetMoneyAmountRulesDTO[], number]>
/**
* This method is used to retrieve a paginated list of price set money amounts based on optional filters and configuration.
*
@@ -2070,6 +1800,20 @@ export interface IPricingModuleService extends IModuleService {
sharedContext?: Context
): Promise<PriceSetMoneyAmountDTO[]>
softDeletePriceSetMoneyAmounts<
TReturnableLinkableKeys extends string = string
>(
psmaIds: string[],
config?: SoftDeleteReturn<TReturnableLinkableKeys>,
sharedContext?: Context
): Promise<Record<string, string[]> | void>
restorePriceSetMoneyAmounts<TReturnableLinkableKeys extends string = string>(
psmaIds: string[],
config?: RestoreReturn<TReturnableLinkableKeys>,
sharedContext?: Context
): Promise<Record<string, string[]> | void>
/**
* This method is used to retrieve a paginated list of price set money amounts along with the total count of
* available price set money amounts satisfying the provided filters.
@@ -2178,92 +1922,6 @@ export interface IPricingModuleService extends IModuleService {
sharedContext?: Context
): Promise<[PriceSetMoneyAmountDTO[], number]>
/**
* This method is used to create new price set money amount rules. A price set money amount rule creates an association between a price set money amount and
* a rule type.
*
* @param {CreatePriceSetMoneyAmountRulesDTO[]} data - The price set money amount rules to create.
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<PriceSetMoneyAmountRulesDTO[]>} The list of created price set money amount rules.
*
* @example
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function createPriceSetMoneyAmountRules (priceSetMoneyAmountId: string, ruleTypeId: string, value: string) {
* const pricingService = await initializePricingModule()
*
* const priceSetMoneyAmountRules = await pricingService.createPriceSetMoneyAmountRules([
* {
* price_set_money_amount: priceSetMoneyAmountId,
* rule_type: ruleTypeId,
* value
* }
* ])
*
* // do something with the price set money amount rules or return them
* }
*/
createPriceSetMoneyAmountRules(
data: CreatePriceSetMoneyAmountRulesDTO[],
sharedContext?: Context
): Promise<PriceSetMoneyAmountRulesDTO[]>
/**
* This method is used to update price set money amount rules, each with their provided data.
*
* @param {UpdatePriceSetMoneyAmountRulesDTO[]} data -
* The price set money amounts to update, each having the attributes to update in a price set money amount.
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<PriceSetMoneyAmountRulesDTO[]>} The list of updated price set money amount rules.
*
* @example
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function updatePriceSetMoneyAmountRules (id: string, value: string) {
* const pricingService = await initializePricingModule()
*
* const priceSetMoneyAmountRules = await pricingService.updatePriceSetMoneyAmountRules([
* {
* id,
* value
* }
* ])
*
* // do something with the price set money amount rules or return them
* }
*/
updatePriceSetMoneyAmountRules(
data: UpdatePriceSetMoneyAmountRulesDTO[],
sharedContext?: Context
): Promise<PriceSetMoneyAmountRulesDTO[]>
/**
* This method is used to delete price set money amount rules based on the specified IDs.
*
* @param {string[]} ids - The IDs of the price set money amount rules to delete.
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<void>} Resolves once the price set money amount rules are deleted.
*
* @example
* import {
* initialize as initializePricingModule,
* } from "@medusajs/pricing"
*
* async function deletePriceSetMoneyAmountRule (id: string) {
* const pricingService = await initializePricingModule()
*
* await pricingService.deletePriceSetMoneyAmountRules([id])
* }
*/
deletePriceSetMoneyAmountRules(
ids: string[],
sharedContext?: Context
): Promise<void>
/**
* This method is used to retrieve a price rule by its ID.
*
@@ -3004,6 +2662,18 @@ export interface IPricingModuleService extends IModuleService {
sharedContext?: Context
): Promise<void>
softDeletePriceLists<TReturnableLinkableKeys extends string = string>(
priceListIds: string[],
config?: SoftDeleteReturn<TReturnableLinkableKeys>,
sharedContext?: Context
): Promise<Record<string, string[]> | void>
restorePriceLists<TReturnableLinkableKeys extends string = string>(
priceListIds: string[],
config?: RestoreReturn<TReturnableLinkableKeys>,
sharedContext?: Context
): Promise<Record<string, string[]> | void>
/**
* This method is used to retrieve a price list rule by its ID.
*