chore: merge money amounts and price set money amounts (#6768)
what: - merges price set money amounts and money amount
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import { BaseFilterable } from "../../dal"
|
||||
import { CreatePriceSetPriceRules } from "./price-list"
|
||||
import { Context } from "../../shared-context"
|
||||
import {
|
||||
CreateMoneyAmountDTO,
|
||||
FilterableMoneyAmountProps,
|
||||
MoneyAmountDTO,
|
||||
} from "./money-amount"
|
||||
import { CreatePriceSetPriceRules } from "./price-list"
|
||||
import { RuleTypeDTO } from "./rule-type"
|
||||
import { Context } from "../../shared-context"
|
||||
|
||||
export interface PricingRepositoryService {
|
||||
calculatePrices(
|
||||
@@ -145,9 +145,9 @@ export interface CalculatedPriceSet {
|
||||
*/
|
||||
calculated_price?: {
|
||||
/**
|
||||
* The ID of the money amount selected as the calculated price.
|
||||
* The ID of the price selected as the calculated price.
|
||||
*/
|
||||
money_amount_id: string | null
|
||||
id: string | null
|
||||
/**
|
||||
* The ID of the associated price list, if any.
|
||||
*/
|
||||
@@ -157,11 +157,11 @@ export interface CalculatedPriceSet {
|
||||
*/
|
||||
price_list_type: string | null
|
||||
/**
|
||||
* The `min_quantity` field defined on a money amount.
|
||||
* The `min_quantity` field defined on a price.
|
||||
*/
|
||||
min_quantity: number | null
|
||||
/**
|
||||
* The `max_quantity` field defined on a money amount.
|
||||
* The `max_quantity` field defined on a price.
|
||||
*/
|
||||
max_quantity: number | null
|
||||
}
|
||||
@@ -171,9 +171,9 @@ export interface CalculatedPriceSet {
|
||||
*/
|
||||
original_price?: {
|
||||
/**
|
||||
* The ID of the money amount selected as the original price.
|
||||
* The ID of the price selected as the original price.
|
||||
*/
|
||||
money_amount_id: string | null
|
||||
id: string | null
|
||||
/**
|
||||
* The ID of the associated price list, if any.
|
||||
*/
|
||||
@@ -183,11 +183,11 @@ export interface CalculatedPriceSet {
|
||||
*/
|
||||
price_list_type: string | null
|
||||
/**
|
||||
* The `min_quantity` field defined on a money amount.
|
||||
* The `min_quantity` field defined on a price.
|
||||
*/
|
||||
min_quantity: number | null
|
||||
/**
|
||||
* The `max_quantity` field defined on a money amount.
|
||||
* The `max_quantity` field defined on a price.
|
||||
*/
|
||||
max_quantity: number | null
|
||||
}
|
||||
|
||||
@@ -3,20 +3,17 @@ import {
|
||||
AddPricesDTO,
|
||||
AddRulesDTO,
|
||||
CalculatedPriceSet,
|
||||
CreateMoneyAmountDTO,
|
||||
CreatePriceListDTO,
|
||||
CreatePriceListRuleDTO,
|
||||
CreatePriceRuleDTO,
|
||||
CreatePriceSetDTO,
|
||||
CreateRuleTypeDTO,
|
||||
FilterableMoneyAmountProps,
|
||||
FilterablePriceListProps,
|
||||
FilterablePriceListRuleProps,
|
||||
FilterablePriceRuleProps,
|
||||
FilterablePriceSetMoneyAmountProps,
|
||||
FilterablePriceSetProps,
|
||||
FilterableRuleTypeProps,
|
||||
MoneyAmountDTO,
|
||||
PriceListDTO,
|
||||
PriceListRuleDTO,
|
||||
PriceRuleDTO,
|
||||
@@ -28,7 +25,6 @@ import {
|
||||
RemovePriceSetRulesDTO,
|
||||
RuleTypeDTO,
|
||||
SetPriceListRulesDTO,
|
||||
UpdateMoneyAmountDTO,
|
||||
UpdatePriceListDTO,
|
||||
UpdatePriceListPricesDTO,
|
||||
UpdatePriceListRuleDTO,
|
||||
@@ -886,456 +882,6 @@ export interface IPricingModuleService extends IModuleService {
|
||||
*/
|
||||
addRules(data: AddRulesDTO[], sharedContext?: Context): Promise<PriceSetDTO[]>
|
||||
|
||||
/**
|
||||
* This method retrieves a money amount by its ID.
|
||||
*
|
||||
* @param {string} id - The ID of the money amount to retrieve.
|
||||
* @param {FindConfig<MoneyAmountDTO>} config -
|
||||
* The configurations determining how a money amount is retrieved. Its properties, such as `select` or `relations`, accept the
|
||||
* attributes or relations associated with a money amount.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<MoneyAmountDTO>} The retrieved money amount.
|
||||
*
|
||||
* @example
|
||||
* To retrieve a money amount by its ID:
|
||||
*
|
||||
* ```ts
|
||||
* import {
|
||||
* initialize as initializePricingModule,
|
||||
* } from "@medusajs/pricing"
|
||||
*
|
||||
* async function retrieveMoneyAmount (moneyAmountId: string) {
|
||||
* const pricingService = await initializePricingModule()
|
||||
*
|
||||
* const moneyAmount = await pricingService.retrieveMoneyAmount(
|
||||
* moneyAmountId,
|
||||
* )
|
||||
*
|
||||
* // do something with the money amount or return it
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* To retrieve relations along with the money amount:
|
||||
*
|
||||
* ```ts
|
||||
* import {
|
||||
* initialize as initializePricingModule,
|
||||
* } from "@medusajs/pricing"
|
||||
*
|
||||
* async function retrieveMoneyAmount (moneyAmountId: string) {
|
||||
* const pricingService = await initializePricingModule()
|
||||
*
|
||||
* const moneyAmount = await pricingService.retrieveMoneyAmount(
|
||||
* moneyAmountId,
|
||||
* {
|
||||
* relations: ["price_set_money_amount"]
|
||||
* }
|
||||
* )
|
||||
*
|
||||
* // do something with the money amount or return it
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
retrieveMoneyAmount(
|
||||
id: string,
|
||||
config?: FindConfig<MoneyAmountDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<MoneyAmountDTO>
|
||||
|
||||
/**
|
||||
* This method is used to retrieve a paginated list of money amounts based on optional filters and configuration.
|
||||
*
|
||||
* @param {FilterableMoneyAmountProps} filters - The filtes to apply on the retrieved money amounts.
|
||||
* @param {FindConfig<MoneyAmountDTO>} config -
|
||||
* The configurations determining how the money amounts are retrieved. Its properties, such as `select` or `relations`, accept the
|
||||
* attributes or relations associated with a money amount.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<MoneyAmountDTO[]>} The list of money amounts.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* To retrieve a list of money amounts using their IDs:
|
||||
*
|
||||
* ```ts
|
||||
* import {
|
||||
* initialize as initializePricingModule,
|
||||
* } from "@medusajs/pricing"
|
||||
*
|
||||
* async function retrieveMoneyAmounts (moneyAmountIds: string[]) {
|
||||
* const pricingService = await initializePricingModule()
|
||||
*
|
||||
* const moneyAmounts = await pricingService.listMoneyAmounts(
|
||||
* {
|
||||
* id: moneyAmountIds
|
||||
* }
|
||||
* )
|
||||
*
|
||||
* // do something with the money amounts or return them
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* To specify relations that should be retrieved within the money amounts:
|
||||
*
|
||||
* ```ts
|
||||
* import {
|
||||
* initialize as initializePricingModule,
|
||||
* } from "@medusajs/pricing"
|
||||
*
|
||||
* async function retrieveMoneyAmounts (moneyAmountIds: string[]) {
|
||||
* const pricingService = await initializePricingModule()
|
||||
*
|
||||
* const moneyAmounts = await pricingService.listMoneyAmounts(
|
||||
* {
|
||||
* id: moneyAmountIds
|
||||
* },
|
||||
* {
|
||||
* relations: ["price_set_money_amount"]
|
||||
* }
|
||||
* )
|
||||
*
|
||||
* // do something with the money amounts 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 retrieveMoneyAmounts (moneyAmountIds: string[], skip: number, take: number) {
|
||||
* const pricingService = await initializePricingModule()
|
||||
*
|
||||
* const moneyAmounts = await pricingService.listMoneyAmounts(
|
||||
* {
|
||||
* id: moneyAmountIds
|
||||
* },
|
||||
* {
|
||||
* relations: ["price_set_money_amount"],
|
||||
* skip,
|
||||
* take
|
||||
* }
|
||||
* )
|
||||
*
|
||||
* // do something with the money amounts 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 retrieveMoneyAmounts (moneyAmountIds: string[], currencyCode: string[], skip: number, take: number) {
|
||||
* const pricingService = await initializePricingModule()
|
||||
*
|
||||
* const moneyAmounts = await pricingService.listMoneyAmounts(
|
||||
* {
|
||||
* $and: [
|
||||
* {
|
||||
* id: moneyAmountIds
|
||||
* },
|
||||
* {
|
||||
* currency_code: currencyCode
|
||||
* }
|
||||
* ]
|
||||
* },
|
||||
* {
|
||||
* relations: ["price_set_money_amount"],
|
||||
* skip,
|
||||
* take
|
||||
* }
|
||||
* )
|
||||
*
|
||||
* // do something with the money amounts or return them
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
listMoneyAmounts(
|
||||
filters?: FilterableMoneyAmountProps,
|
||||
config?: FindConfig<MoneyAmountDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<MoneyAmountDTO[]>
|
||||
|
||||
/**
|
||||
* This method is used to retrieve a paginated list of money amounts along with the total count of available money amounts satisfying the provided filters.
|
||||
*
|
||||
* @param {FilterableMoneyAmountProps} filters - The filters to apply on the retrieved money amounts.
|
||||
* @param {FindConfig<MoneyAmountDTO>} config -
|
||||
* The configurations determining how the money amounts are retrieved. Its properties, such as `select` or `relations`, accept the
|
||||
* attributes or relations associated with a money amount.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<[MoneyAmountDTO[], number]>} The list of money amounts along with their total count.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* To retrieve a list of money amounts using their IDs:
|
||||
*
|
||||
* ```ts
|
||||
* import {
|
||||
* initialize as initializePricingModule,
|
||||
* } from "@medusajs/pricing"
|
||||
*
|
||||
* async function retrieveMoneyAmounts (moneyAmountIds: string[]) {
|
||||
* const pricingService = await initializePricingModule()
|
||||
*
|
||||
* const [moneyAmounts, count] = await pricingService.listAndCountMoneyAmounts(
|
||||
* {
|
||||
* id: moneyAmountIds
|
||||
* }
|
||||
* )
|
||||
*
|
||||
* // do something with the money amounts or return them
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* To specify relations that should be retrieved within the money amounts:
|
||||
*
|
||||
* ```ts
|
||||
* import {
|
||||
* initialize as initializePricingModule,
|
||||
* } from "@medusajs/pricing"
|
||||
*
|
||||
* async function retrieveMoneyAmounts (moneyAmountIds: string[]) {
|
||||
* const pricingService = await initializePricingModule()
|
||||
*
|
||||
* const [moneyAmounts, count] = await pricingService.listAndCountMoneyAmounts(
|
||||
* {
|
||||
* id: moneyAmountIds
|
||||
* },
|
||||
* {
|
||||
* relations: ["price_set_money_amount"]
|
||||
* }
|
||||
* )
|
||||
*
|
||||
* // do something with the money amounts 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 retrieveMoneyAmounts (moneyAmountIds: string[], skip: number, take: number) {
|
||||
* const pricingService = await initializePricingModule()
|
||||
*
|
||||
* const [moneyAmounts, count] = await pricingService.listAndCountMoneyAmounts(
|
||||
* {
|
||||
* id: moneyAmountIds
|
||||
* },
|
||||
* {
|
||||
* relations: ["price_set_money_amount"],
|
||||
* skip,
|
||||
* take
|
||||
* }
|
||||
* )
|
||||
*
|
||||
* // do something with the money amounts 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 retrieveMoneyAmounts (moneyAmountIds: string[], currencyCode: string[], skip: number, take: number) {
|
||||
* const pricingService = await initializePricingModule()
|
||||
*
|
||||
* const [moneyAmounts, count] = await pricingService.listAndCountMoneyAmounts(
|
||||
* {
|
||||
* $and: [
|
||||
* {
|
||||
* id: moneyAmountIds
|
||||
* },
|
||||
* {
|
||||
* currency_code: currencyCode
|
||||
* }
|
||||
* ]
|
||||
* },
|
||||
* {
|
||||
* relations: ["price_set_money_amount"],
|
||||
* skip,
|
||||
* take
|
||||
* }
|
||||
* )
|
||||
*
|
||||
* // do something with the money amounts or return them
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
listAndCountMoneyAmounts(
|
||||
filters?: FilterableMoneyAmountProps,
|
||||
config?: FindConfig<MoneyAmountDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<[MoneyAmountDTO[], number]>
|
||||
|
||||
/**
|
||||
* This method creates money amounts.
|
||||
*
|
||||
* @param {CreateMoneyAmountDTO[]} data - The money amounts to create.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<MoneyAmountDTO[]>} The list of created money amounts.
|
||||
*
|
||||
* @example
|
||||
* import {
|
||||
* initialize as initializePricingModule,
|
||||
* } from "@medusajs/pricing"
|
||||
*
|
||||
* async function retrieveMoneyAmounts () {
|
||||
* const pricingService = await initializePricingModule()
|
||||
*
|
||||
* const moneyAmounts = await pricingService.createMoneyAmounts([
|
||||
* {
|
||||
* amount: 500,
|
||||
* currency_code: "USD",
|
||||
* },
|
||||
* {
|
||||
* amount: 400,
|
||||
* currency_code: "USD",
|
||||
* min_quantity: 0,
|
||||
* max_quantity: 4
|
||||
* }
|
||||
* ])
|
||||
*
|
||||
* // do something with the money amounts or return them
|
||||
* }
|
||||
*/
|
||||
createMoneyAmounts(
|
||||
data: CreateMoneyAmountDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<MoneyAmountDTO[]>
|
||||
|
||||
createMoneyAmounts(
|
||||
data: CreateMoneyAmountDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<MoneyAmountDTO>
|
||||
|
||||
/**
|
||||
* This method updates existing money amounts.
|
||||
*
|
||||
* @param {UpdateMoneyAmountDTO[]} data - The money amounts to update, each having the attributes that should be updated in a money amount.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<MoneyAmountDTO[]>} The list of updated money amounts.
|
||||
*
|
||||
* @example
|
||||
* import {
|
||||
* initialize as initializePricingModule,
|
||||
* } from "@medusajs/pricing"
|
||||
*
|
||||
* async function updateMoneyAmounts (moneyAmountId: string, amount: number) {
|
||||
* const pricingService = await initializePricingModule()
|
||||
*
|
||||
* const moneyAmounts = await pricingService.updateMoneyAmounts([
|
||||
* {
|
||||
* id: moneyAmountId,
|
||||
* amount
|
||||
* }
|
||||
* ])
|
||||
*
|
||||
* // do something with the money amounts or return them
|
||||
* }
|
||||
*/
|
||||
updateMoneyAmounts(
|
||||
data: UpdateMoneyAmountDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<MoneyAmountDTO[]>
|
||||
|
||||
updateMoneyAmounts(
|
||||
data: UpdateMoneyAmountDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<MoneyAmountDTO>
|
||||
|
||||
/**
|
||||
* This method deletes money amounts by their IDs.
|
||||
*
|
||||
* @param {string[]} ids - The IDs of the money amounts 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 when the money amounts are successfully deleted.
|
||||
*
|
||||
* @example
|
||||
* import {
|
||||
* initialize as initializePricingModule,
|
||||
* } from "@medusajs/pricing"
|
||||
*
|
||||
* async function deleteMoneyAmounts (moneyAmountIds: string[]) {
|
||||
* const pricingService = await initializePricingModule()
|
||||
*
|
||||
* await pricingService.deleteMoneyAmounts(
|
||||
* moneyAmountIds
|
||||
* )
|
||||
* }
|
||||
*/
|
||||
deleteMoneyAmounts(ids: string[], sharedContext?: Context): Promise<void>
|
||||
|
||||
/**
|
||||
* This method soft deletes money amounts by their IDs.
|
||||
*
|
||||
* @param {string[]} ids - The IDs of the money amounts to delete.
|
||||
* @param {SoftDeleteReturn<TReturnableLinkableKeys>} config
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<void>} Resolves when the money amounts are successfully deleted.
|
||||
*
|
||||
* @example
|
||||
* import {
|
||||
* initialize as initializePricingModule,
|
||||
* } from "@medusajs/pricing"
|
||||
*
|
||||
* async function softDeleteMoneyAmounts (moneyAmountIds: string[]) {
|
||||
* const pricingService = await initializePricingModule()
|
||||
*
|
||||
* await pricingService.softDeleteMoneyAmounts(
|
||||
* moneyAmountIds
|
||||
* )
|
||||
* }
|
||||
*/
|
||||
softDeleteMoneyAmounts<TReturnableLinkableKeys extends string = string>(
|
||||
ids: string[],
|
||||
config?: SoftDeleteReturn<TReturnableLinkableKeys>,
|
||||
sharedContext?: Context
|
||||
): Promise<Record<string, string[]> | void>
|
||||
|
||||
/**
|
||||
* This method restores soft deleted money amounts by their IDs.
|
||||
*
|
||||
* @param {string[]} ids - The IDs of the money amounts to delete.
|
||||
* @param {RestoreReturn<TReturnableLinkableKeys>} config -
|
||||
* Configurations determining which relations to restore along with each of the money amounts. You can pass to its `returnLinkableKeys`
|
||||
* property any of the money amount's relation attribute names, such as `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<Record<string, string[]> | void>}
|
||||
* An object that includes the IDs of related records that were restored, such as the ID of associated price set money amounts.
|
||||
* The object's keys are the ID attribute names of the money amount entity's relations, such as `price_set_money_amount_id`,
|
||||
* and its value is an array of strings, each being the ID of the record associated with the money amount through this relation,
|
||||
* such as the IDs of associated price set money amounts.
|
||||
*
|
||||
* @example
|
||||
* import {
|
||||
* initialize as initializePricingModule,
|
||||
* } from "@medusajs/pricing"
|
||||
*
|
||||
* async function softDeleteMoneyAmounts (moneyAmountIds: string[]) {
|
||||
* const pricingService = await initializePricingModule()
|
||||
*
|
||||
* await pricingService.softDeleteMoneyAmounts(
|
||||
* moneyAmountIds
|
||||
* )
|
||||
* }
|
||||
*/
|
||||
restoreMoneyAmounts<TReturnableLinkableKeys extends string = string>(
|
||||
ids: string[],
|
||||
config?: RestoreReturn<TReturnableLinkableKeys>,
|
||||
sharedContext?: Context
|
||||
): Promise<Record<string, string[]> | void>
|
||||
|
||||
/**
|
||||
* This method is used to retrieve a rule type by its ID and and optionally based on the provided configurations.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user