diff --git a/packages/core/core-flows/src/order/steps/add-order-transaction.ts b/packages/core/core-flows/src/order/steps/add-order-transaction.ts index 28153e59d0..833cfa1e94 100644 --- a/packages/core/core-flows/src/order/steps/add-order-transaction.ts +++ b/packages/core/core-flows/src/order/steps/add-order-transaction.ts @@ -11,7 +11,7 @@ export const addOrderTransactionStep = createStep( async (data: CreateOrderTransactionDTO, { container }) => { const service = container.resolve(ModuleRegistrationName.ORDER) - const created = await service.addTransactions(data) + const created = await service.addOrderTransactions(data) return new StepResponse(created, created.id) }, @@ -22,6 +22,6 @@ export const addOrderTransactionStep = createStep( const service = container.resolve(ModuleRegistrationName.ORDER) - await service.deleteTransactions(id) + await service.deleteOrderTransactions(id) } ) diff --git a/packages/core/core-flows/src/order/steps/create-line-items.ts b/packages/core/core-flows/src/order/steps/create-line-items.ts index 5d3d1a16ed..72dde0c266 100644 --- a/packages/core/core-flows/src/order/steps/create-line-items.ts +++ b/packages/core/core-flows/src/order/steps/create-line-items.ts @@ -16,7 +16,7 @@ export const createOrderLineItemsStep = createStep( const orderModule = container.resolve(ModuleRegistrationName.ORDER) const createdItems = input.items.length - ? await orderModule.createLineItems(input.items) + ? await orderModule.createOrderLineItems(input.items) : [] return new StepResponse( @@ -31,6 +31,6 @@ export const createOrderLineItemsStep = createStep( const orderModule = container.resolve(ModuleRegistrationName.ORDER) - await orderModule.deleteLineItems(itemIds) + await orderModule.deleteOrderLineItems(itemIds) } ) diff --git a/packages/core/core-flows/src/order/steps/create-order-shipping-methods.ts b/packages/core/core-flows/src/order/steps/create-order-shipping-methods.ts index 1640382104..500e1148b4 100644 --- a/packages/core/core-flows/src/order/steps/create-order-shipping-methods.ts +++ b/packages/core/core-flows/src/order/steps/create-order-shipping-methods.ts @@ -3,7 +3,7 @@ import { IOrderModuleService, } from "@medusajs/types" import { ModuleRegistrationName } from "@medusajs/utils" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" export interface CreateOrderShippingMethodsStepInput { shipping_methods: CreateOrderShippingMethodDTO[] @@ -19,7 +19,9 @@ export const createOrderShippingMethods = createStep( ModuleRegistrationName.ORDER ) - const created = await service.createShippingMethods(input.shipping_methods) + const created = await service.createOrderShippingMethods( + input.shipping_methods + ) return new StepResponse( created, @@ -35,6 +37,6 @@ export const createOrderShippingMethods = createStep( ModuleRegistrationName.ORDER ) - await service.deleteShippingMethods(createdMethodIds) + await service.deleteOrderShippingMethods(createdMethodIds) } ) diff --git a/packages/core/core-flows/src/order/steps/delete-line-items.ts b/packages/core/core-flows/src/order/steps/delete-line-items.ts index 4c7d155e22..bbda679959 100644 --- a/packages/core/core-flows/src/order/steps/delete-line-items.ts +++ b/packages/core/core-flows/src/order/steps/delete-line-items.ts @@ -16,7 +16,7 @@ export const deleteOrderLineItems = createStep( ModuleRegistrationName.ORDER ) - const deleted = await service.softDeleteLineItems(input.ids) + const deleted = await service.softDeleteOrderLineItems(input.ids) return new StepResponse(deleted, input.ids) }, @@ -29,6 +29,6 @@ export const deleteOrderLineItems = createStep( ModuleRegistrationName.ORDER ) - await service.restoreLineItems(ids) + await service.restoreOrderLineItems(ids) } ) diff --git a/packages/core/core-flows/src/order/steps/delete-order-shipping-methods.ts b/packages/core/core-flows/src/order/steps/delete-order-shipping-methods.ts index 8bb79ef618..f00e0b01a1 100644 --- a/packages/core/core-flows/src/order/steps/delete-order-shipping-methods.ts +++ b/packages/core/core-flows/src/order/steps/delete-order-shipping-methods.ts @@ -6,7 +6,6 @@ export interface DeleteOrderShippingMethodsStepInput { ids: string[] } - /** * This step deletes order shipping methods. */ @@ -17,7 +16,7 @@ export const deleteOrderShippingMethods = createStep( ModuleRegistrationName.ORDER ) - const deleted = await service.softDeleteShippingMethods(input.ids) + const deleted = await service.softDeleteOrderShippingMethods(input.ids) return new StepResponse(deleted, input.ids) }, @@ -30,6 +29,6 @@ export const deleteOrderShippingMethods = createStep( ModuleRegistrationName.ORDER ) - await service.restoreShippingMethods(ids) + await service.restoreOrderShippingMethods(ids) } ) diff --git a/packages/core/core-flows/src/order/steps/set-tax-lines-for-items.ts b/packages/core/core-flows/src/order/steps/set-tax-lines-for-items.ts index 77d28c9ec1..f6b2a319f3 100644 --- a/packages/core/core-flows/src/order/steps/set-tax-lines-for-items.ts +++ b/packages/core/core-flows/src/order/steps/set-tax-lines-for-items.ts @@ -28,23 +28,25 @@ export const setOrderTaxLinesForItemsStep = createStep( ) const getShippingTaxLinesPromise = - await orderService.listShippingMethodTaxLines({ + await orderService.listOrderShippingMethodTaxLines({ shipping_method_id: shipping_tax_lines.map((t) => t.shipping_line_id), }) - const getItemTaxLinesPromise = await orderService.listLineItemTaxLines({ - item_id: item_tax_lines.map((t) => t.line_item_id), - }) + const getItemTaxLinesPromise = await orderService.listOrderLineItemTaxLines( + { + item_id: item_tax_lines.map((t) => t.line_item_id), + } + ) const itemsTaxLinesData = normalizeItemTaxLinesForOrder(item_tax_lines) const setItemTaxLinesPromise = itemsTaxLinesData.length - ? orderService.setLineItemTaxLines(order.id, itemsTaxLinesData) + ? orderService.setOrderLineItemTaxLines(order.id, itemsTaxLinesData) : void 0 const shippingTaxLinesData = normalizeShippingTaxLinesForOrder(shipping_tax_lines) const setShippingTaxLinesPromise = shippingTaxLinesData.length - ? await orderService.setShippingMethodTaxLines( + ? await orderService.setOrderShippingMethodTaxLines( order.id, shippingTaxLinesData ) @@ -77,7 +79,7 @@ export const setOrderTaxLinesForItemsStep = createStep( ) if (existingLineItemTaxLines) { - await orderService.setLineItemTaxLines( + await orderService.setOrderLineItemTaxLines( order.id, existingLineItemTaxLines.map((taxLine) => ({ description: taxLine.description, @@ -90,7 +92,7 @@ export const setOrderTaxLinesForItemsStep = createStep( ) } - await orderService.setShippingMethodTaxLines( + await orderService.setOrderShippingMethodTaxLines( order.id, existingShippingMethodTaxLines.map((taxLine) => ({ description: taxLine.description, diff --git a/packages/core/core-flows/src/order/steps/update-shipping-methods.ts b/packages/core/core-flows/src/order/steps/update-shipping-methods.ts index 2790d31ac5..9b06e58166 100644 --- a/packages/core/core-flows/src/order/steps/update-shipping-methods.ts +++ b/packages/core/core-flows/src/order/steps/update-shipping-methods.ts @@ -22,12 +22,12 @@ export const updateOrderShippingMethodsStep = createStep( const { selects, relations } = getSelectsAndRelationsFromObjectArray(data, { objectFields: ["metadata"], }) - const dataBeforeUpdate = await service.listShippingMethods( + const dataBeforeUpdate = await service.listOrderShippingMethods( { id: data.map((d) => d.id) }, { relations, select: selects } ) - const updated = await service.updateShippingMethods(data) + const updated = await service.updateOrderShippingMethods(data) return new StepResponse(updated, dataBeforeUpdate) }, @@ -40,6 +40,6 @@ export const updateOrderShippingMethodsStep = createStep( ModuleRegistrationName.ORDER ) - await service.updateShippingMethods(dataBeforeUpdate) + await service.updateOrderShippingMethods(dataBeforeUpdate) } ) diff --git a/packages/core/orchestration/src/joiner/remote-joiner.ts b/packages/core/orchestration/src/joiner/remote-joiner.ts index 0dd670f4d5..2b21b71385 100644 --- a/packages/core/orchestration/src/joiner/remote-joiner.ts +++ b/packages/core/orchestration/src/joiner/remote-joiner.ts @@ -204,8 +204,8 @@ export class RemoteJoiner { // self-reference for (const alias of service_.alias) { - if (this.serviceConfigCache.has(`alias_${alias.name}}`)) { - const defined = this.serviceConfigCache.get(`alias_${alias.name}}`) + if (this.serviceConfigCache.has(`alias_${alias.name}`)) { + const defined = this.serviceConfigCache.get(`alias_${alias.name}`) if (service_.serviceName === defined?.serviceName) { continue diff --git a/packages/core/types/src/cart/service.ts b/packages/core/types/src/cart/service.ts index cc2f315326..027ef9e37d 100644 --- a/packages/core/types/src/cart/service.ts +++ b/packages/core/types/src/cart/service.ts @@ -32,8 +32,8 @@ import { CreateShippingMethodForSingleCartDTO, CreateShippingMethodTaxLineDTO, UpdateAddressDTO, - UpdateCartDataDTO, UpdateCartDTO, + UpdateCartDataDTO, UpdateLineItemDTO, UpdateLineItemTaxLineDTO, UpdateLineItemWithSelectorDTO, diff --git a/packages/core/types/src/order/service.ts b/packages/core/types/src/order/service.ts index ec7c6cbc90..63725a2f39 100644 --- a/packages/core/types/src/order/service.ts +++ b/packages/core/types/src/order/service.ts @@ -814,7 +814,7 @@ export interface IOrderModuleService extends IModuleService { * To retrieve a list of addresses using their IDs: * * ```ts - * const addresses = await orderModuleService.listAddresses({ + * const addresses = await orderModuleService.listOrderAddresses({ * id: ["123", "321"] * }) * ``` @@ -822,7 +822,7 @@ export interface IOrderModuleService extends IModuleService { * 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 - * const addresses = await orderModuleService.listAddresses({ + * const addresses = await orderModuleService.listOrderAddresses({ * id: ["123", "321"] * }, { * take: 20, @@ -830,7 +830,7 @@ export interface IOrderModuleService extends IModuleService { * }) * ``` */ - listAddresses( + listOrderAddresses( filters?: FilterableOrderAddressProps, config?: FindConfig, sharedContext?: Context @@ -845,7 +845,7 @@ export interface IOrderModuleService extends IModuleService { * * @example * ```typescript - * const addresses = await orderModuleService.createAddresses([ + * const addresses = await orderModuleService.createOrderAddresses([ * { * first_name: "John", * last_name: "Doe", @@ -859,7 +859,7 @@ export interface IOrderModuleService extends IModuleService { * ``` * */ - createAddresses( + createOrderAddresses( data: CreateOrderAddressDTO[], sharedContext?: Context ): Promise @@ -873,7 +873,7 @@ export interface IOrderModuleService extends IModuleService { * * @example * ```typescript - * const address = await orderModuleService.createAddresses({ + * const address = await orderModuleService.createOrderAddresses({ * first_name: "John", * last_name: "Doe", * address_1: "123 Main St", @@ -885,7 +885,7 @@ export interface IOrderModuleService extends IModuleService { * ``` * */ - createAddresses( + createOrderAddresses( data: CreateOrderAddressDTO, sharedContext?: Context ): Promise @@ -899,14 +899,14 @@ export interface IOrderModuleService extends IModuleService { * * @example * ```typescript - * const addresses = await orderModuleService.updateAddresses([{ + * const addresses = await orderModuleService.updateOrderAddresses([{ * id: "123", * first_name: "John", * }]) * ``` * */ - updateAddresses( + updateOrderAddresses( data: UpdateOrderAddressDTO[], sharedContext?: Context ): Promise @@ -920,14 +920,14 @@ export interface IOrderModuleService extends IModuleService { * * @example * ```typescript - * const address = await orderModuleService.updateAddresses({ + * const address = await orderModuleService.updateOrderAddresses({ * id: "123", * first_name: "John", * }) * ``` * */ - updateAddresses( + updateOrderAddresses( data: UpdateOrderAddressDTO, sharedContext?: Context ): Promise @@ -941,11 +941,11 @@ export interface IOrderModuleService extends IModuleService { * * @example * ```typescript - * await orderModuleService.deleteAddresses(["123", "321"]) + * await orderModuleService.deleteOrderAddresses(["123", "321"]) * ``` * */ - deleteAddresses(ids: string[], sharedContext?: Context): Promise + deleteOrderAddresses(ids: string[], sharedContext?: Context): Promise /** * This method deletes an address by its ID. @@ -956,11 +956,11 @@ export interface IOrderModuleService extends IModuleService { * * @example * ```typescript - * await orderModuleService.deleteAddresses("123") + * await orderModuleService.deleteOrderAddresses("123") * ``` * */ - deleteAddresses(ids: string, sharedContext?: Context): Promise + deleteOrderAddresses(ids: string, sharedContext?: Context): Promise /** * This method retrieves a line item by its ID. @@ -975,13 +975,13 @@ export interface IOrderModuleService extends IModuleService { * A simple example that retrieves an order change by its ID: * * ```ts - * const lineItem = await orderModuleService.retrieveLineItem("123") + * const lineItem = await orderModuleService.retrieveOrderLineItem("123") * ``` * * To specify relations that should be retrieved: * * ```ts - * const lineItem = await orderModuleService.retrieveLineItem( + * const lineItem = await orderModuleService.retrieveOrderLineItem( * "123", * { * relations: ["order"] @@ -990,7 +990,7 @@ export interface IOrderModuleService extends IModuleService { * ``` * */ - retrieveLineItem( + retrieveOrderLineItem( itemId: string, config?: FindConfig, sharedContext?: Context @@ -1009,7 +1009,7 @@ export interface IOrderModuleService extends IModuleService { * To retrieve a list of line items using their IDs: * * ```ts - * const lineItems = await orderModuleService.listLineItems({ + * const lineItems = await orderModuleService.listOrderLineItems({ * id: ["123", "321"] * }) * ``` @@ -1017,7 +1017,7 @@ export interface IOrderModuleService extends IModuleService { * To specify relations that should be retrieved within the line item: * * ```ts - * const lineItems = await orderModuleService.listLineItems({ + * const lineItems = await orderModuleService.listOrderLineItems({ * id: ["123", "321"] * }, { * relations: ["order"] @@ -1027,7 +1027,7 @@ export interface IOrderModuleService extends IModuleService { * 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 - * const lineItems = await orderModuleService.listLineItems({ + * const lineItems = await orderModuleService.listOrderLineItems({ * id: ["123", "321"] * }, { * relations: ["order"], @@ -1037,7 +1037,7 @@ export interface IOrderModuleService extends IModuleService { * ``` * */ - listLineItems( + listOrderLineItems( filters: FilterableOrderLineItemProps, config?: FindConfig, sharedContext?: Context @@ -1051,13 +1051,13 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} The created line items. * * @example - * const lineItems = await orderModuleService.createLineItems({ + * const lineItems = await orderModuleService.createOrderLineItems({ * title: "Shirt", * quantity: 1, * unit_price: 20 * }) */ - createLineItems( + createOrderLineItems( data: CreateOrderLineItemDTO, sharedContext?: Context ): Promise @@ -1070,13 +1070,13 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} The created line items. * * @example - * const lineItems = await orderModuleService.createLineItems([{ + * const lineItems = await orderModuleService.createOrderLineItems([{ * title: "Shirt", * quantity: 1, * unit_price: 20 * }]) */ - createLineItems( + createOrderLineItems( data: CreateOrderLineItemDTO[], sharedContext?: Context ): Promise @@ -1090,7 +1090,7 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} The created orders. * * @example - * const lineItems = await orderModuleService.createLineItems( + * const lineItems = await orderModuleService.createOrderLineItems( * "123", * [{ * title: "Shirt", @@ -1099,7 +1099,7 @@ export interface IOrderModuleService extends IModuleService { * }] * ) */ - createLineItems( + createOrderLineItems( orderId: string, items: CreateOrderLineItemDTO[], sharedContext?: Context @@ -1113,7 +1113,7 @@ export interface IOrderModuleService extends IModuleService { * * @example * ```typescript - * const lineItems = await orderModuleService.updateLineItems([ + * const lineItems = await orderModuleService.updateOrderLineItems([ * { * selector: { * id: "123" @@ -1126,7 +1126,7 @@ export interface IOrderModuleService extends IModuleService { * ``` * */ - updateLineItems( + updateOrderLineItems( data: UpdateOrderLineItemWithSelectorDTO[], sharedContext?: Context ): Promise @@ -1140,14 +1140,14 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} The updated line items. * * @example - * const lineItems = await orderModuleService.updateLineItems({ + * const lineItems = await orderModuleService.updateOrderLineItems({ * id: "123" * }, { * quantity: 2 * }) * */ - updateLineItems( + updateOrderLineItems( selector: Partial, data: Partial, sharedContext?: Context @@ -1162,7 +1162,7 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} The updated line item. * * @example - * const lineItem = await orderModuleService.updateLineItems( + * const lineItem = await orderModuleService.updateOrderLineItems( * "123", * { * quantity: 2 @@ -1170,7 +1170,7 @@ export interface IOrderModuleService extends IModuleService { * ) * */ - updateLineItems( + updateOrderLineItems( lineId: string, data: Partial, sharedContext?: Context @@ -1184,11 +1184,14 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} Resolves when the line items are deleted successfully. * * @example - * await orderModuleService.deleteLineItems([ + * await orderModuleService.deleteOrderLineItems([ * "123", "321" * ]) */ - deleteLineItems(itemIds: string[], sharedContext?: Context): Promise + deleteOrderLineItems( + itemIds: string[], + sharedContext?: Context + ): Promise /** * This method deletes a line item by its ID. @@ -1198,9 +1201,9 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} Resolves when the line item is deleted successfully. * * @example - * await orderModuleService.deleteLineItems("123") + * await orderModuleService.deleteOrderLineItems("123") */ - deleteLineItems(itemId: string, sharedContext?: Context): Promise + deleteOrderLineItems(itemId: string, sharedContext?: Context): Promise /** * This method deletes line items that match the specified filters. @@ -1210,11 +1213,11 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} Resolves when the line items are deleted successfully. * * @example - * await orderModuleService.deleteLineItems({ + * await orderModuleService.deleteOrderLineItems({ * id: ["123", "321"] * }) */ - deleteLineItems( + deleteOrderLineItems( selector: Partial, sharedContext?: Context ): Promise @@ -1304,7 +1307,7 @@ export interface IOrderModuleService extends IModuleService { * To retrieve a list of shipping methods using their IDs: * * ```ts - * const shippingMethods = await orderModuleService.listShippingMethods({ + * const shippingMethods = await orderModuleService.listOrderShippingMethods({ * id: ["123", "321"] * }, {}) * ``` @@ -1312,7 +1315,7 @@ export interface IOrderModuleService extends IModuleService { * To specify relations that should be retrieved within the shipping method: * * ```ts - * const shippingMethods = await orderModuleService.listShippingMethods({ + * const shippingMethods = await orderModuleService.listOrderShippingMethods({ * id: ["123", "321"] * }, { * relations: ["adjustments"] @@ -1322,7 +1325,7 @@ export interface IOrderModuleService extends IModuleService { * 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 - * const shippingMethods = await orderModuleService.listShippingMethods({ + * const shippingMethods = await orderModuleService.listOrderShippingMethods({ * id: ["123", "321"] * }, { * relations: ["adjustments"], @@ -1332,7 +1335,7 @@ export interface IOrderModuleService extends IModuleService { * ``` * */ - listShippingMethods( + listOrderShippingMethods( filters: FilterableOrderShippingMethodProps, config: FindConfig, sharedContext?: Context @@ -1345,13 +1348,13 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} The created shipping method. * * @example - * const shippingMethod = await orderModuleService.createShippingMethods({ + * const shippingMethod = await orderModuleService.createOrderShippingMethods({ * name: "Express Shipping", * order_id: "123", * amount: 10 * }) */ - createShippingMethods( + createOrderShippingMethods( data: CreateOrderShippingMethodDTO, sharedContext?: Context ): Promise @@ -1363,13 +1366,13 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} The created orders. * * @example - * const shippingMethods = await orderModuleService.createShippingMethods([{ + * const shippingMethods = await orderModuleService.createOrderShippingMethods([{ * name: "Express Shipping", * order_id: "123", * amount: 10 * }]) */ - createShippingMethods( + createOrderShippingMethods( data: CreateOrderShippingMethodDTO[], sharedContext?: Context ): Promise @@ -1383,7 +1386,7 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} The created shipping methods. * * @example - * const shippingMethods = await orderModuleService.createShippingMethods( + * const shippingMethods = await orderModuleService.createOrderShippingMethods( * "123", * [ * { @@ -1394,7 +1397,7 @@ export interface IOrderModuleService extends IModuleService { * ] * ) */ - createShippingMethods( + createOrderShippingMethods( orderId: string, methods: CreateOrderShippingMethodDTO[], sharedContext?: Context @@ -1408,12 +1411,12 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} The updated shipping methods. * * @example - * const shippingMethods = await orderModuleService.updateShippingMethods([{ + * const shippingMethods = await orderModuleService.updateOrderShippingMethods([{ * id: "123", * name: "Express Shipping" * }]) */ - updateShippingMethods( + updateOrderShippingMethods( data: UpdateOrderShippingMethodDTO[], sharedContext?: Context ): Promise @@ -1426,12 +1429,12 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} The updated shipping method. * * @example - * const shippingMethod = await orderModuleService.updateShippingMethods({ + * const shippingMethod = await orderModuleService.updateOrderShippingMethods({ * id: "123", * name: "Express Shipping" * }) */ - updateShippingMethods( + updateOrderShippingMethods( data: UpdateOrderShippingMethodDTO, sharedContext?: Context ): Promise @@ -1444,11 +1447,11 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} Resolves when the shipping methods are deleted successfully. * * @example - * await orderModuleService.deleteShippingMethods([ + * await orderModuleService.deleteOrderShippingMethods([ * "123", "321" * ]) */ - deleteShippingMethods( + deleteOrderShippingMethods( methodIds: string[], sharedContext?: Context ): Promise @@ -1461,9 +1464,9 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} Resolves when the shipping method is deleted successfully. * * @example - * await orderModuleService.deleteShippingMethods("123") + * await orderModuleService.deleteOrderShippingMethods("123") */ - deleteShippingMethods( + deleteOrderShippingMethods( methodId: string, sharedContext?: Context ): Promise @@ -1476,11 +1479,11 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} Resolves when the shipping methods are deleted successfully. * * @example - * await orderModuleService.deleteShippingMethods({ + * await orderModuleService.deleteOrderShippingMethods({ * id: "123" * }) */ - deleteShippingMethods( + deleteOrderShippingMethods( selector: Partial, sharedContext?: Context ): Promise @@ -1498,7 +1501,7 @@ export interface IOrderModuleService extends IModuleService { * To retrieve a list of line item adjustments using their IDs: * * ```ts - * const lineItemAdjustment = await orderModuleService.listLineItemAdjustments({ + * const lineItemAdjustment = await orderModuleService.listOrderLineItemAdjustments({ * id: ["123", "321"] * }) * ``` @@ -1506,7 +1509,7 @@ export interface IOrderModuleService extends IModuleService { * To specify relations that should be retrieved within the line item adjustment: * * ```ts - * const lineItemAdjustment = await orderModuleService.listLineItemAdjustments({ + * const lineItemAdjustment = await orderModuleService.listOrderLineItemAdjustments({ * id: ["123", "321"] * }, { * relations: ["item"] @@ -1516,7 +1519,7 @@ export interface IOrderModuleService extends IModuleService { * 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 - * const lineItemAdjustment = await orderModuleService.listLineItemAdjustments({ + * const lineItemAdjustment = await orderModuleService.listOrderLineItemAdjustments({ * id: ["123", "321"] * }, { * relations: ["item"], @@ -1526,7 +1529,7 @@ export interface IOrderModuleService extends IModuleService { * ``` * */ - listLineItemAdjustments( + listOrderLineItemAdjustments( filters: FilterableOrderLineItemAdjustmentProps, config?: FindConfig, sharedContext?: Context @@ -1539,11 +1542,11 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} The created line item adjustments. * * @example - * const lineItemAdjustments = await orderModuleService.createLineItemAdjustments([{ + * const lineItemAdjustments = await orderModuleService.createOrderLineItemAdjustments([{ * amount: 5 * }]) */ - createLineItemAdjustments( + createOrderLineItemAdjustments( data: CreateOrderAdjustmentDTO[], sharedContext?: Context ): Promise @@ -1555,11 +1558,11 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} The created line-item adjustment. * * @example - * const lineItemAdjustment = await orderModuleService.createLineItemAdjustments({ + * const lineItemAdjustment = await orderModuleService.createOrderLineItemAdjustments({ * amount: 5 * }) */ - createLineItemAdjustments( + createOrderLineItemAdjustments( data: CreateOrderAdjustmentDTO, sharedContext?: Context ): Promise @@ -1572,14 +1575,14 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} The created line item adjustments. * * @example - * const lineItemAdjustments = await orderModuleService.createLineItemAdjustments( + * const lineItemAdjustments = await orderModuleService.createOrderLineItemAdjustments( * "123", * [{ * amount: 5 * }] * ) */ - createLineItemAdjustments( + createOrderLineItemAdjustments( orderId: string, data: CreateOrderAdjustmentDTO[], sharedContext?: Context @@ -1595,7 +1598,7 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} The order's line item adjustments. * * @example - * const lineItemAdjustments = await orderModuleService.setLineItemAdjustments( + * const lineItemAdjustments = await orderModuleService.setOrderLineItemAdjustments( * "123", * [ * { @@ -1611,7 +1614,7 @@ export interface IOrderModuleService extends IModuleService { * ) * */ - setLineItemAdjustments( + setOrderLineItemAdjustments( orderId: string, data: UpsertOrderLineItemAdjustmentDTO[], sharedContext?: Context @@ -1625,11 +1628,11 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} Resolves when the line item adjustments are deleted successfully. * * @example - * await orderModuleService.deleteLineItemAdjustments([ + * await orderModuleService.deleteOrderLineItemAdjustments([ * "123", "321" * ]) */ - deleteLineItemAdjustments( + deleteOrderLineItemAdjustments( adjustmentIds: string[], sharedContext?: Context ): Promise @@ -1642,9 +1645,9 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} Resolves when the line item adjustment is deleted. * * @example - * await orderModuleService.deleteLineItemAdjustments("123") + * await orderModuleService.deleteOrderLineItemAdjustments("123") */ - deleteLineItemAdjustments( + deleteOrderLineItemAdjustments( adjustmentId: string, sharedContext?: Context ): Promise @@ -1657,11 +1660,11 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} Resolves when the line item adjustments are deleted successfully. * * @example - * await orderModuleService.deleteLineItemAdjustments({ + * await orderModuleService.deleteOrderLineItemAdjustments({ * id: "123" * }) */ - deleteLineItemAdjustments( + deleteOrderLineItemAdjustments( selector: Partial, sharedContext?: Context ): Promise @@ -1680,7 +1683,7 @@ export interface IOrderModuleService extends IModuleService { * * ```ts * const shippingMethodAdjustments = await orderModuleService - * .listShippingMethodAdjustments({ + * .listOrderShippingMethodAdjustments({ * id: ["123", "321"] * }) * ``` @@ -1689,7 +1692,7 @@ export interface IOrderModuleService extends IModuleService { * * ```ts * const shippingMethodAdjustments = await orderModuleService - * .listShippingMethodAdjustments({ + * .listOrderShippingMethodAdjustments({ * id: ["123", "321"] * }, { * relations: ["shipping_method"] @@ -1700,7 +1703,7 @@ export interface IOrderModuleService extends IModuleService { * * ```ts * const shippingMethodAdjustments = await orderModuleService - * .listShippingMethodAdjustments({ + * .listOrderShippingMethodAdjustments({ * id: ["123", "321"] * }, { * relations: ["shipping_method"], @@ -1710,7 +1713,7 @@ export interface IOrderModuleService extends IModuleService { * ``` * */ - listShippingMethodAdjustments( + listOrderShippingMethodAdjustments( filters: FilterableOrderShippingMethodAdjustmentProps, config?: FindConfig, sharedContext?: Context @@ -1724,7 +1727,7 @@ export interface IOrderModuleService extends IModuleService { * * @example * const shippingMethodAdjustments = await orderModuleService - * .createShippingMethodAdjustments([ + * .createOrderShippingMethodAdjustments([ * { * shipping_method_id: "123", * code: "50OFF", @@ -1732,7 +1735,7 @@ export interface IOrderModuleService extends IModuleService { * } * ]) */ - createShippingMethodAdjustments( + createOrderShippingMethodAdjustments( data: CreateOrderShippingMethodAdjustmentDTO[], sharedContext?: Context ): Promise @@ -1745,13 +1748,13 @@ export interface IOrderModuleService extends IModuleService { * * @example * const shippingMethodAdjustment = await orderModuleService - * .createShippingMethodAdjustments({ + * .createOrderShippingMethodAdjustments({ * shipping_method_id: "123", * code: "50OFF", * amount: 5 * }) */ - createShippingMethodAdjustments( + createOrderShippingMethodAdjustments( data: CreateOrderShippingMethodAdjustmentDTO, sharedContext?: Context ): Promise @@ -1766,7 +1769,7 @@ export interface IOrderModuleService extends IModuleService { * * @example * const shippingMethodAdjustments = await orderModuleService - * .createShippingMethodAdjustments( + * .createOrderShippingMethodAdjustments( * "123", * [{ * shipping_method_id: "123", @@ -1775,7 +1778,7 @@ export interface IOrderModuleService extends IModuleService { * }] * ) */ - createShippingMethodAdjustments( + createOrderShippingMethodAdjustments( orderId: string, data: CreateOrderShippingMethodAdjustmentDTO[], sharedContext?: Context @@ -1792,7 +1795,7 @@ export interface IOrderModuleService extends IModuleService { * * @example * const shippingMethodAdjustments = await orderModuleService - * .setShippingMethodAdjustments( + * .setOrderShippingMethodAdjustments( * "123", * [ * { @@ -1808,7 +1811,7 @@ export interface IOrderModuleService extends IModuleService { * ) * */ - setShippingMethodAdjustments( + setOrderShippingMethodAdjustments( orderId: string, data: ( | CreateOrderShippingMethodAdjustmentDTO @@ -1825,11 +1828,11 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} Resolves when the shipping method adjustments are deleted successfully. * * @example - * await orderModuleService.deleteShippingMethodAdjustments([ + * await orderModuleService.deleteOrderShippingMethodAdjustments([ * "123", "321" * ]) */ - deleteShippingMethodAdjustments( + deleteOrderShippingMethodAdjustments( adjustmentIds: string[], sharedContext?: Context ): Promise @@ -1842,9 +1845,9 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} Resolves when the shipping method adjustment is deleted successfully * * @example - * await orderModuleService.deleteShippingMethodAdjustments("123") + * await orderModuleService.deleteOrderShippingMethodAdjustments("123") */ - deleteShippingMethodAdjustments( + deleteOrderShippingMethodAdjustments( adjustmentId: string, sharedContext?: Context ): Promise @@ -1857,11 +1860,11 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} Resolves when the shipping method adjustments are deleted. * * @example - * await orderModuleService.deleteShippingMethodAdjustments({ + * await orderModuleService.deleteOrderShippingMethodAdjustments({ * id: "123" * }) */ - deleteShippingMethodAdjustments( + deleteOrderShippingMethodAdjustments( selector: Partial, sharedContext?: Context ): Promise @@ -1880,7 +1883,7 @@ export interface IOrderModuleService extends IModuleService { * * ```ts * const lineItemTaxLines = await orderModuleService - * .listLineItemTaxLines({ + * .listOrderLineItemTaxLines({ * id: ["123", "321"] * }) * ``` @@ -1889,7 +1892,7 @@ export interface IOrderModuleService extends IModuleService { * * ```ts * const lineItemTaxLines = await orderModuleService - * .listLineItemTaxLines({ + * .listOrderLineItemTaxLines({ * id: ["123", "321"] * }, { * relations: ["item"] @@ -1900,7 +1903,7 @@ export interface IOrderModuleService extends IModuleService { * * ```ts * const lineItemTaxLines = await orderModuleService - * .listLineItemTaxLines({ + * .listOrderLineItemTaxLines({ * id: ["123", "321"] * }, { * relations: ["item"], @@ -1910,7 +1913,7 @@ export interface IOrderModuleService extends IModuleService { * ``` * */ - listLineItemTaxLines( + listOrderLineItemTaxLines( filters: FilterableOrderLineItemTaxLineProps, config?: FindConfig, sharedContext?: Context @@ -1924,14 +1927,14 @@ export interface IOrderModuleService extends IModuleService { * * @example * const lineItemTaxLines = await orderModuleService - * .createLineItemTaxLines([ + * .createOrderLineItemTaxLines([ * { * code: "123", * rate: 2 * } * ]) */ - createLineItemTaxLines( + createOrderLineItemTaxLines( taxLines: CreateOrderLineItemTaxLineDTO[], sharedContext?: Context ): Promise @@ -1944,12 +1947,12 @@ export interface IOrderModuleService extends IModuleService { * * @example * const lineItemTaxLines = await orderModuleService - * .createLineItemTaxLines({ + * .createOrderLineItemTaxLines({ * code: "123", * rate: 2 * }) */ - createLineItemTaxLines( + createOrderLineItemTaxLines( taxLine: CreateOrderLineItemTaxLineDTO, sharedContext?: Context ): Promise @@ -1964,7 +1967,7 @@ export interface IOrderModuleService extends IModuleService { * * @example * const lineItemTaxLines = await orderModuleService - * .createLineItemTaxLines( + * .createOrderLineItemTaxLines( * "123", * [ * { @@ -1974,7 +1977,7 @@ export interface IOrderModuleService extends IModuleService { * ] * ) */ - createLineItemTaxLines( + createOrderLineItemTaxLines( orderId: string, taxLines: CreateOrderLineItemTaxLineDTO[] | CreateOrderLineItemTaxLineDTO, sharedContext?: Context @@ -1991,7 +1994,7 @@ export interface IOrderModuleService extends IModuleService { * * @example * const lineItemTaxLines = await orderModuleService - * .setLineItemTaxLines( + * .setOrderLineItemTaxLines( * "123", * [ * { @@ -2002,7 +2005,7 @@ export interface IOrderModuleService extends IModuleService { * ) * */ - setLineItemTaxLines( + setOrderLineItemTaxLines( orderId: string, taxLines: (CreateOrderLineItemTaxLineDTO | UpdateOrderLineItemTaxLineDTO)[], sharedContext?: Context @@ -2016,11 +2019,11 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} Resolves when the line item tax lines are deleted successfully. * * @example - * await orderModuleService.deleteLineItemTaxLines([ + * await orderModuleService.deleteOrderLineItemTaxLines([ * "123", "321" * ]) */ - deleteLineItemTaxLines( + deleteOrderLineItemTaxLines( taxLineIds: string[], sharedContext?: Context ): Promise @@ -2033,9 +2036,9 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} Resolves when the line item tax line is deleted successfully. * * @example - * await orderModuleService.deleteLineItemTaxLines("123") + * await orderModuleService.deleteOrderLineItemTaxLines("123") */ - deleteLineItemTaxLines( + deleteOrderLineItemTaxLines( taxLineId: string, sharedContext?: Context ): Promise @@ -2048,11 +2051,11 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} Resolves when the line item tax lines are deleted successfully. * * @example - * await orderModuleService.deleteLineItemTaxLines({ + * await orderModuleService.deleteOrderLineItemTaxLines({ * id: ["123", "321"] * }) */ - deleteLineItemTaxLines( + deleteOrderLineItemTaxLines( selector: FilterableOrderLineItemTaxLineProps, sharedContext?: Context ): Promise @@ -2071,7 +2074,7 @@ export interface IOrderModuleService extends IModuleService { * * ```ts * const shippingMethodTaxLines = await orderModuleService - * .listShippingMethodTaxLines({ + * .listOrderShippingMethodTaxLines({ * id: ["123", "321"] * }) * ``` @@ -2080,7 +2083,7 @@ export interface IOrderModuleService extends IModuleService { * * ```ts * const shippingMethodTaxLines = await orderModuleService - * .listShippingMethodTaxLines({ + * .listOrderShippingMethodTaxLines({ * id: ["123", "321"] * }, { * relations: ["shipping_method"] @@ -2091,7 +2094,7 @@ export interface IOrderModuleService extends IModuleService { * * ```ts * const shippingMethodTaxLines = await orderModuleService - * .listShippingMethodTaxLines({ + * .listOrderShippingMethodTaxLines({ * id: ["123", "321"] * }, { * relations: ["shipping_method"], @@ -2101,7 +2104,7 @@ export interface IOrderModuleService extends IModuleService { * ``` * */ - listShippingMethodTaxLines( + listOrderShippingMethodTaxLines( filters: FilterableOrderShippingMethodTaxLineProps, config?: FindConfig, sharedContext?: Context @@ -2115,14 +2118,14 @@ export interface IOrderModuleService extends IModuleService { * * @example * const shippingMethodTaxLines = await orderModuleService - * .createShippingMethodTaxLines([ + * .createOrderShippingMethodTaxLines([ * { * code: "123", * rate: 2 * } * ]) */ - createShippingMethodTaxLines( + createOrderShippingMethodTaxLines( taxLines: CreateOrderShippingMethodTaxLineDTO[], sharedContext?: Context ): Promise @@ -2135,12 +2138,12 @@ export interface IOrderModuleService extends IModuleService { * * @example * const shippingMethodTaxLine = await orderModuleService - * .createShippingMethodTaxLines({ + * .createOrderShippingMethodTaxLines({ * code: "123", * rate: 2 * }) */ - createShippingMethodTaxLines( + createOrderShippingMethodTaxLines( taxLine: CreateOrderShippingMethodTaxLineDTO, sharedContext?: Context ): Promise @@ -2155,7 +2158,7 @@ export interface IOrderModuleService extends IModuleService { * * @example * const shippingMethodTaxLines = await orderModuleService - * .createShippingMethodTaxLines( + * .createOrderShippingMethodTaxLines( * "123", * [{ * code: "123", @@ -2163,7 +2166,7 @@ export interface IOrderModuleService extends IModuleService { * }] * ) */ - createShippingMethodTaxLines( + createOrderShippingMethodTaxLines( orderId: string, taxLines: | CreateOrderShippingMethodTaxLineDTO[] @@ -2182,7 +2185,7 @@ export interface IOrderModuleService extends IModuleService { * * @example * const shippingMethodTaxLines = await orderModuleService - * .setShippingMethodTaxLines( + * .setOrderShippingMethodTaxLines( * "123", * [ * { @@ -2197,7 +2200,7 @@ export interface IOrderModuleService extends IModuleService { * ) * */ - setShippingMethodTaxLines( + setOrderShippingMethodTaxLines( orderId: string, taxLines: ( | CreateOrderShippingMethodTaxLineDTO @@ -2214,11 +2217,11 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} Resolves when the shipping method tax lines are deleted successfully. * * @example - * await orderModuleService.deleteShippingMethodTaxLines([ + * await orderModuleService.deleteOrderShippingMethodTaxLines([ * "123", "321" * ]) */ - deleteShippingMethodTaxLines( + deleteOrderShippingMethodTaxLines( taxLineIds: string[], sharedContext?: Context ): Promise @@ -2231,9 +2234,9 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} Resolves when the shipping method tax line is deleted successfully. * * @example - * await orderModuleService.deleteShippingMethodTaxLines("123") + * await orderModuleService.deleteOrderShippingMethodTaxLines("123") */ - deleteShippingMethodTaxLines( + deleteOrderShippingMethodTaxLines( taxLineId: string, sharedContext?: Context ): Promise @@ -2246,11 +2249,11 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} Resolves when the shipping method tax lines are deleted successfully. * * @example - * await orderModuleService.deleteShippingMethodTaxLines({ + * await orderModuleService.deleteOrderShippingMethodTaxLines({ * id: ["123", "321"] * }) */ - deleteShippingMethodTaxLines( + deleteOrderShippingMethodTaxLines( selector: FilterableOrderShippingMethodTaxLineProps, sharedContext?: Context ): Promise @@ -3043,11 +3046,11 @@ export interface IOrderModuleService extends IModuleService { * If there are no related records, the promise resolves to `void`. * * @example - * await orderModuleService.softDeleteAddresses([ + * await orderModuleService.softDeleteOrderAddresses([ * "123", "321" * ]) */ - softDeleteAddresses( + softDeleteOrderAddresses( ids: string[], config?: SoftDeleteReturn, sharedContext?: Context @@ -3067,11 +3070,11 @@ export interface IOrderModuleService extends IModuleService { * If there are no related records restored, the promise resolves to `void`. * * @example - * await orderModuleService.restoreAddresses([ + * await orderModuleService.restoreOrderAddresses([ * "123", "321" * ]) */ - restoreAddresses( + restoreOrderAddresses( ids: string[], config?: RestoreReturn, sharedContext?: Context @@ -3090,11 +3093,11 @@ export interface IOrderModuleService extends IModuleService { * If there are no related records, the promise resolves to `void`. * * @example - * await orderModuleService.softDeleteLineItems([ + * await orderModuleService.softDeleteOrderLineItems([ * "123", "321" * ]) */ - softDeleteLineItems( + softDeleteOrderLineItems( ids: string[], config?: SoftDeleteReturn, sharedContext?: Context @@ -3114,11 +3117,11 @@ export interface IOrderModuleService extends IModuleService { * If there are no related records restored, the promise resolves to `void`. * * @example - * await orderModuleService.restoreLineItems([ + * await orderModuleService.restoreOrderLineItems([ * "123", "321" * ]) */ - restoreLineItems( + restoreOrderLineItems( ids: string[], config?: RestoreReturn, sharedContext?: Context @@ -3137,11 +3140,13 @@ export interface IOrderModuleService extends IModuleService { * If there are no related records, the promise resolves to `void`. * * @example - * await orderModuleService.softDeleteShippingMethods([ + * await orderModuleService.softDeleteOrderShippingMethods([ * "123", "321" * ]) */ - softDeleteShippingMethods( + softDeleteOrderShippingMethods< + TReturnableLinkableKeys extends string = string + >( ids: string[], config?: SoftDeleteReturn, sharedContext?: Context @@ -3161,11 +3166,11 @@ export interface IOrderModuleService extends IModuleService { * If there are no related records restored, the promise resolves to `void`. * * @example - * await orderModuleService.restoreShippingMethods([ + * await orderModuleService.restoreOrderShippingMethods([ * "123", "321" * ]) */ - restoreShippingMethods( + restoreOrderShippingMethods( ids: string[], config?: RestoreReturn, sharedContext?: Context @@ -3184,11 +3189,11 @@ export interface IOrderModuleService extends IModuleService { * If there are no related records, the promise resolves to `void`. * * @example - * await orderModuleService.softDeleteLineItemAdjustments([ + * await orderModuleService.softDeleteOrderLineItemAdjustments([ * "123", "321" * ]) */ - softDeleteLineItemAdjustments< + softDeleteOrderLineItemAdjustments< TReturnableLinkableKeys extends string = string >( ids: string[], @@ -3210,11 +3215,13 @@ export interface IOrderModuleService extends IModuleService { * If there are no related records restored, the promise resolves to `void`. * * @example - * await orderModuleService.restoreLineItemAdjustments([ + * await orderModuleService.restoreOrderLineItemAdjustments([ * "123", "321" * ]) */ - restoreLineItemAdjustments( + restoreOrderLineItemAdjustments< + TReturnableLinkableKeys extends string = string + >( ids: string[], config?: RestoreReturn, sharedContext?: Context @@ -3233,11 +3240,11 @@ export interface IOrderModuleService extends IModuleService { * If there are no related records, the promise resolves to `void`. * * @example - * await orderModuleService.softDeleteShippingMethodAdjustments([ + * await orderModuleService.softDeleteOrderShippingMethodAdjustments([ * "123", "321" * ]) */ - softDeleteShippingMethodAdjustments< + softDeleteOrderShippingMethodAdjustments< TReturnableLinkableKeys extends string = string >( ids: string[], @@ -3259,11 +3266,11 @@ export interface IOrderModuleService extends IModuleService { * If there are no related records restored, the promise resolves to `void`. * * @example - * await orderModuleService.restoreShippingMethodAdjustments([ + * await orderModuleService.restoreOrderShippingMethodAdjustments([ * "123", "321" * ]) */ - restoreShippingMethodAdjustments< + restoreOrderShippingMethodAdjustments< TReturnableLinkableKeys extends string = string >( ids: string[], @@ -3284,11 +3291,13 @@ export interface IOrderModuleService extends IModuleService { * If there are no related records, the promise resolves to `void`. * * @example - * await orderModuleService.softDeleteLineItemTaxLines([ + * await orderModuleService.softDeleteOrderLineItemTaxLines([ * "123", "321" * ]) */ - softDeleteLineItemTaxLines( + softDeleteOrderLineItemTaxLines< + TReturnableLinkableKeys extends string = string + >( ids: string[], config?: SoftDeleteReturn, sharedContext?: Context @@ -3308,11 +3317,11 @@ export interface IOrderModuleService extends IModuleService { * If there are no related records restored, the promise resolves to `void`. * * @example - * await orderModuleService.restoreLineItemTaxLines([ + * await orderModuleService.restoreOrderLineItemTaxLines([ * "123", "321" * ]) */ - restoreLineItemTaxLines( + restoreOrderLineItemTaxLines( ids: string[], config?: RestoreReturn, sharedContext?: Context @@ -3331,11 +3340,11 @@ export interface IOrderModuleService extends IModuleService { * If there are no related records, the promise resolves to `void`. * * @example - * await orderModuleService.softDeleteShippingMethodTaxLines([ + * await orderModuleService.softDeleteOrderShippingMethodTaxLines([ * "123", "321" * ]) */ - softDeleteShippingMethodTaxLines< + softDeleteOrderShippingMethodTaxLines< TReturnableLinkableKeys extends string = string >( ids: string[], @@ -3357,11 +3366,11 @@ export interface IOrderModuleService extends IModuleService { * If there are no related records restored, the promise resolves to `void`. * * @example - * await orderModuleService.restoreShippingMethodTaxLines([ + * await orderModuleService.restoreOrderShippingMethodTaxLines([ * "123", "321" * ]) */ - restoreShippingMethodTaxLines< + restoreOrderShippingMethodTaxLines< TReturnableLinkableKeys extends string = string >( ids: string[], @@ -3394,7 +3403,7 @@ export interface IOrderModuleService extends IModuleService { * To retrieve a list of transactions using their IDs: * * ```ts - * const transactions = await orderModuleService.listTransactions({ + * const transactions = await orderModuleService.listOrderTransactions({ * id: ["123", "321"] * }) * ``` @@ -3402,7 +3411,7 @@ export interface IOrderModuleService extends IModuleService { * To specify relations that should be retrieved within the transaction: * * ```ts - * const transactions = await orderModuleService.listTransactions({ + * const transactions = await orderModuleService.listOrderTransactions({ * id: ["123", "321"] * }, { * relations: ["order"] @@ -3412,7 +3421,7 @@ export interface IOrderModuleService extends IModuleService { * 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 - * const transactions = await orderModuleService.listTransactions({ + * const transactions = await orderModuleService.listOrderTransactions({ * id: ["123", "321"] * }, { * relations: ["order"], @@ -3421,7 +3430,7 @@ export interface IOrderModuleService extends IModuleService { * }) * ``` */ - listTransactions( + listOrderTransactions( filters?: FilterableOrderTransactionProps, config?: FindConfig, sharedContext?: Context @@ -3435,13 +3444,13 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} The created transaction. * * @example - * const transaction = await orderModuleService.addTransactions({ + * const transaction = await orderModuleService.addOrderTransactions({ * order_id: "123", * amount: 10, * currency_code: "usd" * }) */ - addTransactions( + addOrderTransactions( data: CreateOrderTransactionDTO, sharedContext?: Context ): Promise @@ -3454,13 +3463,13 @@ export interface IOrderModuleService extends IModuleService { * @returns {Promise} The created order transactions. * * @example - * const transactions = await orderModuleService.addTransactions([{ + * const transactions = await orderModuleService.addOrderTransactions([{ * order_id: "123", * amount: 10, * currency_code: "usd" * }]) */ - addTransactions( + addOrderTransactions( data: CreateOrderTransactionDTO[], sharedContext?: Context ): Promise @@ -3476,16 +3485,16 @@ export interface IOrderModuleService extends IModuleService { * To delete one transaction: * * ```ts - * await orderModuleService.deleteTransactions("123") + * await orderModuleService.deleteOrderTransactions("123") * ``` * * To delete multiple transactions: * * ```ts - * await orderModuleService.deleteTransactions(["123", "321"]) + * await orderModuleService.deleteOrderTransactions(["123", "321"]) * ``` */ - deleteTransactions( + deleteOrderTransactions( transactionIds: string | object | string[] | object[], sharedContext?: Context ): Promise @@ -3503,9 +3512,9 @@ export interface IOrderModuleService extends IModuleService { * If there are no related records, the promise resolves to `void`. * * @example - * await orderModuleService.softDeleteTransactions(["123", "321"]) + * await orderModuleService.softDeleteOrderTransactions(["123", "321"]) */ - softDeleteTransactions( + softDeleteOrderTransactions( transactionIds: string[], config?: SoftDeleteReturn, sharedContext?: Context @@ -3525,9 +3534,9 @@ export interface IOrderModuleService extends IModuleService { * If there are no related records restored, the promise resolves to `void`. * * @example - * await orderModuleService.restoreTransactions(["123", "321"]) + * await orderModuleService.restoreOrderTransactions(["123", "321"]) */ - restoreTransactions( + restoreOrderTransactions( transactionIds: string[], config?: RestoreReturn, sharedContext?: Context diff --git a/packages/modules/fulfillment/src/models/address.ts b/packages/modules/fulfillment/src/models/address.ts index a5fd0b8baf..9639a6a642 100644 --- a/packages/modules/fulfillment/src/models/address.ts +++ b/packages/modules/fulfillment/src/models/address.ts @@ -21,7 +21,7 @@ const FulfillmentDeletedAtIndex = createPsqlIndexStatementHelper({ }) @Entity({ tableName: "fulfillment_address" }) -export default class Address { +export default class FulfillmentAddress { [OptionalProps]: OptionalAddressProps @PrimaryKey({ columnType: "text" }) diff --git a/packages/modules/fulfillment/src/models/fulfillment.ts b/packages/modules/fulfillment/src/models/fulfillment.ts index bd252b5035..3a11ed5d04 100644 --- a/packages/modules/fulfillment/src/models/fulfillment.ts +++ b/packages/modules/fulfillment/src/models/fulfillment.ts @@ -20,7 +20,7 @@ import { Property, Rel, } from "@mikro-orm/core" -import Address from "./address" +import FulfillmentAddress from "./address" import FulfillmentItem from "./fulfillment-item" import FulfillmentLabel from "./fulfillment-label" import FulfillmentProvider from "./fulfillment-provider" @@ -127,13 +127,13 @@ export default class Fulfillment { provider: Rel @OneToOne({ - entity: () => Address, + entity: () => FulfillmentAddress, owner: true, cascade: [Cascade.PERSIST, "soft-remove"] as any, nullable: true, onDelete: "cascade", }) - delivery_address!: Rel
+ delivery_address!: Rel @OneToMany(() => FulfillmentItem, (item) => item.fulfillment, { cascade: [Cascade.PERSIST, "soft-remove"] as any, diff --git a/packages/modules/fulfillment/src/models/index.ts b/packages/modules/fulfillment/src/models/index.ts index 72b5f97ed0..bf0716c836 100644 --- a/packages/modules/fulfillment/src/models/index.ts +++ b/packages/modules/fulfillment/src/models/index.ts @@ -1,4 +1,4 @@ -export { default as Address } from "./address" +export { default as FulfillmentAddress } from "./address" export { default as Fulfillment } from "./fulfillment" export { default as FulfillmentItem } from "./fulfillment-item" export { default as FulfillmentLabel } from "./fulfillment-label" @@ -10,4 +10,3 @@ export { default as ShippingOption } from "./shipping-option" export { default as ShippingOptionRule } from "./shipping-option-rule" export { default as ShippingOptionType } from "./shipping-option-type" export { default as ShippingProfile } from "./shipping-profile" - diff --git a/packages/modules/order/integration-tests/__tests__/create-order.ts b/packages/modules/order/integration-tests/__tests__/create-order.ts index bb9687ec75..515d3c2442 100644 --- a/packages/modules/order/integration-tests/__tests__/create-order.ts +++ b/packages/modules/order/integration-tests/__tests__/create-order.ts @@ -217,7 +217,7 @@ moduleIntegrationTestRunner({ }) ) - const refund = await service.addTransactions([ + const refund = await service.addOrderTransactions([ { order_id: created.id, amount: -20, @@ -242,7 +242,7 @@ moduleIntegrationTestRunner({ }) ) - await service.softDeleteTransactions([refund[0].id]) + await service.softDeleteOrderTransactions([refund[0].id]) const serializedOrder2 = JSON.parse( JSON.stringify( @@ -261,7 +261,7 @@ moduleIntegrationTestRunner({ }) ) - await service.addTransactions([ + await service.addOrderTransactions([ { order_id: created.id, amount: -50, @@ -286,7 +286,7 @@ moduleIntegrationTestRunner({ }) ) - await service.restoreTransactions([refund[0].id]) + await service.restoreOrderTransactions([refund[0].id]) const serializedOrder4 = JSON.parse( JSON.stringify( diff --git a/packages/modules/order/integration-tests/__tests__/index.spec.ts b/packages/modules/order/integration-tests/__tests__/index.spec.ts index ca6e0e0a79..0c1a244d3c 100644 --- a/packages/modules/order/integration-tests/__tests__/index.spec.ts +++ b/packages/modules/order/integration-tests/__tests__/index.spec.ts @@ -14,19 +14,19 @@ moduleIntegrationTestRunner({ expect(Object.keys(linkable)).toEqual([ "order", - "address", - "lineItem", - "lineItemAdjustment", - "lineItemTaxLine", - "shippingMethod", - "shippingMethodAdjustment", - "shippingMethodTaxLine", - "transaction", + "orderAddress", + "orderLineItem", + "orderLineItemAdjustment", + "orderLineItemTaxLine", + "orderShippingMethod", + "orderShippingMethodAdjustment", + "orderShippingMethodTaxLine", + "orderTransaction", "orderChange", "orderChangeAction", "orderItem", "orderSummary", - "orderShippingMethod", + "orderShipping", "returnReason", "return", "returnItem", @@ -50,68 +50,68 @@ moduleIntegrationTestRunner({ field: "order", }, }, - address: { + orderAddress: { id: { - linkable: "address_id", + linkable: "order_address_id", primaryKey: "id", serviceName: "order", - field: "address", + field: "orderAddress", }, }, - lineItem: { + orderLineItem: { id: { - linkable: "line_item_id", + linkable: "order_line_item_id", primaryKey: "id", serviceName: "order", - field: "lineItem", + field: "orderLineItem", }, }, - lineItemAdjustment: { + orderLineItemAdjustment: { id: { - linkable: "line_item_adjustment_id", + linkable: "order_line_item_adjustment_id", primaryKey: "id", serviceName: "order", - field: "lineItemAdjustment", + field: "orderLineItemAdjustment", }, }, - lineItemTaxLine: { + orderLineItemTaxLine: { id: { - linkable: "line_item_tax_line_id", + linkable: "order_line_item_tax_line_id", primaryKey: "id", serviceName: "order", - field: "lineItemTaxLine", + field: "orderLineItemTaxLine", }, }, - shippingMethod: { + orderShippingMethod: { id: { - linkable: "shipping_method_id", + linkable: "order_shipping_method_id", primaryKey: "id", serviceName: "order", - field: "shippingMethod", + field: "orderShippingMethod", }, }, - shippingMethodAdjustment: { + orderShippingMethodAdjustment: { id: { - linkable: "shipping_method_adjustment_id", + linkable: "order_shipping_method_adjustment_id", primaryKey: "id", serviceName: "order", - field: "shippingMethodAdjustment", + field: "orderShippingMethodAdjustment", }, }, - shippingMethodTaxLine: { + orderShippingMethodTaxLine: { id: { - linkable: "shipping_method_tax_line_id", + linkable: "order_shipping_method_tax_line_id", primaryKey: "id", serviceName: "order", - field: "shippingMethodTaxLine", + field: "orderShippingMethodTaxLine", }, }, - transaction: { + orderTransaction: { id: { - linkable: "transaction_id", + linkable: "order_transaction_id", primaryKey: "id", serviceName: "order", - field: "transaction", + field: "orderTransaction", }, }, orderChange: { @@ -146,12 +146,12 @@ moduleIntegrationTestRunner({ field: "orderSummary", }, }, - orderShippingMethod: { + orderShipping: { id: { - linkable: "order_shipping_method_id", + linkable: "order_shipping_id", primaryKey: "id", serviceName: "order", - field: "orderShippingMethod", + field: "orderShipping", }, }, returnReason: { @@ -188,18 +188,18 @@ moduleIntegrationTestRunner({ }, orderClaimItem: { id: { - field: "orderClaimItem", linkable: "order_claim_item_id", primaryKey: "id", serviceName: "order", + field: "orderClaimItem", }, }, orderClaimItemImage: { id: { - field: "orderClaimItemImage", linkable: "order_claim_item_image_id", primaryKey: "id", serviceName: "order", + field: "orderClaimItemImage", }, }, orderExchange: { @@ -212,10 +212,10 @@ moduleIntegrationTestRunner({ }, orderExchangeItem: { id: { - field: "orderExchangeItem", linkable: "order_exchange_item_id", primaryKey: "id", serviceName: "order", + field: "orderExchangeItem", }, }, }) diff --git a/packages/modules/order/integration-tests/__tests__/order-items-shipping.spec.ts b/packages/modules/order/integration-tests/__tests__/order-items-shipping.spec.ts index 87893b60bc..48e87a8b08 100644 --- a/packages/modules/order/integration-tests/__tests__/order-items-shipping.spec.ts +++ b/packages/modules/order/integration-tests/__tests__/order-items-shipping.spec.ts @@ -87,7 +87,7 @@ moduleIntegrationTestRunner({ }) it("should create an order with billing id + shipping id successfully", async () => { - const [createdAddress] = await service.createAddresses([ + const [createdAddress] = await service.createOrderAddresses([ { first_name: "John", last_name: "Doe", @@ -324,13 +324,13 @@ moduleIntegrationTestRunner({ describe("createAddresses", () => { it("should create an address successfully", async () => { - const [createdAddress] = await service.createAddresses([ + const [createdAddress] = await service.createOrderAddresses([ { first_name: "John", }, ]) - const [address] = await service.listAddresses({ + const [address] = await service.listOrderAddresses({ id: [createdAddress.id!], }) @@ -345,13 +345,13 @@ moduleIntegrationTestRunner({ describe("updateAddresses", () => { it("should update an address successfully", async () => { - const [createdAddress] = await service.createAddresses([ + const [createdAddress] = await service.createOrderAddresses([ { first_name: "John", }, ]) - const [updatedAddress] = await service.updateAddresses([ + const [updatedAddress] = await service.updateOrderAddresses([ { id: createdAddress.id!, first_name: "Jane" }, ]) @@ -366,15 +366,15 @@ moduleIntegrationTestRunner({ describe("deleteAddresses", () => { it("should delete an address successfully", async () => { - const [createdAddress] = await service.createAddresses([ + const [createdAddress] = await service.createOrderAddresses([ { first_name: "John", }, ]) - await service.deleteAddresses([createdAddress.id!]) + await service.deleteOrderAddresses([createdAddress.id!]) - const [address] = await service.listAddresses({ + const [address] = await service.listOrderAddresses({ id: [createdAddress.id!], }) @@ -390,7 +390,7 @@ moduleIntegrationTestRunner({ }, ]) - await service.createLineItems(createdOrder.id, [ + await service.createOrderLineItems(createdOrder.id, [ { quantity: 1, unit_price: 100, @@ -420,7 +420,7 @@ moduleIntegrationTestRunner({ }, ]) - await service.createLineItems([ + await service.createOrderLineItems([ { quantity: 1, unit_price: 100, @@ -472,7 +472,7 @@ moduleIntegrationTestRunner({ }, ]) - const items = await service.createLineItems([ + const items = await service.createOrderLineItems([ { order_id: eurOrder.id, quantity: 1, @@ -508,7 +508,7 @@ moduleIntegrationTestRunner({ it("should throw if order does not exist", async () => { const error = await service - .createLineItems("foo", [ + .createOrderLineItems("foo", [ { quantity: 1, unit_price: 100, @@ -529,7 +529,7 @@ moduleIntegrationTestRunner({ ]) const error = await service - .createLineItems(createdOrder.id, [ + .createOrderLineItems(createdOrder.id, [ { unit_price: 10, title: "test", @@ -550,7 +550,7 @@ moduleIntegrationTestRunner({ ]) const error = await service - .createLineItems([ + .createOrderLineItems([ { order_id: createdOrder.id, unit_price: 10, @@ -573,7 +573,7 @@ moduleIntegrationTestRunner({ }, ]) - const [item] = await service.createLineItems(createdOrder.id, [ + const [item] = await service.createOrderLineItems(createdOrder.id, [ { quantity: 1, unit_price: 100, @@ -584,7 +584,7 @@ moduleIntegrationTestRunner({ expect(item.title).toBe("test") - const [updatedItem] = await service.updateLineItems( + const [updatedItem] = await service.updateOrderLineItems( { id: item.id }, { title: "test2", @@ -601,7 +601,7 @@ moduleIntegrationTestRunner({ }, ]) - const [item] = await service.createLineItems(createdOrder.id, [ + const [item] = await service.createOrderLineItems(createdOrder.id, [ { quantity: 1, unit_price: 100, @@ -612,7 +612,7 @@ moduleIntegrationTestRunner({ expect(item.title).toBe("test") - const updatedItem = await service.updateLineItems(item.id, { + const updatedItem = await service.updateOrderLineItems(item.id, { title: "test2", }) @@ -626,7 +626,7 @@ moduleIntegrationTestRunner({ }, ]) - const items = await service.createLineItems(createdOrder.id, [ + const items = await service.createOrderLineItems(createdOrder.id, [ { quantity: 1, unit_price: 100, @@ -654,7 +654,7 @@ moduleIntegrationTestRunner({ const itemTwo = items.find((i) => i.title === "other-test") - await service.updateLineItems([ + await service.updateOrderLineItems([ { selector: { unit_price: 100 }, data: { @@ -701,7 +701,7 @@ moduleIntegrationTestRunner({ }, ]) - const [item] = await service.createLineItems(createdOrder.id, [ + const [item] = await service.createOrderLineItems(createdOrder.id, [ { quantity: 1, unit_price: 100, @@ -712,7 +712,7 @@ moduleIntegrationTestRunner({ expect(item.title).toBe("test") - await service.deleteLineItems([item.id]) + await service.deleteOrderLineItems([item.id]) const order = await service.retrieveOrder(createdOrder.id, { relations: ["items"], @@ -728,20 +728,23 @@ moduleIntegrationTestRunner({ }, ]) - const [item, item2] = await service.createLineItems(createdOrder.id, [ - { - quantity: 1, - unit_price: 100, - title: "test", - }, - { - quantity: 1, - unit_price: 100, - title: "test-2", - }, - ]) + const [item, item2] = await service.createOrderLineItems( + createdOrder.id, + [ + { + quantity: 1, + unit_price: 100, + title: "test", + }, + { + quantity: 1, + unit_price: 100, + title: "test-2", + }, + ] + ) - await service.deleteLineItems([item.id, item2.id]) + await service.deleteOrderLineItems([item.id, item2.id]) const order = await service.retrieveOrder(createdOrder.id, { relations: ["items"], @@ -759,7 +762,7 @@ moduleIntegrationTestRunner({ }, ]) - const [method] = await service.createShippingMethods( + const [method] = await service.createOrderShippingMethods( createdOrder.id, [ { @@ -789,18 +792,19 @@ moduleIntegrationTestRunner({ }, ]) - const [eurMethod, usdMethod] = await service.createShippingMethods([ - { - order_id: eurOrder.id, - amount: 100, - name: "Test One", - }, - { - order_id: usdOrder.id, - amount: 100, - name: "Test One", - }, - ]) + const [eurMethod, usdMethod] = + await service.createOrderShippingMethods([ + { + order_id: eurOrder.id, + amount: 100, + name: "Test One", + }, + { + order_id: usdOrder.id, + amount: 100, + name: "Test One", + }, + ]) const orders = await service.listOrders( { id: [eurOrder.id, usdOrder.id] }, @@ -818,7 +822,7 @@ moduleIntegrationTestRunner({ }) }) - describe("setLineItemAdjustments", () => { + describe("setOrderLineItemAdjustments", () => { it("should set line item adjustments for an order", async () => { const [createdOrder] = await service.createOrders([ { @@ -826,23 +830,29 @@ moduleIntegrationTestRunner({ }, ]) - const [itemOne] = await service.createLineItems(createdOrder.id, [ - { - quantity: 1, - unit_price: 100, - title: "test", - }, - ]) + const [itemOne] = await service.createOrderLineItems( + createdOrder.id, + [ + { + quantity: 1, + unit_price: 100, + title: "test", + }, + ] + ) - const [itemTwo] = await service.createLineItems(createdOrder.id, [ - { - quantity: 2, - unit_price: 200, - title: "test-2", - }, - ]) + const [itemTwo] = await service.createOrderLineItems( + createdOrder.id, + [ + { + quantity: 2, + unit_price: 200, + title: "test-2", + }, + ] + ) - const adjustments = await service.setLineItemAdjustments( + const adjustments = await service.setOrderLineItemAdjustments( createdOrder.id, [ { @@ -881,15 +891,18 @@ moduleIntegrationTestRunner({ }, ]) - const [itemOne] = await service.createLineItems(createdOrder.id, [ - { - quantity: 1, - unit_price: 100, - title: "test", - }, - ]) + const [itemOne] = await service.createOrderLineItems( + createdOrder.id, + [ + { + quantity: 1, + unit_price: 100, + title: "test", + }, + ] + ) - const adjustments = await service.setLineItemAdjustments( + const adjustments = await service.setOrderLineItemAdjustments( createdOrder.id, [ { @@ -910,7 +923,7 @@ moduleIntegrationTestRunner({ ]) ) - await service.setLineItemAdjustments(createdOrder.id, [ + await service.setOrderLineItemAdjustments(createdOrder.id, [ { item_id: itemOne.id, amount: 50, @@ -949,15 +962,18 @@ moduleIntegrationTestRunner({ }, ]) - const [itemOne] = await service.createLineItems(createdOrder.id, [ - { - quantity: 1, - unit_price: 100, - title: "test", - }, - ]) + const [itemOne] = await service.createOrderLineItems( + createdOrder.id, + [ + { + quantity: 1, + unit_price: 100, + title: "test", + }, + ] + ) - const adjustments = await service.setLineItemAdjustments( + const adjustments = await service.setOrderLineItemAdjustments( createdOrder.id, [ { @@ -978,7 +994,7 @@ moduleIntegrationTestRunner({ ]) ) - await service.setLineItemAdjustments(createdOrder.id, []) + await service.setOrderLineItemAdjustments(createdOrder.id, []) const order = await service.retrieveOrder(createdOrder.id, { relations: ["items.item.adjustments"], @@ -1004,15 +1020,18 @@ moduleIntegrationTestRunner({ }, ]) - const [itemOne] = await service.createLineItems(createdOrder.id, [ - { - quantity: 1, - unit_price: 100, - title: "test", - }, - ]) + const [itemOne] = await service.createOrderLineItems( + createdOrder.id, + [ + { + quantity: 1, + unit_price: 100, + title: "test", + }, + ] + ) - const adjustments = await service.setLineItemAdjustments( + const adjustments = await service.setOrderLineItemAdjustments( createdOrder.id, [ { @@ -1033,7 +1052,7 @@ moduleIntegrationTestRunner({ ]) ) - await service.setLineItemAdjustments(createdOrder.id, [ + await service.setOrderLineItemAdjustments(createdOrder.id, [ { id: adjustments[0].id, item_id: itemOne.id, @@ -1076,15 +1095,18 @@ moduleIntegrationTestRunner({ }, ]) - const [itemOne] = await service.createLineItems(createdOrder.id, [ - { - quantity: 1, - unit_price: 100, - title: "test", - }, - ]) + const [itemOne] = await service.createOrderLineItems( + createdOrder.id, + [ + { + quantity: 1, + unit_price: 100, + title: "test", + }, + ] + ) - const adjustments = await service.createLineItemAdjustments( + const adjustments = await service.createOrderLineItemAdjustments( createdOrder.id, [ { @@ -1113,22 +1135,28 @@ moduleIntegrationTestRunner({ }, ]) - const [itemOne] = await service.createLineItems(createdOrder.id, [ - { - quantity: 1, - unit_price: 100, - title: "test", - }, - ]) - const [itemTwo] = await service.createLineItems(createdOrder.id, [ - { - quantity: 2, - unit_price: 200, - title: "test-2", - }, - ]) + const [itemOne] = await service.createOrderLineItems( + createdOrder.id, + [ + { + quantity: 1, + unit_price: 100, + title: "test", + }, + ] + ) + const [itemTwo] = await service.createOrderLineItems( + createdOrder.id, + [ + { + quantity: 2, + unit_price: 200, + title: "test-2", + }, + ] + ) - const adjustments = await service.createLineItemAdjustments( + const adjustments = await service.createOrderLineItemAdjustments( createdOrder.id, [ { @@ -1170,14 +1198,14 @@ moduleIntegrationTestRunner({ }, ]) - const [itemOne] = await service.createLineItems(orderOne.id, [ + const [itemOne] = await service.createOrderLineItems(orderOne.id, [ { quantity: 1, unit_price: 100, title: "test", }, ]) - const [itemTwo] = await service.createLineItems(orderTwo.id, [ + const [itemTwo] = await service.createOrderLineItems(orderTwo.id, [ { quantity: 2, unit_price: 200, @@ -1185,7 +1213,7 @@ moduleIntegrationTestRunner({ }, ]) - await service.createLineItemAdjustments([ + await service.createOrderLineItemAdjustments([ // item from order one { item_id: itemOne.id, @@ -1249,7 +1277,7 @@ moduleIntegrationTestRunner({ }, ]) - const [item] = await service.createLineItems(createdOrder.id, [ + const [item] = await service.createOrderLineItems(createdOrder.id, [ { quantity: 1, unit_price: 100, @@ -1257,7 +1285,7 @@ moduleIntegrationTestRunner({ }, ]) - const [adjustment] = await service.createLineItemAdjustments( + const [adjustment] = await service.createOrderLineItemAdjustments( createdOrder.id, [ { @@ -1269,9 +1297,9 @@ moduleIntegrationTestRunner({ expect(adjustment.item_id).toBe(item.id) - await service.deleteLineItemAdjustments(adjustment.id) + await service.deleteOrderLineItemAdjustments(adjustment.id) - const adjustments = await service.listLineItemAdjustments({ + const adjustments = await service.listOrderLineItemAdjustments({ item_id: item.id, }) @@ -1285,7 +1313,7 @@ moduleIntegrationTestRunner({ }, ]) - const [item] = await service.createLineItems(createdOrder.id, [ + const [item] = await service.createOrderLineItems(createdOrder.id, [ { quantity: 1, unit_price: 100, @@ -1293,7 +1321,7 @@ moduleIntegrationTestRunner({ }, ]) - const [adjustment] = await service.createLineItemAdjustments( + const [adjustment] = await service.createOrderLineItemAdjustments( createdOrder.id, [ { @@ -1305,9 +1333,9 @@ moduleIntegrationTestRunner({ expect(adjustment.item_id).toBe(item.id) - await service.deleteLineItemAdjustments({ item_id: item.id }) + await service.deleteOrderLineItemAdjustments({ item_id: item.id }) - const adjustments = await service.listLineItemAdjustments({ + const adjustments = await service.listOrderLineItemAdjustments({ item_id: item.id, }) @@ -1323,7 +1351,7 @@ moduleIntegrationTestRunner({ }, ]) - const [shippingMethodOne] = await service.createShippingMethods( + const [shippingMethodOne] = await service.createOrderShippingMethods( createdOrder.id, [ { @@ -1333,7 +1361,7 @@ moduleIntegrationTestRunner({ ] ) - const [shippingMethodTwo] = await service.createShippingMethods( + const [shippingMethodTwo] = await service.createOrderShippingMethods( createdOrder.id, [ { @@ -1343,7 +1371,7 @@ moduleIntegrationTestRunner({ ] ) - const adjustments = await service.setShippingMethodAdjustments( + const adjustments = await service.setOrderShippingMethodAdjustments( createdOrder.id, [ { @@ -1382,7 +1410,7 @@ moduleIntegrationTestRunner({ }, ]) - const [shippingMethodOne] = await service.createShippingMethods( + const [shippingMethodOne] = await service.createOrderShippingMethods( createdOrder.id, [ { @@ -1392,7 +1420,7 @@ moduleIntegrationTestRunner({ ] ) - const adjustments = await service.setShippingMethodAdjustments( + const adjustments = await service.setOrderShippingMethodAdjustments( createdOrder.id, [ { @@ -1413,7 +1441,7 @@ moduleIntegrationTestRunner({ ]) ) - await service.setShippingMethodAdjustments(createdOrder.id, [ + await service.setOrderShippingMethodAdjustments(createdOrder.id, [ { shipping_method_id: shippingMethodOne.id, amount: 50, @@ -1454,7 +1482,7 @@ moduleIntegrationTestRunner({ }, ]) - const [shippingMethodOne] = await service.createShippingMethods( + const [shippingMethodOne] = await service.createOrderShippingMethods( createdOrder.id, [ { @@ -1464,7 +1492,7 @@ moduleIntegrationTestRunner({ ] ) - const adjustments = await service.setShippingMethodAdjustments( + const adjustments = await service.setOrderShippingMethodAdjustments( createdOrder.id, [ { @@ -1485,7 +1513,7 @@ moduleIntegrationTestRunner({ ]) ) - await service.setShippingMethodAdjustments(createdOrder.id, []) + await service.setOrderShippingMethodAdjustments(createdOrder.id, []) const order = await service.retrieveOrder(createdOrder.id, { relations: ["shipping_methods.adjustments"], @@ -1511,7 +1539,7 @@ moduleIntegrationTestRunner({ }, ]) - const [shippingMethodOne] = await service.createShippingMethods( + const [shippingMethodOne] = await service.createOrderShippingMethods( createdOrder.id, [ { @@ -1521,7 +1549,7 @@ moduleIntegrationTestRunner({ ] ) - const adjustments = await service.setShippingMethodAdjustments( + const adjustments = await service.setOrderShippingMethodAdjustments( createdOrder.id, [ { @@ -1542,7 +1570,7 @@ moduleIntegrationTestRunner({ ]) ) - await service.setShippingMethodAdjustments(createdOrder.id, [ + await service.setOrderShippingMethodAdjustments(createdOrder.id, [ { id: adjustments[0].id, amount: 50, @@ -1584,7 +1612,7 @@ moduleIntegrationTestRunner({ }, ]) - const [shippingMethodOne] = await service.createShippingMethods( + const [shippingMethodOne] = await service.createOrderShippingMethods( createdOrder.id, [ { @@ -1594,16 +1622,17 @@ moduleIntegrationTestRunner({ ] ) - const adjustments = await service.createShippingMethodAdjustments( - createdOrder.id, - [ - { - shipping_method_id: shippingMethodOne.id, - amount: 100, - code: "FREE", - }, - ] - ) + const adjustments = + await service.createOrderShippingMethodAdjustments( + createdOrder.id, + [ + { + shipping_method_id: shippingMethodOne.id, + amount: 100, + code: "FREE", + }, + ] + ) expect(adjustments).toEqual( expect.arrayContaining([ @@ -1623,7 +1652,7 @@ moduleIntegrationTestRunner({ }, ]) - const [shippingMethodOne] = await service.createShippingMethods( + const [shippingMethodOne] = await service.createOrderShippingMethods( createdOrder.id, [ { @@ -1632,7 +1661,7 @@ moduleIntegrationTestRunner({ }, ] ) - const [shippingMethodTwo] = await service.createShippingMethods( + const [shippingMethodTwo] = await service.createOrderShippingMethods( createdOrder.id, [ { @@ -1642,21 +1671,22 @@ moduleIntegrationTestRunner({ ] ) - const adjustments = await service.createShippingMethodAdjustments( - createdOrder.id, - [ - { - shipping_method_id: shippingMethodOne.id, - amount: 100, - code: "FREE", - }, - { - shipping_method_id: shippingMethodTwo.id, - amount: 150, - code: "CODE-2", - }, - ] - ) + const adjustments = + await service.createOrderShippingMethodAdjustments( + createdOrder.id, + [ + { + shipping_method_id: shippingMethodOne.id, + amount: 100, + code: "FREE", + }, + { + shipping_method_id: shippingMethodTwo.id, + amount: 150, + code: "CODE-2", + }, + ] + ) expect(adjustments).toEqual( expect.arrayContaining([ @@ -1686,7 +1716,7 @@ moduleIntegrationTestRunner({ }, ]) - const [shippingMethodOne] = await service.createShippingMethods( + const [shippingMethodOne] = await service.createOrderShippingMethods( orderOne.id, [ { @@ -1695,7 +1725,7 @@ moduleIntegrationTestRunner({ }, ] ) - const [shippingMethodTwo] = await service.createShippingMethods( + const [shippingMethodTwo] = await service.createOrderShippingMethods( orderTwo.id, [ { @@ -1705,7 +1735,7 @@ moduleIntegrationTestRunner({ ] ) - await service.createShippingMethodAdjustments([ + await service.createOrderShippingMethodAdjustments([ // item from order one { shipping_method_id: shippingMethodOne.id, @@ -1720,16 +1750,12 @@ moduleIntegrationTestRunner({ }, ]) - const orderOneMethods = await ( - service as any - ).listOrderShippingMethods( + const orderOneMethods = await (service as any).listOrderShippings( { order_id: orderOne.id }, { relations: ["shipping_method.adjustments"] } ) - const orderTwoMethods = await ( - service as any - ).listOrderShippingMethods( + const orderTwoMethods = await (service as any).listOrderShippings( { order_id: orderTwo.id }, { relations: ["shipping_method.adjustments"] } ) @@ -1779,7 +1805,7 @@ moduleIntegrationTestRunner({ }, ]) - const [shippingMethodOne] = await service.createShippingMethods( + const [shippingMethodOne] = await service.createOrderShippingMethods( orderOne.id, [ { @@ -1790,7 +1816,7 @@ moduleIntegrationTestRunner({ ) const error = await service - .createShippingMethodAdjustments(orderTwo.id, [ + .createOrderShippingMethodAdjustments(orderTwo.id, [ { shipping_method_id: shippingMethodOne.id, amount: 100, @@ -1813,7 +1839,7 @@ moduleIntegrationTestRunner({ }, ]) - const [method] = await service.createShippingMethods( + const [method] = await service.createOrderShippingMethods( createdOrder.id, [ { @@ -1823,22 +1849,23 @@ moduleIntegrationTestRunner({ ] ) - const [adjustment] = await service.createShippingMethodAdjustments( - createdOrder.id, - [ - { - shipping_method_id: method.id, - amount: 50, - code: "50%", - }, - ] - ) + const [adjustment] = + await service.createOrderShippingMethodAdjustments( + createdOrder.id, + [ + { + shipping_method_id: method.id, + amount: 50, + code: "50%", + }, + ] + ) expect(adjustment.shipping_method_id).toBe(method.id) - await service.deleteShippingMethodAdjustments(adjustment.id) + await service.deleteOrderShippingMethodAdjustments(adjustment.id) - const adjustments = await service.listShippingMethodAdjustments({ + const adjustments = await service.listOrderShippingMethodAdjustments({ shipping_method_id: method.id, }) @@ -1852,7 +1879,7 @@ moduleIntegrationTestRunner({ }, ]) - const [shippingMethod] = await service.createShippingMethods( + const [shippingMethod] = await service.createOrderShippingMethods( createdOrder.id, [ { @@ -1862,24 +1889,25 @@ moduleIntegrationTestRunner({ ] ) - const [adjustment] = await service.createShippingMethodAdjustments( - createdOrder.id, - [ - { - shipping_method_id: shippingMethod.id, - amount: 50, - code: "50%", - }, - ] - ) + const [adjustment] = + await service.createOrderShippingMethodAdjustments( + createdOrder.id, + [ + { + shipping_method_id: shippingMethod.id, + amount: 50, + code: "50%", + }, + ] + ) expect(adjustment.shipping_method_id).toBe(shippingMethod.id) - await service.deleteShippingMethodAdjustments({ + await service.deleteOrderShippingMethodAdjustments({ shipping_method_id: shippingMethod.id, }) - const adjustments = await service.listShippingMethodAdjustments({ + const adjustments = await service.listOrderShippingMethodAdjustments({ shipping_method_id: shippingMethod.id, }) @@ -1887,7 +1915,7 @@ moduleIntegrationTestRunner({ }) }) - describe("setLineItemTaxLines", () => { + describe("setOrderLineItemTaxLines", () => { it("should set line item tax lines for an order", async () => { const [createdOrder] = await service.createOrders([ { @@ -1895,34 +1923,43 @@ moduleIntegrationTestRunner({ }, ]) - const [itemOne] = await service.createLineItems(createdOrder.id, [ - { - quantity: 1, - unit_price: 100, - title: "test", - }, - ]) + const [itemOne] = await service.createOrderLineItems( + createdOrder.id, + [ + { + quantity: 1, + unit_price: 100, + title: "test", + }, + ] + ) - const [itemTwo] = await service.createLineItems(createdOrder.id, [ - { - quantity: 2, - unit_price: 200, - title: "test-2", - }, - ]) + const [itemTwo] = await service.createOrderLineItems( + createdOrder.id, + [ + { + quantity: 2, + unit_price: 200, + title: "test-2", + }, + ] + ) - const taxLines = await service.setLineItemTaxLines(createdOrder.id, [ - { - item_id: itemOne.id, - rate: 20, - code: "TX", - }, - { - item_id: itemTwo.id, - rate: 20, - code: "TX", - }, - ]) + const taxLines = await service.setOrderLineItemTaxLines( + createdOrder.id, + [ + { + item_id: itemOne.id, + rate: 20, + code: "TX", + }, + { + item_id: itemTwo.id, + rate: 20, + code: "TX", + }, + ] + ) expect(taxLines).toEqual( expect.arrayContaining([ @@ -1947,21 +1984,27 @@ moduleIntegrationTestRunner({ }, ]) - const [itemOne] = await service.createLineItems(createdOrder.id, [ - { - quantity: 1, - unit_price: 100, - title: "test", - }, - ]) + const [itemOne] = await service.createOrderLineItems( + createdOrder.id, + [ + { + quantity: 1, + unit_price: 100, + title: "test", + }, + ] + ) - const taxLines = await service.setLineItemTaxLines(createdOrder.id, [ - { - item_id: itemOne.id, - rate: 20, - code: "TX", - }, - ]) + const taxLines = await service.setOrderLineItemTaxLines( + createdOrder.id, + [ + { + item_id: itemOne.id, + rate: 20, + code: "TX", + }, + ] + ) expect(taxLines).toEqual( expect.arrayContaining([ @@ -1973,7 +2016,7 @@ moduleIntegrationTestRunner({ ]) ) - await service.setLineItemTaxLines(createdOrder.id, [ + await service.setOrderLineItemTaxLines(createdOrder.id, [ { item_id: itemOne.id, rate: 25, @@ -2012,21 +2055,27 @@ moduleIntegrationTestRunner({ }, ]) - const [itemOne] = await service.createLineItems(createdOrder.id, [ - { - quantity: 1, - unit_price: 100, - title: "test", - }, - ]) + const [itemOne] = await service.createOrderLineItems( + createdOrder.id, + [ + { + quantity: 1, + unit_price: 100, + title: "test", + }, + ] + ) - const taxLines = await service.setLineItemTaxLines(createdOrder.id, [ - { - item_id: itemOne.id, - rate: 20, - code: "TX", - }, - ]) + const taxLines = await service.setOrderLineItemTaxLines( + createdOrder.id, + [ + { + item_id: itemOne.id, + rate: 20, + code: "TX", + }, + ] + ) expect(taxLines).toEqual( expect.arrayContaining([ @@ -2038,7 +2087,7 @@ moduleIntegrationTestRunner({ ]) ) - await service.setLineItemTaxLines(createdOrder.id, []) + await service.setOrderLineItemTaxLines(createdOrder.id, []) const order = await service.retrieveOrder(createdOrder.id, { relations: ["items.item.tax_lines"], @@ -2064,21 +2113,27 @@ moduleIntegrationTestRunner({ }, ]) - const [itemOne] = await service.createLineItems(createdOrder.id, [ - { - quantity: 1, - unit_price: 100, - title: "test", - }, - ]) + const [itemOne] = await service.createOrderLineItems( + createdOrder.id, + [ + { + quantity: 1, + unit_price: 100, + title: "test", + }, + ] + ) - const taxLines = await service.setLineItemTaxLines(createdOrder.id, [ - { - item_id: itemOne.id, - rate: 20, - code: "TX", - }, - ]) + const taxLines = await service.setOrderLineItemTaxLines( + createdOrder.id, + [ + { + item_id: itemOne.id, + rate: 20, + code: "TX", + }, + ] + ) expect(taxLines).toEqual( expect.arrayContaining([ @@ -2090,7 +2145,7 @@ moduleIntegrationTestRunner({ ]) ) - await service.setLineItemTaxLines(createdOrder.id, [ + await service.setOrderLineItemTaxLines(createdOrder.id, [ { id: taxLines[0].id, item_id: itemOne.id, @@ -2131,26 +2186,32 @@ moduleIntegrationTestRunner({ }, ]) - const [itemOne] = await service.createLineItems(createdOrder.id, [ - { - quantity: 1, - unit_price: 100, - title: "test", - }, - ]) + const [itemOne] = await service.createOrderLineItems( + createdOrder.id, + [ + { + quantity: 1, + unit_price: 100, + title: "test", + }, + ] + ) - const taxLines = await service.setLineItemTaxLines(createdOrder.id, [ - { - item_id: itemOne.id, - rate: 20, - code: "TX", - }, - { - item_id: itemOne.id, - rate: 25, - code: "TX", - }, - ]) + const taxLines = await service.setOrderLineItemTaxLines( + createdOrder.id, + [ + { + item_id: itemOne.id, + rate: 20, + code: "TX", + }, + { + item_id: itemOne.id, + rate: 25, + code: "TX", + }, + ] + ) expect(taxLines).toEqual( expect.arrayContaining([ @@ -2169,7 +2230,7 @@ moduleIntegrationTestRunner({ const taxLine = taxLines.find((tx) => tx.item_id === itemOne.id)! - await service.setLineItemTaxLines(createdOrder.id, [ + await service.setOrderLineItemTaxLines(createdOrder.id, [ // update { id: taxLine.id, @@ -2225,15 +2286,18 @@ moduleIntegrationTestRunner({ }, ]) - const [itemOne] = await service.createLineItems(createdOrder.id, [ - { - quantity: 1, - unit_price: 100, - title: "test", - }, - ]) + const [itemOne] = await service.createOrderLineItems( + createdOrder.id, + [ + { + quantity: 1, + unit_price: 100, + title: "test", + }, + ] + ) - const taxLines = await service.createLineItemTaxLines( + const taxLines = await service.createOrderLineItemTaxLines( createdOrder.id, [ { @@ -2262,22 +2326,28 @@ moduleIntegrationTestRunner({ }, ]) - const [itemOne] = await service.createLineItems(createdOrder.id, [ - { - quantity: 1, - unit_price: 100, - title: "test", - }, - ]) - const [itemTwo] = await service.createLineItems(createdOrder.id, [ - { - quantity: 2, - unit_price: 200, - title: "test-2", - }, - ]) + const [itemOne] = await service.createOrderLineItems( + createdOrder.id, + [ + { + quantity: 1, + unit_price: 100, + title: "test", + }, + ] + ) + const [itemTwo] = await service.createOrderLineItems( + createdOrder.id, + [ + { + quantity: 2, + unit_price: 200, + title: "test-2", + }, + ] + ) - const taxLines = await service.createLineItemTaxLines( + const taxLines = await service.createOrderLineItemTaxLines( createdOrder.id, [ { @@ -2321,14 +2391,14 @@ moduleIntegrationTestRunner({ }, ]) - const [itemOne] = await service.createLineItems(orderOne.id, [ + const [itemOne] = await service.createOrderLineItems(orderOne.id, [ { quantity: 1, unit_price: 100, title: "test", }, ]) - const [itemTwo] = await service.createLineItems(orderTwo.id, [ + const [itemTwo] = await service.createOrderLineItems(orderTwo.id, [ { quantity: 2, unit_price: 200, @@ -2336,7 +2406,7 @@ moduleIntegrationTestRunner({ }, ]) - await service.createLineItemTaxLines([ + await service.createOrderLineItemTaxLines([ // item from order one { item_id: itemOne.id, @@ -2400,7 +2470,7 @@ moduleIntegrationTestRunner({ }, ]) - const [item] = await service.createLineItems(createdOrder.id, [ + const [item] = await service.createOrderLineItems(createdOrder.id, [ { quantity: 1, unit_price: 100, @@ -2408,7 +2478,7 @@ moduleIntegrationTestRunner({ }, ]) - const [taxLine] = await service.createLineItemTaxLines( + const [taxLine] = await service.createOrderLineItemTaxLines( createdOrder.id, [ { @@ -2421,9 +2491,9 @@ moduleIntegrationTestRunner({ expect(taxLine.item_id).toBe(item.id) - await service.deleteLineItemTaxLines(taxLine.id) + await service.deleteOrderLineItemTaxLines(taxLine.id) - const taxLines = await service.listLineItemTaxLines({ + const taxLines = await service.listOrderLineItemTaxLines({ item_id: item.id, }) @@ -2437,7 +2507,7 @@ moduleIntegrationTestRunner({ }, ]) - const [item] = await service.createLineItems(createdOrder.id, [ + const [item] = await service.createOrderLineItems(createdOrder.id, [ { quantity: 1, unit_price: 100, @@ -2445,7 +2515,7 @@ moduleIntegrationTestRunner({ }, ]) - const [taxLine] = await service.createLineItemTaxLines( + const [taxLine] = await service.createOrderLineItemTaxLines( createdOrder.id, [ { @@ -2458,9 +2528,9 @@ moduleIntegrationTestRunner({ expect(taxLine.item_id).toBe(item.id) - await service.deleteLineItemTaxLines({ item_id: item.id }) + await service.deleteOrderLineItemTaxLines({ item_id: item.id }) - const taxLines = await service.listLineItemTaxLines({ + const taxLines = await service.listOrderLineItemTaxLines({ item_id: item.id, }) diff --git a/packages/modules/order/src/models/address.ts b/packages/modules/order/src/models/address.ts index f06d78b64c..970d3cda4b 100644 --- a/packages/modules/order/src/models/address.ts +++ b/packages/modules/order/src/models/address.ts @@ -20,7 +20,7 @@ const CustomerIdIndex = createPsqlIndexStatementHelper({ }) @Entity({ tableName: "order_address" }) -export default class Address { +export default class OrderAddress { [OptionalProps]: OptionalAddressProps @PrimaryKey({ columnType: "text" }) diff --git a/packages/modules/order/src/models/claim-item.ts b/packages/modules/order/src/models/claim-item.ts index 9a080876fd..b23240164a 100644 --- a/packages/modules/order/src/models/claim-item.ts +++ b/packages/modules/order/src/models/claim-item.ts @@ -21,7 +21,7 @@ import { } from "@mikro-orm/core" import Claim from "./claim" import OrderClaimItemImage from "./claim-item-image" -import LineItem from "./line-item" +import OrderLineItem from "./line-item" type OptionalLineItemProps = DAL.ModelDateColumns @@ -80,7 +80,7 @@ export default class OrderClaimItem { claim: Rel @ManyToOne({ - entity: () => LineItem, + entity: () => OrderLineItem, fieldName: "item_id", mapToPk: true, columnType: "text", @@ -88,10 +88,10 @@ export default class OrderClaimItem { @ItemIdIndex.MikroORMIndex() item_id: string - @ManyToOne(() => LineItem, { + @ManyToOne(() => OrderLineItem, { persist: false, }) - item: Rel + item: Rel @Property({ columnType: "boolean", default: false }) is_additional_item: boolean = false diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index 5b0e4b6306..ce7f010f56 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -25,9 +25,9 @@ import { } from "@mikro-orm/core" import ClaimItem from "./claim-item" import Order from "./order" -import OrderShippingMethod from "./order-shipping-method" +import OrderShipping from "./order-shipping-method" import Return from "./return" -import Transaction from "./transaction" +import OrderTransaction from "./transaction" type OptionalOrderClaimProps = DAL.ModelDateColumns @@ -123,19 +123,15 @@ export default class OrderClaim { }) claim_items = new Collection>(this) - @OneToMany( - () => OrderShippingMethod, - (shippingMethod) => shippingMethod.claim, - { - cascade: [Cascade.PERSIST], - } - ) - shipping_methods = new Collection>(this) - - @OneToMany(() => Transaction, (transaction) => transaction.claim, { + @OneToMany(() => OrderShipping, (shippingMethod) => shippingMethod.claim, { cascade: [Cascade.PERSIST], }) - transactions = new Collection(this) + shipping_methods = new Collection>(this) + + @OneToMany(() => OrderTransaction, (transaction) => transaction.claim, { + cascade: [Cascade.PERSIST], + }) + transactions = new Collection(this) @Property({ columnType: "text", nullable: true }) created_by: string | null = null diff --git a/packages/modules/order/src/models/exchange-item.ts b/packages/modules/order/src/models/exchange-item.ts index fd7aa7a8ca..1173170ac5 100644 --- a/packages/modules/order/src/models/exchange-item.ts +++ b/packages/modules/order/src/models/exchange-item.ts @@ -14,7 +14,7 @@ import { Property, } from "@mikro-orm/core" import Exchange from "./exchange" -import LineItem from "./line-item" +import OrderLineItem from "./line-item" type OptionalLineItemProps = DAL.ModelDateColumns @@ -64,7 +64,7 @@ export default class OrderExchangeItem { exchange: Exchange @ManyToOne({ - entity: () => LineItem, + entity: () => OrderLineItem, fieldName: "item_id", mapToPk: true, columnType: "text", @@ -72,10 +72,10 @@ export default class OrderExchangeItem { @ItemIdIndex.MikroORMIndex() item_id: string - @ManyToOne(() => LineItem, { + @ManyToOne(() => OrderLineItem, { persist: false, }) - item: LineItem + item: OrderLineItem @Property({ columnType: "text", nullable: true }) note: string diff --git a/packages/modules/order/src/models/exchange.ts b/packages/modules/order/src/models/exchange.ts index a2deba8668..7855296860 100644 --- a/packages/modules/order/src/models/exchange.ts +++ b/packages/modules/order/src/models/exchange.ts @@ -21,9 +21,9 @@ import { Property, Rel, } from "@mikro-orm/core" -import { OrderExchangeItem, Transaction } from "@models" +import { OrderExchangeItem, OrderTransaction } from "@models" import Order from "./order" -import OrderShippingMethod from "./order-shipping-method" +import OrderShipping from "./order-shipping-method" import Return from "./return" type OptionalOrderExchangeProps = DAL.ModelDateColumns @@ -115,19 +115,15 @@ export default class OrderExchange { }) additional_items = new Collection>(this) - @OneToMany( - () => OrderShippingMethod, - (shippingMethod) => shippingMethod.exchange, - { - cascade: [Cascade.PERSIST], - } - ) - shipping_methods = new Collection>(this) - - @OneToMany(() => Transaction, (transaction) => transaction.exchange, { + @OneToMany(() => OrderShipping, (shippingMethod) => shippingMethod.exchange, { cascade: [Cascade.PERSIST], }) - transactions = new Collection(this) + shipping_methods = new Collection>(this) + + @OneToMany(() => OrderTransaction, (transaction) => transaction.exchange, { + cascade: [Cascade.PERSIST], + }) + transactions = new Collection(this) @Property({ columnType: "text", nullable: true }) created_by: string | null = null diff --git a/packages/modules/order/src/models/index.ts b/packages/modules/order/src/models/index.ts index 68a91bbc68..8262fb98d1 100644 --- a/packages/modules/order/src/models/index.ts +++ b/packages/modules/order/src/models/index.ts @@ -1,22 +1,22 @@ -export { default as Address } from "./address" +export { default as OrderAddress } from "./address" export { default as OrderClaim } from "./claim" export { default as OrderClaimItem } from "./claim-item" export { default as OrderClaimItemImage } from "./claim-item-image" export { default as OrderExchange } from "./exchange" export { default as OrderExchangeItem } from "./exchange-item" -export { default as LineItem } from "./line-item" -export { default as LineItemAdjustment } from "./line-item-adjustment" -export { default as LineItemTaxLine } from "./line-item-tax-line" +export { default as OrderLineItem } from "./line-item" +export { default as OrderLineItemAdjustment } from "./line-item-adjustment" +export { default as OrderLineItemTaxLine } from "./line-item-tax-line" export { default as Order } from "./order" export { default as OrderChange } from "./order-change" export { default as OrderChangeAction } from "./order-change-action" export { default as OrderItem } from "./order-item" -export { default as OrderShippingMethod } from "./order-shipping-method" +export { default as OrderShipping } from "./order-shipping-method" export { default as OrderSummary } from "./order-summary" export { default as Return } from "./return" export { default as ReturnItem } from "./return-item" export { default as ReturnReason } from "./return-reason" -export { default as ShippingMethod } from "./shipping-method" -export { default as ShippingMethodAdjustment } from "./shipping-method-adjustment" -export { default as ShippingMethodTaxLine } from "./shipping-method-tax-line" -export { default as Transaction } from "./transaction" +export { default as OrderShippingMethod } from "./shipping-method" +export { default as OrderShippingMethodAdjustment } from "./shipping-method-adjustment" +export { default as OrderShippingMethodTaxLine } from "./shipping-method-tax-line" +export { default as OrderTransaction } from "./transaction" diff --git a/packages/modules/order/src/models/line-item-adjustment.ts b/packages/modules/order/src/models/line-item-adjustment.ts index 20e00de281..fe4e4cfb3f 100644 --- a/packages/modules/order/src/models/line-item-adjustment.ts +++ b/packages/modules/order/src/models/line-item-adjustment.ts @@ -4,7 +4,7 @@ import { } from "@medusajs/utils" import { BeforeCreate, Entity, ManyToOne, OnInit, Rel } from "@mikro-orm/core" import AdjustmentLine from "./adjustment-line" -import LineItem from "./line-item" +import OrderLineItem from "./line-item" const ItemIdIndex = createPsqlIndexStatementHelper({ tableName: "order_line_item_adjustment", @@ -12,14 +12,14 @@ const ItemIdIndex = createPsqlIndexStatementHelper({ }) @Entity({ tableName: "order_line_item_adjustment" }) -export default class LineItemAdjustment extends AdjustmentLine { - @ManyToOne(() => LineItem, { +export default class OrderLineItemAdjustment extends AdjustmentLine { + @ManyToOne(() => OrderLineItem, { persist: false, }) - item: Rel + item: Rel @ManyToOne({ - entity: () => LineItem, + entity: () => OrderLineItem, columnType: "text", fieldName: "item_id", onDelete: "cascade", diff --git a/packages/modules/order/src/models/line-item-tax-line.ts b/packages/modules/order/src/models/line-item-tax-line.ts index 6367caba37..b1ef83902a 100644 --- a/packages/modules/order/src/models/line-item-tax-line.ts +++ b/packages/modules/order/src/models/line-item-tax-line.ts @@ -10,7 +10,7 @@ import { OnInit, Rel, } from "@mikro-orm/core" -import LineItem from "./line-item" +import OrderLineItem from "./line-item" import TaxLine from "./tax-line" const ItemIdIndex = createPsqlIndexStatementHelper({ @@ -19,15 +19,15 @@ const ItemIdIndex = createPsqlIndexStatementHelper({ }) @Entity({ tableName: "order_line_item_tax_line" }) -export default class LineItemTaxLine extends TaxLine { - @ManyToOne(() => LineItem, { +export default class OrderLineItemTaxLine extends TaxLine { + @ManyToOne(() => OrderLineItem, { fieldName: "item_id", persist: false, }) - item: Rel + item: Rel @ManyToOne({ - entity: () => LineItem, + entity: () => OrderLineItem, columnType: "text", fieldName: "item_id", cascade: [Cascade.PERSIST, Cascade.REMOVE], diff --git a/packages/modules/order/src/models/line-item.ts b/packages/modules/order/src/models/line-item.ts index 8e0a456cb4..2e30fcd4db 100644 --- a/packages/modules/order/src/models/line-item.ts +++ b/packages/modules/order/src/models/line-item.ts @@ -19,8 +19,8 @@ import { Property, Rel, } from "@mikro-orm/core" -import LineItemAdjustment from "./line-item-adjustment" -import LineItemTaxLine from "./line-item-tax-line" +import OrderLineItemAdjustment from "./line-item-adjustment" +import OrderLineItemTaxLine from "./line-item-tax-line" type OptionalLineItemProps = DAL.ModelDateColumns @@ -44,7 +44,7 @@ const VariantIdIndex = createPsqlIndexStatementHelper({ @Entity({ tableName: "order_line_item" }) @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -export default class LineItem { +export default class OrderLineItem { [OptionalProps]?: OptionalLineItemProps @PrimaryKey({ columnType: "text" }) @@ -128,15 +128,15 @@ export default class LineItem { @Property({ columnType: "jsonb" }) raw_unit_price: BigNumberRawValue - @OneToMany(() => LineItemTaxLine, (taxLine) => taxLine.item, { + @OneToMany(() => OrderLineItemTaxLine, (taxLine) => taxLine.item, { cascade: [Cascade.PERSIST, "soft-remove" as Cascade], }) - tax_lines = new Collection>(this) + tax_lines = new Collection>(this) - @OneToMany(() => LineItemAdjustment, (adjustment) => adjustment.item, { + @OneToMany(() => OrderLineItemAdjustment, (adjustment) => adjustment.item, { cascade: [Cascade.PERSIST, "soft-remove" as Cascade], }) - adjustments = new Collection>(this) + adjustments = new Collection>(this) @Property({ columnType: "jsonb", nullable: true }) metadata: Record | null = null diff --git a/packages/modules/order/src/models/order-item.ts b/packages/modules/order/src/models/order-item.ts index 4284f34534..98009db9b2 100644 --- a/packages/modules/order/src/models/order-item.ts +++ b/packages/modules/order/src/models/order-item.ts @@ -15,7 +15,7 @@ import { Property, Rel, } from "@mikro-orm/core" -import LineItem from "./line-item" +import OrderLineItem from "./line-item" import Order from "./order" type OptionalLineItemProps = DAL.ModelDateColumns @@ -71,7 +71,7 @@ export default class OrderItem { version: number @ManyToOne({ - entity: () => LineItem, + entity: () => OrderLineItem, fieldName: "item_id", mapToPk: true, columnType: "text", @@ -79,10 +79,10 @@ export default class OrderItem { @ItemIdIndex.MikroORMIndex() item_id: string - @ManyToOne(() => LineItem, { + @ManyToOne(() => OrderLineItem, { persist: false, }) - item: Rel + item: Rel @MikroOrmBigNumberProperty() quantity: BigNumber | number diff --git a/packages/modules/order/src/models/order-shipping-method.ts b/packages/modules/order/src/models/order-shipping-method.ts index 0ac2642ffb..c2a468459c 100644 --- a/packages/modules/order/src/models/order-shipping-method.ts +++ b/packages/modules/order/src/models/order-shipping-method.ts @@ -17,7 +17,7 @@ import Claim from "./claim" import Exchange from "./exchange" import Order from "./order" import Return from "./return" -import ShippingMethod from "./shipping-method" +import OrderShippingMethod from "./shipping-method" type OptionalShippingMethodProps = DAL.ModelDateColumns @@ -65,7 +65,7 @@ const DeletedAtIndex = createPsqlIndexStatementHelper({ }) @Entity({ tableName }) -export default class OrderShippingMethod { +export default class OrderShipping { [OptionalProps]?: OptionalShippingMethodProps @PrimaryKey({ columnType: "text" }) @@ -138,7 +138,7 @@ export default class OrderShippingMethod { version: number @ManyToOne({ - entity: () => ShippingMethod, + entity: () => OrderShippingMethod, fieldName: "shipping_method_id", mapToPk: true, columnType: "text", @@ -146,10 +146,10 @@ export default class OrderShippingMethod { @ItemIdIndex.MikroORMIndex() shipping_method_id: string - @ManyToOne(() => ShippingMethod, { + @ManyToOne(() => OrderShippingMethod, { persist: false, }) - shipping_method: Rel + shipping_method: Rel @Property({ onCreate: () => new Date(), diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index 4e262f80dd..89141913c7 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -18,11 +18,11 @@ import { Property, Rel, } from "@mikro-orm/core" -import Address from "./address" +import OrderAddress from "./address" import OrderItem from "./order-item" -import OrderShippingMethod from "./order-shipping-method" +import OrderShipping from "./order-shipping-method" import OrderSummary from "./order-summary" -import Transaction from "./transaction" +import OrderTransaction from "./transaction" type OptionalOrderProps = | "shipping_address" @@ -142,24 +142,24 @@ export default class Order { shipping_address_id?: string | null @ManyToOne({ - entity: () => Address, + entity: () => OrderAddress, fieldName: "shipping_address_id", nullable: true, cascade: [Cascade.PERSIST], }) - shipping_address?: Rel
| null + shipping_address?: Rel | null @Property({ columnType: "text", nullable: true }) @BillingAddressIdIndex.MikroORMIndex() billing_address_id?: string | null @ManyToOne({ - entity: () => Address, + entity: () => OrderAddress, fieldName: "billing_address_id", nullable: true, cascade: [Cascade.PERSIST], }) - billing_address?: Rel
| null + billing_address?: Rel | null @Property({ columnType: "boolean", nullable: true }) no_notification: boolean | null = null @@ -177,19 +177,15 @@ export default class Order { }) items = new Collection>(this) - @OneToMany( - () => OrderShippingMethod, - (shippingMethod) => shippingMethod.order, - { - cascade: [Cascade.PERSIST], - } - ) - shipping_methods = new Collection>(this) - - @OneToMany(() => Transaction, (transaction) => transaction.order, { + @OneToMany(() => OrderShipping, (shippingMethod) => shippingMethod.order, { cascade: [Cascade.PERSIST], }) - transactions = new Collection>(this) + shipping_methods = new Collection>(this) + + @OneToMany(() => OrderTransaction, (transaction) => transaction.order, { + cascade: [Cascade.PERSIST], + }) + transactions = new Collection>(this) @Property({ onCreate: () => new Date(), diff --git a/packages/modules/order/src/models/return-item.ts b/packages/modules/order/src/models/return-item.ts index 864c4e1302..bc0b835c59 100644 --- a/packages/modules/order/src/models/return-item.ts +++ b/packages/modules/order/src/models/return-item.ts @@ -13,7 +13,7 @@ import { PrimaryKey, Property, } from "@mikro-orm/core" -import LineItem from "./line-item" +import OrderLineItem from "./line-item" import Return from "./return" import ReturnReason from "./return-reason" @@ -98,7 +98,7 @@ export default class ReturnItem { return: Return @ManyToOne({ - entity: () => LineItem, + entity: () => OrderLineItem, fieldName: "item_id", mapToPk: true, columnType: "text", @@ -106,10 +106,10 @@ export default class ReturnItem { @ItemIdIndex.MikroORMIndex() item_id: string - @ManyToOne(() => LineItem, { + @ManyToOne(() => OrderLineItem, { persist: false, }) - item: LineItem + item: OrderLineItem @Property({ columnType: "text", nullable: true }) note: string diff --git a/packages/modules/order/src/models/return.ts b/packages/modules/order/src/models/return.ts index 765e2ff40a..553c1d4b1a 100644 --- a/packages/modules/order/src/models/return.ts +++ b/packages/modules/order/src/models/return.ts @@ -23,11 +23,11 @@ import { Property, Rel, } from "@mikro-orm/core" -import { ReturnItem, Transaction } from "@models" +import { OrderTransaction, ReturnItem } from "@models" import Claim from "./claim" import Exchange from "./exchange" import Order from "./order" -import OrderShippingMethod from "./order-shipping-method" +import OrderShipping from "./order-shipping-method" type OptionalReturnProps = DAL.ModelDateColumns @@ -136,19 +136,15 @@ export default class Return { }) items = new Collection>(this) - @OneToMany( - () => OrderShippingMethod, - (shippingMethod) => shippingMethod.return, - { - cascade: [Cascade.PERSIST], - } - ) - shipping_methods = new Collection(this) - - @OneToMany(() => Transaction, (transaction) => transaction.return, { + @OneToMany(() => OrderShipping, (shippingMethod) => shippingMethod.return, { cascade: [Cascade.PERSIST], }) - transactions = new Collection(this) + shipping_methods = new Collection(this) + + @OneToMany(() => OrderTransaction, (transaction) => transaction.return, { + cascade: [Cascade.PERSIST], + }) + transactions = new Collection(this) @Property({ columnType: "text", nullable: true }) created_by: string | null = null diff --git a/packages/modules/order/src/models/shipping-method-adjustment.ts b/packages/modules/order/src/models/shipping-method-adjustment.ts index 86810b0993..09babe559e 100644 --- a/packages/modules/order/src/models/shipping-method-adjustment.ts +++ b/packages/modules/order/src/models/shipping-method-adjustment.ts @@ -4,7 +4,7 @@ import { } from "@medusajs/utils" import { BeforeCreate, Entity, ManyToOne, OnInit, Rel } from "@mikro-orm/core" import AdjustmentLine from "./adjustment-line" -import ShippingMethod from "./shipping-method" +import OrderShippingMethod from "./shipping-method" const ShippingMethodIdIdIndex = createPsqlIndexStatementHelper({ tableName: "order_shipping_method_adjustment", @@ -12,14 +12,14 @@ const ShippingMethodIdIdIndex = createPsqlIndexStatementHelper({ }) @Entity({ tableName: "order_shipping_method_adjustment" }) -export default class ShippingMethodAdjustment extends AdjustmentLine { - @ManyToOne(() => ShippingMethod, { +export default class OrderShippingMethodAdjustment extends AdjustmentLine { + @ManyToOne(() => OrderShippingMethod, { persist: false, }) - shipping_method: Rel + shipping_method: Rel @ManyToOne({ - entity: () => ShippingMethod, + entity: () => OrderShippingMethod, columnType: "text", fieldName: "shipping_method_id", mapToPk: true, diff --git a/packages/modules/order/src/models/shipping-method-tax-line.ts b/packages/modules/order/src/models/shipping-method-tax-line.ts index 5d958a850f..86938a7daf 100644 --- a/packages/modules/order/src/models/shipping-method-tax-line.ts +++ b/packages/modules/order/src/models/shipping-method-tax-line.ts @@ -3,7 +3,7 @@ import { generateEntityId, } from "@medusajs/utils" import { BeforeCreate, Entity, ManyToOne, OnInit, Rel } from "@mikro-orm/core" -import ShippingMethod from "./shipping-method" +import OrderShippingMethod from "./shipping-method" import TaxLine from "./tax-line" const ShippingMethodIdIdIndex = createPsqlIndexStatementHelper({ @@ -12,14 +12,14 @@ const ShippingMethodIdIdIndex = createPsqlIndexStatementHelper({ }) @Entity({ tableName: "order_shipping_method_tax_line" }) -export default class ShippingMethodTaxLine extends TaxLine { - @ManyToOne(() => ShippingMethod, { +export default class OrderShippingMethodTaxLine extends TaxLine { + @ManyToOne(() => OrderShippingMethod, { persist: false, }) - shipping_method: Rel + shipping_method: Rel @ManyToOne({ - entity: () => ShippingMethod, + entity: () => OrderShippingMethod, fieldName: "shipping_method_id", columnType: "text", mapToPk: true, diff --git a/packages/modules/order/src/models/shipping-method.ts b/packages/modules/order/src/models/shipping-method.ts index 339aef974f..ffa05ab8aa 100644 --- a/packages/modules/order/src/models/shipping-method.ts +++ b/packages/modules/order/src/models/shipping-method.ts @@ -18,8 +18,8 @@ import { Property, Rel, } from "@mikro-orm/core" -import ShippingMethodAdjustment from "./shipping-method-adjustment" -import ShippingMethodTaxLine from "./shipping-method-tax-line" +import OrderShippingMethodAdjustment from "./shipping-method-adjustment" +import OrderShippingMethodTaxLine from "./shipping-method-tax-line" const DeletedAtIndex = createPsqlIndexStatementHelper({ tableName: "order_shipping_method", @@ -35,7 +35,7 @@ const ShippingOptionIdIndex = createPsqlIndexStatementHelper({ @Entity({ tableName: "order_shipping_method" }) @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) -export default class ShippingMethod { +export default class OrderShippingMethod { @PrimaryKey({ columnType: "text" }) id: string @@ -68,22 +68,22 @@ export default class ShippingMethod { metadata: Record | null = null @OneToMany( - () => ShippingMethodTaxLine, + () => OrderShippingMethodTaxLine, (taxLine) => taxLine.shipping_method, { cascade: [Cascade.PERSIST, "soft-remove" as Cascade], } ) - tax_lines = new Collection>(this) + tax_lines = new Collection>(this) @OneToMany( - () => ShippingMethodAdjustment, + () => OrderShippingMethodAdjustment, (adjustment) => adjustment.shipping_method, { cascade: [Cascade.PERSIST, "soft-remove" as Cascade], } ) - adjustments = new Collection>(this) + adjustments = new Collection>(this) @Property({ onCreate: () => new Date(), diff --git a/packages/modules/order/src/models/transaction.ts b/packages/modules/order/src/models/transaction.ts index 6210902b77..4c47a55f98 100644 --- a/packages/modules/order/src/models/transaction.ts +++ b/packages/modules/order/src/models/transaction.ts @@ -77,7 +77,7 @@ const OrderIdVersionIndex = createPsqlIndexStatementHelper({ @Entity({ tableName }) @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) @OrderIdVersionIndex.MikroORMIndex() -export default class Transaction { +export default class OrderTransaction { [OptionalProps]?: OptionalLineItemProps @PrimaryKey({ columnType: "text" }) diff --git a/packages/modules/order/src/services/actions/create-claim.ts b/packages/modules/order/src/services/actions/create-claim.ts index ec76608419..6978477c04 100644 --- a/packages/modules/order/src/services/actions/create-claim.ts +++ b/packages/modules/order/src/services/actions/create-claim.ts @@ -154,7 +154,7 @@ async function processAdditionalItems( } }) - const createItems = await service.lineItemService_.create( + const createItems = await service.orderLineItemService_.create( itemsToAdd, sharedContext ) @@ -192,7 +192,7 @@ async function processShippingMethods( let shippingMethodId if (!isString(shippingMethod)) { - const methods = await service.createShippingMethods( + const methods = await service.createOrderShippingMethods( [ { ...shippingMethod, @@ -207,7 +207,7 @@ async function processShippingMethods( shippingMethodId = shippingMethod } - const method = await service.retrieveShippingMethod( + const method = await service.retrieveOrderShippingMethod( shippingMethodId, { relations: ["tax_lines", "adjustments"] }, sharedContext @@ -243,7 +243,7 @@ async function processReturnShipping( let returnShippingMethodId if (!isString(data.return_shipping)) { - const methods = await service.createShippingMethods( + const methods = await service.createOrderShippingMethods( [ { ...data.return_shipping, @@ -259,7 +259,7 @@ async function processReturnShipping( returnShippingMethodId = data.return_shipping } - const method = await service.retrieveShippingMethod( + const method = await service.retrieveOrderShippingMethod( returnShippingMethodId, { relations: ["tax_lines", "adjustments"] }, sharedContext diff --git a/packages/modules/order/src/services/actions/create-exchange.ts b/packages/modules/order/src/services/actions/create-exchange.ts index 39cb8477f1..d27a980310 100644 --- a/packages/modules/order/src/services/actions/create-exchange.ts +++ b/packages/modules/order/src/services/actions/create-exchange.ts @@ -121,7 +121,7 @@ async function processAdditionalItems( } }) - const createItems = await service.lineItemService_.create( + const createItems = await service.orderLineItemService_.create( itemsToAdd, sharedContext ) @@ -161,7 +161,7 @@ async function processShippingMethods( let shippingMethodId if (!isString(shippingMethod)) { - const methods = await service.createShippingMethods( + const methods = await service.createOrderShippingMethods( [ { ...shippingMethod, @@ -176,7 +176,7 @@ async function processShippingMethods( shippingMethodId = shippingMethod } - const method = await service.retrieveShippingMethod( + const method = await service.retrieveOrderShippingMethod( shippingMethodId, { relations: ["tax_lines", "adjustments"] }, sharedContext @@ -207,7 +207,7 @@ async function processReturnShipping( let returnShippingMethodId if (!isString(data.return_shipping)) { - const methods = await service.createShippingMethods( + const methods = await service.createOrderShippingMethods( [ { ...data.return_shipping, @@ -223,7 +223,7 @@ async function processReturnShipping( returnShippingMethodId = data.return_shipping } - const method = await service.retrieveShippingMethod( + const method = await service.retrieveOrderShippingMethod( returnShippingMethodId, { relations: ["tax_lines", "adjustments"] }, sharedContext diff --git a/packages/modules/order/src/services/actions/create-return.ts b/packages/modules/order/src/services/actions/create-return.ts index 2433520a13..ec1b542dcf 100644 --- a/packages/modules/order/src/services/actions/create-return.ts +++ b/packages/modules/order/src/services/actions/create-return.ts @@ -64,7 +64,7 @@ async function processShippingMethod( } if (!isString(data.shipping_method)) { - const methods = await service.createShippingMethods( + const methods = await service.createOrderShippingMethods( [ { ...data.shipping_method, @@ -79,7 +79,7 @@ async function processShippingMethod( shippingMethodId = data.shipping_method } - const method = await service.retrieveShippingMethod( + const method = await service.retrieveOrderShippingMethod( shippingMethodId, { relations: ["tax_lines", "adjustments"] }, sharedContext diff --git a/packages/modules/order/src/services/order-module-service.ts b/packages/modules/order/src/services/order-module-service.ts index 9a08e36a11..96fd2b1e86 100644 --- a/packages/modules/order/src/services/order-module-service.ts +++ b/packages/modules/order/src/services/order-module-service.ts @@ -4,11 +4,12 @@ import { DAL, FilterableOrderReturnReasonProps, FindConfig, - InternalModuleDeclaration, IOrderModuleService, + InternalModuleDeclaration, ModulesSdkTypes, OrderDTO, OrderReturnReasonDTO, + OrderShippingMethodDTO, OrderTypes, RestoreReturn, SoftDeleteReturn, @@ -17,30 +18,27 @@ import { } from "@medusajs/types" import { BigNumber, - createRawPropertiesFromBigNumber, DecorateCartLikeInputDTO, - decorateCartTotals, - deduplicate, InjectManager, InjectTransactionManager, - isDefined, - isObject, - isString, MathBN, MedusaContext, MedusaError, ModulesSdkUtils, OrderChangeStatus, OrderStatus, + createRawPropertiesFromBigNumber, + decorateCartTotals, + deduplicate, + isDefined, + isObject, + isString, promiseAll, transformPropertiesToBigNumber, } from "@medusajs/utils" import { - Address, - LineItem, - LineItemAdjustment, - LineItemTaxLine, Order, + OrderAddress, OrderChange, OrderChangeAction, OrderClaim, @@ -49,15 +47,18 @@ import { OrderExchange, OrderExchangeItem, OrderItem, + OrderLineItem, + OrderLineItemAdjustment, + OrderLineItemTaxLine, + OrderShipping, OrderShippingMethod, + OrderShippingMethodAdjustment, + OrderShippingMethodTaxLine, OrderSummary, + OrderTransaction, Return, ReturnItem, ReturnReason, - ShippingMethod, - ShippingMethodAdjustment, - ShippingMethodTaxLine, - Transaction, } from "@models" import { CreateOrderChangeDTO, @@ -73,8 +74,8 @@ import { } from "@types" import { UpdateReturnReasonDTO } from "src/types/return-reason" import { - applyChangesToOrder, ApplyOrderChangeDTO, + applyChangesToOrder, calculateOrderChange, formatOrder, } from "../utils" @@ -84,19 +85,19 @@ import OrderService from "./order-service" type InjectedDependencies = { baseRepository: DAL.RepositoryService orderService: OrderService - addressService: ModulesSdkTypes.IMedusaInternalService - lineItemService: ModulesSdkTypes.IMedusaInternalService - shippingMethodAdjustmentService: ModulesSdkTypes.IMedusaInternalService - shippingMethodService: ModulesSdkTypes.IMedusaInternalService - lineItemAdjustmentService: ModulesSdkTypes.IMedusaInternalService - lineItemTaxLineService: ModulesSdkTypes.IMedusaInternalService - shippingMethodTaxLineService: ModulesSdkTypes.IMedusaInternalService - transactionService: ModulesSdkTypes.IMedusaInternalService + orderAddressService: ModulesSdkTypes.IMedusaInternalService + orderLineItemService: ModulesSdkTypes.IMedusaInternalService + orderShippingMethodAdjustmentService: ModulesSdkTypes.IMedusaInternalService + orderShippingMethodService: ModulesSdkTypes.IMedusaInternalService + orderLineItemAdjustmentService: ModulesSdkTypes.IMedusaInternalService + orderLineItemTaxLineService: ModulesSdkTypes.IMedusaInternalService + orderShippingMethodTaxLineService: ModulesSdkTypes.IMedusaInternalService + orderTransactionService: ModulesSdkTypes.IMedusaInternalService orderChangeService: ModulesSdkTypes.IMedusaInternalService orderChangeActionService: ModulesSdkTypes.IMedusaInternalService orderItemService: ModulesSdkTypes.IMedusaInternalService orderSummaryService: ModulesSdkTypes.IMedusaInternalService - orderShippingMethodService: ModulesSdkTypes.IMedusaInternalService + orderShippingService: ModulesSdkTypes.IMedusaInternalService returnReasonService: ModulesSdkTypes.IMedusaInternalService returnService: ModulesSdkTypes.IMedusaInternalService returnItemService: ModulesSdkTypes.IMedusaInternalService @@ -106,19 +107,19 @@ type InjectedDependencies = { const generateMethodForModels = { Order, - Address, - LineItem, - LineItemAdjustment, - LineItemTaxLine, - ShippingMethod, - ShippingMethodAdjustment, - ShippingMethodTaxLine, - Transaction, + OrderAddress, + OrderLineItem, + OrderLineItemAdjustment, + OrderLineItemTaxLine, + OrderShippingMethod, + OrderShippingMethodAdjustment, + OrderShippingMethodTaxLine, + OrderTransaction, OrderChange, OrderChangeAction, OrderItem, OrderSummary, - OrderShippingMethod, + OrderShipping, ReturnReason, Return, ReturnItem, @@ -132,19 +133,19 @@ const generateMethodForModels = { // TODO: rm template args here, keep it for later to not collide with carlos work at least as little as possible export default class OrderModuleService< TOrder extends Order = Order, - TAddress extends Address = Address, - TLineItem extends LineItem = LineItem, - TLineItemAdjustment extends LineItemAdjustment = LineItemAdjustment, - TLineItemTaxLine extends LineItemTaxLine = LineItemTaxLine, - TShippingMethodAdjustment extends ShippingMethodAdjustment = ShippingMethodAdjustment, - TShippingMethodTaxLine extends ShippingMethodTaxLine = ShippingMethodTaxLine, - TShippingMethod extends ShippingMethod = ShippingMethod, - TTransaction extends Transaction = Transaction, + TAddress extends OrderAddress = OrderAddress, + TLineItem extends OrderLineItem = OrderLineItem, + TLineItemAdjustment extends OrderLineItemAdjustment = OrderLineItemAdjustment, + TLineItemTaxLine extends OrderLineItemTaxLine = OrderLineItemTaxLine, + TOrderShippingMethodAdjustment extends OrderShippingMethodAdjustment = OrderShippingMethodAdjustment, + TOrderShippingMethodTaxLine extends OrderShippingMethodTaxLine = OrderShippingMethodTaxLine, + TOrderShippingMethod extends OrderShippingMethod = OrderShippingMethod, + TOrderTransaction extends OrderTransaction = OrderTransaction, TOrderChange extends OrderChange = OrderChange, TOrderChangeAction extends OrderChangeAction = OrderChangeAction, TOrderItem extends OrderItem = OrderItem, TOrderSummary extends OrderSummary = OrderSummary, - TOrderShippingMethod extends OrderShippingMethod = OrderShippingMethod, + TOrderShipping extends OrderShipping = OrderShipping, TReturnReason extends ReturnReason = ReturnReason, TReturn extends Return = Return, TReturnItem extends ReturnItem = ReturnItem, @@ -156,22 +157,24 @@ export default class OrderModuleService< > extends ModulesSdkUtils.MedusaService<{ Order: { dto: OrderTypes.OrderDTO } - Address: { dto: OrderTypes.OrderAddressDTO } - LineItem: { dto: OrderTypes.OrderLineItemDTO } - LineItemAdjustment: { dto: OrderTypes.OrderLineItemAdjustmentDTO } - LineItemTaxLine: { dto: OrderTypes.OrderLineItemTaxLineDTO } - ShippingMethod: { dto: OrderTypes.OrderShippingMethodDTO } - ShippingMethodAdjustment: { + OrderAddress: { dto: OrderTypes.OrderAddressDTO } + OrderLineItem: { dto: OrderTypes.OrderLineItemDTO } + OrderLineItemAdjustment: { dto: OrderTypes.OrderLineItemAdjustmentDTO } + OrderLineItemTaxLine: { dto: OrderTypes.OrderLineItemTaxLineDTO } + OrderShippingMethod: { dto: OrderShippingMethodDTO } + OrderShippingMethodAdjustment: { dto: OrderTypes.OrderShippingMethodAdjustmentDTO } - ShippingMethodTaxLine: { dto: OrderTypes.OrderShippingMethodTaxLineDTO } + OrderShippingMethodTaxLine: { + dto: OrderTypes.OrderShippingMethodTaxLineDTO + } + OrderShipping: { dto: any } OrderChange: { dto: OrderTypes.OrderChangeDTO } OrderChangeAction: { dto: OrderTypes.OrderChangeActionDTO } OrderItem: { dto: OrderTypes.OrderItemDTO } - OrderShippingMethod: { dto: OrderShippingMethod } ReturnReason: { dto: OrderTypes.OrderReturnReasonDTO } OrderSummary: { dto: OrderTypes.OrderSummaryDTO } - Transaction: { dto: OrderTypes.OrderTransactionDTO } + OrderTransaction: { dto: OrderTypes.OrderTransactionDTO } Return: { dto: OrderTypes.ReturnDTO } ReturnItem: { dto: OrderTypes.OrderReturnItemDTO } OrderClaim: { dto: OrderTypes.OrderClaimDTO } @@ -184,19 +187,19 @@ export default class OrderModuleService< { protected baseRepository_: DAL.RepositoryService protected orderService_: OrderService - protected addressService_: ModulesSdkTypes.IMedusaInternalService - protected lineItemService_: ModulesSdkTypes.IMedusaInternalService - protected shippingMethodAdjustmentService_: ModulesSdkTypes.IMedusaInternalService - protected shippingMethodService_: ModulesSdkTypes.IMedusaInternalService - protected lineItemAdjustmentService_: ModulesSdkTypes.IMedusaInternalService - protected lineItemTaxLineService_: ModulesSdkTypes.IMedusaInternalService - protected shippingMethodTaxLineService_: ModulesSdkTypes.IMedusaInternalService - protected transactionService_: ModulesSdkTypes.IMedusaInternalService + protected orderAddressService_: ModulesSdkTypes.IMedusaInternalService + protected orderLineItemService_: ModulesSdkTypes.IMedusaInternalService + protected orderShippingMethodAdjustmentService_: ModulesSdkTypes.IMedusaInternalService + protected orderShippingMethodService_: ModulesSdkTypes.IMedusaInternalService + protected orderLineItemAdjustmentService_: ModulesSdkTypes.IMedusaInternalService + protected orderLineItemTaxLineService_: ModulesSdkTypes.IMedusaInternalService + protected orderShippingMethodTaxLineService_: ModulesSdkTypes.IMedusaInternalService + protected orderTransactionService_: ModulesSdkTypes.IMedusaInternalService protected orderChangeService_: ModulesSdkTypes.IMedusaInternalService protected orderChangeActionService_: ModulesSdkTypes.IMedusaInternalService protected orderItemService_: ModulesSdkTypes.IMedusaInternalService protected orderSummaryService_: ModulesSdkTypes.IMedusaInternalService - protected orderShippingMethodService_: ModulesSdkTypes.IMedusaInternalService + protected orderShippingService_: ModulesSdkTypes.IMedusaInternalService protected returnReasonService_: ModulesSdkTypes.IMedusaInternalService protected returnService_: ModulesSdkTypes.IMedusaInternalService protected returnItemService_: ModulesSdkTypes.IMedusaInternalService @@ -210,19 +213,19 @@ export default class OrderModuleService< { baseRepository, orderService, - addressService, - lineItemService, - shippingMethodAdjustmentService, - shippingMethodService, - lineItemAdjustmentService, - shippingMethodTaxLineService, - lineItemTaxLineService, - transactionService, + orderAddressService, + orderLineItemService, + orderShippingMethodAdjustmentService, + orderShippingMethodService, + orderLineItemAdjustmentService, + orderShippingMethodTaxLineService, + orderLineItemTaxLineService, + orderTransactionService, orderChangeService, orderChangeActionService, orderItemService, orderSummaryService, - orderShippingMethodService, + orderShippingService, returnReasonService, returnService, returnItemService, @@ -236,19 +239,20 @@ export default class OrderModuleService< this.baseRepository_ = baseRepository this.orderService_ = orderService - this.addressService_ = addressService - this.lineItemService_ = lineItemService - this.shippingMethodAdjustmentService_ = shippingMethodAdjustmentService - this.shippingMethodService_ = shippingMethodService - this.lineItemAdjustmentService_ = lineItemAdjustmentService - this.shippingMethodTaxLineService_ = shippingMethodTaxLineService - this.lineItemTaxLineService_ = lineItemTaxLineService - this.transactionService_ = transactionService + this.orderAddressService_ = orderAddressService + this.orderLineItemService_ = orderLineItemService + this.orderShippingMethodAdjustmentService_ = + orderShippingMethodAdjustmentService + this.orderShippingMethodService_ = orderShippingMethodService + this.orderLineItemAdjustmentService_ = orderLineItemAdjustmentService + this.orderShippingMethodTaxLineService_ = orderShippingMethodTaxLineService + this.orderLineItemTaxLineService_ = orderLineItemTaxLineService + this.orderTransactionService_ = orderTransactionService this.orderChangeService_ = orderChangeService this.orderChangeActionService_ = orderChangeActionService this.orderItemService_ = orderItemService this.orderSummaryService_ = orderSummaryService - this.orderShippingMethodService_ = orderShippingMethodService + this.orderShippingService_ = orderShippingService this.returnReasonService_ = returnReasonService this.returnService_ = returnService this.returnItemService_ = returnItemService @@ -671,7 +675,7 @@ export default class OrderModuleService< } if (lineItemsToCreate.length) { - await this.createLineItemsBulk_(lineItemsToCreate, sharedContext) + await this.createOrderLineItemsBulk_(lineItemsToCreate, sharedContext) } return createdOrders @@ -755,20 +759,20 @@ export default class OrderModuleService< } // @ts-ignore - createLineItems( + createOrderLineItems( data: OrderTypes.CreateOrderLineItemForOrderDTO ): Promise - createLineItems( + createOrderLineItems( data: OrderTypes.CreateOrderLineItemForOrderDTO[] ): Promise - createLineItems( + createOrderLineItems( orderId: string, items: OrderTypes.CreateOrderLineItemDTO[], sharedContext?: Context ): Promise @InjectManager("baseRepository_") - async createLineItems( + async createOrderLineItems( orderIdOrData: | string | OrderTypes.CreateOrderLineItemForOrderDTO[] @@ -778,9 +782,9 @@ export default class OrderModuleService< | OrderTypes.CreateOrderLineItemDTO, @MedusaContext() sharedContext: Context = {} ): Promise { - let items: LineItem[] = [] + let items: OrderLineItem[] = [] if (isString(orderIdOrData)) { - items = await this.createLineItems_( + items = await this.createOrderLineItems_( orderIdOrData, data as OrderTypes.CreateOrderLineItemDTO[], sharedContext @@ -808,7 +812,7 @@ export default class OrderModuleService< } }) - items = await this.createLineItemsBulk_(lineItems, sharedContext) + items = await this.createOrderLineItemsBulk_(lineItems, sharedContext) } return await this.baseRepository_.serialize( @@ -820,11 +824,11 @@ export default class OrderModuleService< } @InjectTransactionManager("baseRepository_") - protected async createLineItems_( + protected async createOrderLineItems_( orderId: string, items: OrderTypes.CreateOrderLineItemDTO[], @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise { const order = await this.retrieveOrder( orderId, { select: ["id", "version"] }, @@ -839,17 +843,20 @@ export default class OrderModuleService< } }) - return await this.createLineItemsBulk_(toUpdate, sharedContext) + return await this.createOrderLineItemsBulk_(toUpdate, sharedContext) } @InjectTransactionManager("baseRepository_") - protected async createLineItemsBulk_( + protected async createOrderLineItemsBulk_( data: CreateOrderLineItemDTO[], @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise { const orderItemToCreate: CreateOrderItemDTO[] = [] - const lineItems = await this.lineItemService_.create(data, sharedContext) + const lineItems = await this.orderLineItemService_.create( + data, + sharedContext + ) for (let i = 0; i < lineItems.length; i++) { const item = lineItems[i] @@ -873,22 +880,22 @@ export default class OrderModuleService< } // @ts-ignore - updateLineItems( + updateOrderLineItems( data: OrderTypes.UpdateOrderLineItemWithSelectorDTO[] ): Promise - updateLineItems( + updateOrderLineItems( selector: Partial, data: OrderTypes.UpdateOrderLineItemDTO, sharedContext?: Context ): Promise - updateLineItems( + updateOrderLineItems( lineItemId: string, data: Partial, sharedContext?: Context ): Promise @InjectManager("baseRepository_") - async updateLineItems( + async updateOrderLineItems( lineItemIdOrDataOrSelector: | string | OrderTypes.UpdateOrderLineItemWithSelectorDTO[] @@ -898,9 +905,9 @@ export default class OrderModuleService< | Partial, @MedusaContext() sharedContext: Context = {} ): Promise { - let items: LineItem[] = [] + let items: OrderLineItem[] = [] if (isString(lineItemIdOrDataOrSelector)) { - const item = await this.updateLineItem_( + const item = await this.updateOrderLineItem_( lineItemIdOrDataOrSelector, data as Partial, sharedContext @@ -923,7 +930,10 @@ export default class OrderModuleService< } as OrderTypes.UpdateOrderLineItemWithSelectorDTO, ] - items = await this.updateLineItemsWithSelector_(toUpdate, sharedContext) + items = await this.updateOrderLineItemsWithSelector_( + toUpdate, + sharedContext + ) return await this.baseRepository_.serialize( items, @@ -934,12 +944,12 @@ export default class OrderModuleService< } @InjectTransactionManager("baseRepository_") - protected async updateLineItem_( + protected async updateOrderLineItem_( lineItemId: string, data: Partial, @MedusaContext() sharedContext: Context = {} - ): Promise { - const [item] = await this.lineItemService_.update( + ): Promise { + const [item] = await this.orderLineItemService_.update( [{ id: lineItemId, ...data }], sharedContext ) @@ -960,14 +970,18 @@ export default class OrderModuleService< } @InjectTransactionManager("baseRepository_") - protected async updateLineItemsWithSelector_( + protected async updateOrderLineItemsWithSelector_( updates: OrderTypes.UpdateOrderLineItemWithSelectorDTO[], @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise { let toUpdate: UpdateOrderLineItemDTO[] = [] const detailsToUpdate: UpdateOrderItemWithSelectorDTO[] = [] for (const { selector, data } of updates) { - const items = await this.listLineItems({ ...selector }, {}, sharedContext) + const items = await this.listOrderLineItems( + { ...selector }, + {}, + sharedContext + ) items.forEach((item) => { toUpdate.push({ @@ -988,7 +1002,7 @@ export default class OrderModuleService< await this.updateOrderItemWithSelector_(detailsToUpdate, sharedContext) } - return await this.lineItemService_.update(toUpdate, sharedContext) + return await this.orderLineItemService_.update(toUpdate, sharedContext) } updateOrderItem( @@ -1087,94 +1101,20 @@ export default class OrderModuleService< } // @ts-ignore - async createAddresses( - data: OrderTypes.CreateOrderAddressDTO, - sharedContext?: Context - ): Promise - async createAddresses( - data: OrderTypes.CreateOrderAddressDTO[], - sharedContext?: Context - ): Promise - - @InjectManager("baseRepository_") - async createAddresses( - data: OrderTypes.CreateOrderAddressDTO[] | OrderTypes.CreateOrderAddressDTO, - @MedusaContext() sharedContext: Context = {} - ): Promise { - const input = Array.isArray(data) ? data : [data] - const addresses = await this.createAddresses_(input, sharedContext) - - const result = await this.listAddresses( - { id: addresses.map((p) => p.id) }, - {}, - sharedContext - ) - - return (Array.isArray(data) ? result : result[0]) as - | OrderTypes.OrderAddressDTO - | OrderTypes.OrderAddressDTO[] - } - - @InjectTransactionManager("baseRepository_") - protected async createAddresses_( - data: OrderTypes.CreateOrderAddressDTO[], - @MedusaContext() sharedContext: Context = {} - ) { - return await this.addressService_.create(data, sharedContext) - } - - // @ts-ignore - async updateAddresses( - data: OrderTypes.UpdateOrderAddressDTO, - sharedContext?: Context - ): Promise - async updateAddresses( - data: OrderTypes.UpdateOrderAddressDTO[], - sharedContext?: Context - ): Promise - - @InjectManager("baseRepository_") - async updateAddresses( - data: OrderTypes.UpdateOrderAddressDTO[] | OrderTypes.UpdateOrderAddressDTO, - @MedusaContext() sharedContext: Context = {} - ): Promise { - const input = Array.isArray(data) ? data : [data] - const addresses = await this.updateAddresses_(input, sharedContext) - - const result = await this.listAddresses( - { id: addresses.map((p) => p.id) }, - {}, - sharedContext - ) - - return (Array.isArray(data) ? result : result[0]) as - | OrderTypes.OrderAddressDTO - | OrderTypes.OrderAddressDTO[] - } - - @InjectTransactionManager("baseRepository_") - protected async updateAddresses_( - data: OrderTypes.UpdateOrderAddressDTO[], - @MedusaContext() sharedContext: Context = {} - ) { - return await this.addressService_.update(data, sharedContext) - } - - // @ts-ignore - async createShippingMethods( + async createOrderShippingMethods( data: OrderTypes.CreateOrderShippingMethodDTO ): Promise - async createShippingMethods( + async createOrderShippingMethods( data: OrderTypes.CreateOrderShippingMethodDTO[] ): Promise - async createShippingMethods( + async createOrderShippingMethods( orderId: string, methods: OrderTypes.CreateOrderShippingMethodDTO[], sharedContext?: Context ): Promise @InjectManager("baseRepository_") - async createShippingMethods( + async createOrderShippingMethods( orderIdOrData: | string | OrderTypes.CreateOrderShippingMethodDTO[] @@ -1184,9 +1124,9 @@ export default class OrderModuleService< ): Promise< OrderTypes.OrderShippingMethodDTO[] | OrderTypes.OrderShippingMethodDTO > { - let methods: ShippingMethod[] + let methods: OrderShippingMethod[] if (isString(orderIdOrData)) { - methods = await this.createShippingMethods_( + methods = await this.createOrderShippingMethods_( orderIdOrData, data!, sharedContext @@ -1218,7 +1158,7 @@ export default class OrderModuleService< } }) - methods = await this.createShippingMethodsBulk_( + methods = await this.createOrderShippingMethodsBulk_( orderShippingMethodData as any, sharedContext ) @@ -1230,11 +1170,11 @@ export default class OrderModuleService< } @InjectTransactionManager("baseRepository_") - protected async createShippingMethods_( + protected async createOrderShippingMethods_( orderId: string, data: CreateOrderShippingMethodDTO[], @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise { const order = await this.retrieveOrder( orderId, { select: ["id", "version"] }, @@ -1252,19 +1192,19 @@ export default class OrderModuleService< } }) - return await this.createShippingMethodsBulk_(methods, sharedContext) + return await this.createOrderShippingMethodsBulk_(methods, sharedContext) } @InjectTransactionManager("baseRepository_") - protected async createShippingMethodsBulk_( + protected async createOrderShippingMethodsBulk_( data: { shipping_method: OrderTypes.CreateOrderShippingMethodDTO order_id: string version: number }[], @MedusaContext() sharedContext: Context = {} - ): Promise { - const sm = await this.orderShippingMethodService_.create( + ): Promise { + const sm = await this.orderShippingService_.create( data as unknown as CreateOrderShippingMethodDTO[], sharedContext ) @@ -1274,12 +1214,12 @@ export default class OrderModuleService< @InjectManager("baseRepository_") // @ts-ignore - async softDeleteShippingMethods( + async softDeleteOrderShippingMethods( ids: string | object | string[] | object[], config?: SoftDeleteReturn, @MedusaContext() sharedContext?: Context ): Promise | void> { - const rel = await super.listOrderShippingMethods( + const rel = await super.listOrderShippings( { shipping_method_id: ids, }, @@ -1288,15 +1228,11 @@ export default class OrderModuleService< }, sharedContext ) - const orderShippingMethodIds = rel.map((r) => r.id) + const orderShippingIds = rel.map((r) => r.id) const [returned] = await promiseAll([ - super.softDeleteShippingMethods(ids, config, sharedContext), - super.softDeleteOrderShippingMethods( - orderShippingMethodIds, - config, - sharedContext - ), + super.softDeleteOrderShippingMethods(ids, config, sharedContext), + super.softDeleteOrderShippings(orderShippingIds, config, sharedContext), ]) return returned @@ -1304,49 +1240,45 @@ export default class OrderModuleService< @InjectManager("baseRepository_") // @ts-ignore - async restoreShippingMethods( - transactionIds: string | object | string[] | object[], + async restoreOrderShippingMethods( + ids: string | object | string[] | object[], config?: RestoreReturn, @MedusaContext() sharedContext?: Context ): Promise | void> { - const rel = await super.listOrderShippingMethods( + const rel = await super.listOrderShippings( { - shipping_method_id: transactionIds, + shipping_method_id: ids, }, { select: ["id"], }, sharedContext ) - const orderShippingMethodIds = rel.map((r) => r.id) + const shippingIds = rel.map((r) => r.id) const [returned] = await promiseAll([ - super.restoreShippingMethods(transactionIds, config, sharedContext), - super.restoreOrderShippingMethods( - orderShippingMethodIds, - config, - sharedContext - ), + super.restoreOrderShippingMethods(ids, config, sharedContext), + super.restoreOrderShippings(shippingIds, config, sharedContext), ]) return returned } // @ts-ignore - async createLineItemAdjustments( + async createOrderLineItemAdjustments( adjustments: OrderTypes.CreateOrderLineItemAdjustmentDTO[] ): Promise - async createLineItemAdjustments( + async createOrderLineItemAdjustments( adjustment: OrderTypes.CreateOrderLineItemAdjustmentDTO ): Promise - async createLineItemAdjustments( + async createOrderLineItemAdjustments( orderId: string, adjustments: OrderTypes.CreateOrderLineItemAdjustmentDTO[], sharedContext?: Context ): Promise @InjectTransactionManager("baseRepository_") - async createLineItemAdjustments( + async createOrderLineItemAdjustments( orderIdOrData: | string | OrderTypes.CreateOrderLineItemAdjustmentDTO[] @@ -1354,7 +1286,7 @@ export default class OrderModuleService< adjustments?: OrderTypes.CreateOrderLineItemAdjustmentDTO[], @MedusaContext() sharedContext: Context = {} ): Promise { - let addedAdjustments: LineItemAdjustment[] = [] + let addedAdjustments: OrderLineItemAdjustment[] = [] if (isString(orderIdOrData)) { const order = await this.retrieveOrder( orderIdOrData, @@ -1373,7 +1305,7 @@ export default class OrderModuleService< } } - addedAdjustments = await this.lineItemAdjustmentService_.create( + addedAdjustments = await this.orderLineItemAdjustmentService_.create( adjustments as OrderTypes.CreateOrderLineItemAdjustmentDTO[], sharedContext ) @@ -1382,7 +1314,7 @@ export default class OrderModuleService< ? orderIdOrData : [orderIdOrData] - addedAdjustments = await this.lineItemAdjustmentService_.create( + addedAdjustments = await this.orderLineItemAdjustmentService_.create( data as OrderTypes.CreateOrderLineItemAdjustmentDTO[], sharedContext ) @@ -1396,7 +1328,7 @@ export default class OrderModuleService< } @InjectTransactionManager("baseRepository_") - async setLineItemAdjustments( + async setOrderLineItemAdjustments( orderId: string, adjustments: ( | OrderTypes.CreateOrderLineItemAdjustmentDTO @@ -1431,10 +1363,10 @@ export default class OrderModuleService< }) if (toDelete.length) { - await this.lineItemAdjustmentService_.delete(toDelete, sharedContext) + await this.orderLineItemAdjustmentService_.delete(toDelete, sharedContext) } - let result = await this.lineItemAdjustmentService_.upsert( + let result = await this.orderLineItemAdjustmentService_.upsert( adjustments, sharedContext ) @@ -1447,7 +1379,7 @@ export default class OrderModuleService< } @InjectTransactionManager("baseRepository_") - async setShippingMethodAdjustments( + async setOrderShippingMethodAdjustments( orderId: string, adjustments: ( | OrderTypes.CreateOrderShippingMethodAdjustmentDTO @@ -1484,13 +1416,13 @@ export default class OrderModuleService< }) if (toDelete.length) { - await this.shippingMethodAdjustmentService_.delete( + await this.orderShippingMethodAdjustmentService_.delete( toDelete, sharedContext ) } - const result = await this.shippingMethodAdjustmentService_.upsert( + const result = await this.orderShippingMethodAdjustmentService_.upsert( adjustments, sharedContext ) @@ -1503,20 +1435,20 @@ export default class OrderModuleService< } // @ts-ignore - async createShippingMethodAdjustments( + async createOrderShippingMethodAdjustments( adjustments: OrderTypes.CreateOrderShippingMethodAdjustmentDTO[] ): Promise - async createShippingMethodAdjustments( + async createOrderShippingMethodAdjustments( adjustment: OrderTypes.CreateOrderShippingMethodAdjustmentDTO ): Promise - async createShippingMethodAdjustments( + async createOrderShippingMethodAdjustments( orderId: string, adjustments: OrderTypes.CreateOrderShippingMethodAdjustmentDTO[], sharedContext?: Context ): Promise @InjectTransactionManager("baseRepository_") - async createShippingMethodAdjustments( + async createOrderShippingMethodAdjustments( orderIdOrData: | string | OrderTypes.CreateOrderShippingMethodAdjustmentDTO[] @@ -1527,7 +1459,7 @@ export default class OrderModuleService< | OrderTypes.OrderShippingMethodAdjustmentDTO[] | OrderTypes.OrderShippingMethodAdjustmentDTO > { - let addedAdjustments: ShippingMethodAdjustment[] = [] + let addedAdjustments: OrderShippingMethodAdjustment[] = [] if (isString(orderIdOrData)) { const order = await this.retrieveOrder( orderIdOrData, @@ -1546,19 +1478,21 @@ export default class OrderModuleService< } } - addedAdjustments = await this.shippingMethodAdjustmentService_.create( - adjustments as OrderTypes.CreateOrderShippingMethodAdjustmentDTO[], - sharedContext - ) + addedAdjustments = + await this.orderShippingMethodAdjustmentService_.create( + adjustments as OrderTypes.CreateOrderShippingMethodAdjustmentDTO[], + sharedContext + ) } else { const data = Array.isArray(orderIdOrData) ? orderIdOrData : [orderIdOrData] - addedAdjustments = await this.shippingMethodAdjustmentService_.create( - data as OrderTypes.CreateOrderShippingMethodAdjustmentDTO[], - sharedContext - ) + addedAdjustments = + await this.orderShippingMethodAdjustmentService_.create( + data as OrderTypes.CreateOrderShippingMethodAdjustmentDTO[], + sharedContext + ) } if (isObject(orderIdOrData)) { @@ -1578,13 +1512,13 @@ export default class OrderModuleService< } // @ts-ignore - createLineItemTaxLines( + createOrderLineItemTaxLines( taxLines: OrderTypes.CreateOrderLineItemTaxLineDTO[] ): Promise - createLineItemTaxLines( + createOrderLineItemTaxLines( taxLine: OrderTypes.CreateOrderLineItemTaxLineDTO ): Promise - createLineItemTaxLines( + createOrderLineItemTaxLines( orderId: string, taxLines: | OrderTypes.CreateOrderLineItemTaxLineDTO[] @@ -1593,7 +1527,7 @@ export default class OrderModuleService< ): Promise @InjectTransactionManager("baseRepository_") - async createLineItemTaxLines( + async createOrderLineItemTaxLines( orderIdOrData: | string | OrderTypes.CreateOrderLineItemTaxLineDTO[] @@ -1605,11 +1539,11 @@ export default class OrderModuleService< ): Promise< OrderTypes.OrderLineItemTaxLineDTO[] | OrderTypes.OrderLineItemTaxLineDTO > { - let addedTaxLines: LineItemTaxLine[] + let addedTaxLines: OrderLineItemTaxLine[] if (isString(orderIdOrData)) { const lines = Array.isArray(taxLines) ? taxLines : [taxLines] - addedTaxLines = await this.lineItemTaxLineService_.create( + addedTaxLines = await this.orderLineItemTaxLineService_.create( lines as CreateOrderLineItemTaxLineDTO[], sharedContext ) @@ -1618,7 +1552,7 @@ export default class OrderModuleService< ? orderIdOrData : [orderIdOrData] - addedTaxLines = await this.lineItemTaxLineService_.create( + addedTaxLines = await this.orderLineItemTaxLineService_.create( data as CreateOrderLineItemTaxLineDTO[], sharedContext ) @@ -1638,7 +1572,7 @@ export default class OrderModuleService< } @InjectTransactionManager("baseRepository_") - async setLineItemTaxLines( + async setOrderLineItemTaxLines( orderId: string, taxLines: ( | OrderTypes.CreateOrderLineItemTaxLineDTO @@ -1673,10 +1607,10 @@ export default class OrderModuleService< }) if (toDelete.length) { - await this.lineItemTaxLineService_.delete(toDelete, sharedContext) + await this.orderLineItemTaxLineService_.delete(toDelete, sharedContext) } - const result = await this.lineItemTaxLineService_.upsert( + const result = await this.orderLineItemTaxLineService_.upsert( taxLines as UpdateOrderLineItemTaxLineDTO[], sharedContext ) @@ -1689,13 +1623,13 @@ export default class OrderModuleService< } // @ts-ignore - createShippingMethodTaxLines( + createOrderShippingMethodTaxLines( taxLines: OrderTypes.CreateOrderShippingMethodTaxLineDTO[] ): Promise - createShippingMethodTaxLines( + createOrderShippingMethodTaxLines( taxLine: OrderTypes.CreateOrderShippingMethodTaxLineDTO ): Promise - createShippingMethodTaxLines( + createOrderShippingMethodTaxLines( orderId: string, taxLines: | OrderTypes.CreateOrderShippingMethodTaxLineDTO[] @@ -1704,7 +1638,7 @@ export default class OrderModuleService< ): Promise @InjectTransactionManager("baseRepository_") - async createShippingMethodTaxLines( + async createOrderShippingMethodTaxLines( orderIdOrData: | string | OrderTypes.CreateOrderShippingMethodTaxLineDTO[] @@ -1717,16 +1651,16 @@ export default class OrderModuleService< | OrderTypes.OrderShippingMethodTaxLineDTO[] | OrderTypes.OrderShippingMethodTaxLineDTO > { - let addedTaxLines: ShippingMethodTaxLine[] + let addedTaxLines: OrderShippingMethodTaxLine[] if (isString(orderIdOrData)) { const lines = Array.isArray(taxLines) ? taxLines : [taxLines] - addedTaxLines = await this.shippingMethodTaxLineService_.create( + addedTaxLines = await this.orderShippingMethodTaxLineService_.create( lines as CreateOrderShippingMethodTaxLineDTO[], sharedContext ) } else { - addedTaxLines = await this.shippingMethodTaxLineService_.create( + addedTaxLines = await this.orderShippingMethodTaxLineService_.create( taxLines as CreateOrderShippingMethodTaxLineDTO[], sharedContext ) @@ -1748,7 +1682,7 @@ export default class OrderModuleService< } @InjectTransactionManager("baseRepository_") - async setShippingMethodTaxLines( + async setOrderShippingMethodTaxLines( orderId: string, taxLines: ( | OrderTypes.CreateOrderShippingMethodTaxLineDTO @@ -1784,10 +1718,13 @@ export default class OrderModuleService< }) if (toDelete.length) { - await this.shippingMethodTaxLineService_.delete(toDelete, sharedContext) + await this.orderShippingMethodTaxLineService_.delete( + toDelete, + sharedContext + ) } - const result = await this.shippingMethodTaxLineService_.upsert( + const result = await this.orderShippingMethodTaxLineService_.upsert( taxLines as UpdateOrderShippingMethodTaxLineDTO[], sharedContext ) @@ -2059,7 +1996,7 @@ export default class OrderModuleService< } if (Object.keys(addedItems).length > 0) { - const addedItemDetails = await this.listLineItems( + const addedItemDetails = await this.listOrderLineItems( { id: Object.keys(addedItems) }, { relations: ["adjustments", "tax_lines"], @@ -2092,7 +2029,7 @@ export default class OrderModuleService< } if (Object.keys(addedShippingMethods).length > 0) { - const addedShippingDetails = await this.listShippingMethods( + const addedShippingDetails = await this.listOrderShippingMethods( { id: Object.keys(addedShippingMethods) }, { relations: ["adjustments", "tax_lines"], @@ -2415,8 +2352,8 @@ export default class OrderModuleService< await this.orderItemService_.softDelete(orderItemIds, sharedContext) - // Shipping Methods - const orderShippingMethods = await this.orderShippingMethodService_.list( + // Order Shipping + const orderShippings = await this.orderShippingService_.list( { order_id: order.id, version: currentVersion, @@ -2424,14 +2361,9 @@ export default class OrderModuleService< { select: ["id", "version"] }, sharedContext ) - const orderShippingMethodIds = orderShippingMethods.map( - (summary) => summary.id - ) + const orderShippingIds = orderShippings.map((sh) => sh.id) - await this.orderShippingMethodService_.softDelete( - orderShippingMethodIds, - sharedContext - ) + await this.orderShippingService_.softDelete(orderShippingIds, sharedContext) // Order await this.orderService_.update( @@ -2701,7 +2633,7 @@ export default class OrderModuleService< ? this.orderSummaryService_.upsert(summariesToUpsert, sharedContext) : null, shippingMethodsToUpsert.length - ? this.orderShippingMethodService_.upsert( + ? this.orderShippingService_.upsert( shippingMethodsToUpsert, sharedContext ) @@ -2714,18 +2646,18 @@ export default class OrderModuleService< } } - async addTransactions( + async addOrderTransactions( transactionData: OrderTypes.CreateOrderTransactionDTO, sharedContext?: Context ): Promise - async addTransactions( + async addOrderTransactions( transactionData: OrderTypes.CreateOrderTransactionDTO[], sharedContext?: Context ): Promise @InjectManager("baseRepository_") - async addTransactions( + async addOrderTransactions( transactionData: | OrderTypes.CreateOrderTransactionDTO | OrderTypes.CreateOrderTransactionDTO[], @@ -2756,7 +2688,10 @@ export default class OrderModuleService< } } - const created = await this.transactionService_.create(data, sharedContext) + const created = await this.orderTransactionService_.create( + data, + sharedContext + ) await this.updateOrderPaidRefundableAmount_(created, false, sharedContext) @@ -2770,7 +2705,7 @@ export default class OrderModuleService< @InjectManager("baseRepository_") // @ts-ignore - async deleteTransactions( + async deleteOrderTransactions( transactionIds: string | object | string[] | object[], @MedusaContext() sharedContext?: Context ): Promise { @@ -2778,7 +2713,7 @@ export default class OrderModuleService< ? transactionIds : [transactionIds] - const transactions = await super.listTransactions( + const transactions = await super.listOrderTransactions( { id: data, }, @@ -2788,7 +2723,7 @@ export default class OrderModuleService< sharedContext ) - await this.transactionService_.delete(data, sharedContext) + await this.orderTransactionService_.delete(data, sharedContext) await this.updateOrderPaidRefundableAmount_( transactions, @@ -2799,12 +2734,12 @@ export default class OrderModuleService< @InjectManager("baseRepository_") // @ts-ignore - async softDeleteTransactions( + async softDeleteOrderTransactions( transactionIds: string | object | string[] | object[], config?: SoftDeleteReturn, @MedusaContext() sharedContext?: Context ): Promise | void> { - const transactions = await super.listTransactions( + const transactions = await super.listOrderTransactions( { id: transactionIds, }, @@ -2814,7 +2749,7 @@ export default class OrderModuleService< sharedContext ) - const returned = await super.softDeleteTransactions( + const returned = await super.softDeleteOrderTransactions( transactionIds, config, sharedContext @@ -2831,12 +2766,12 @@ export default class OrderModuleService< @InjectManager("baseRepository_") // @ts-ignore - async restoreTransactions( + async restoreOrderTransactions( transactionIds: string | object | string[] | object[], config?: RestoreReturn, @MedusaContext() sharedContext?: Context ): Promise | void> { - const transactions = await super.listTransactions( + const transactions = await super.listOrderTransactions( { id: transactionIds, }, @@ -2847,7 +2782,7 @@ export default class OrderModuleService< sharedContext ) - const returned = await super.restoreTransactions( + const returned = await super.restoreOrderTransactions( transactionIds as string[], config, sharedContext