From 5ae3a0c9523358499b0879a54371a2528683a6e2 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" Date: Sat, 21 Dec 2024 10:02:11 -0300 Subject: [PATCH] order --- packages/core/types/src/dml/index.ts | 1 - packages/core/utils/src/dml/entity.ts | 14 ++------------ .../integration-tests/__tests__/order-claim.ts | 2 +- .../integration-tests/__tests__/order-return.ts | 2 +- packages/modules/order/src/models/address.ts | 1 - packages/modules/order/src/models/claim-item.ts | 1 - packages/modules/order/src/models/claim.ts | 7 +------ packages/modules/order/src/models/exchange-item.ts | 1 - .../order/src/models/line-item-adjustment.ts | 1 - .../modules/order/src/models/line-item-tax-line.ts | 1 - .../order/src/models/order-change-action.ts | 11 ----------- packages/modules/order/src/models/order-change.ts | 5 +---- packages/modules/order/src/models/order-item.ts | 14 ++++---------- .../order/src/models/order-shipping-method.ts | 1 - packages/modules/order/src/models/order-summary.ts | 1 - packages/modules/order/src/models/order.ts | 1 - packages/modules/order/src/models/return-item.ts | 1 - .../order/src/models/shipping-method-adjustment.ts | 1 - .../order/src/models/shipping-method-tax-line.ts | 1 - .../order/src/services/order-module-service.ts | 8 ++++++-- .../order/src/utils/base-repository-find.ts | 13 ++++++++----- 21 files changed, 24 insertions(+), 64 deletions(-) diff --git a/packages/core/types/src/dml/index.ts b/packages/core/types/src/dml/index.ts index 99d5344493174..3f25730a070ef 100644 --- a/packages/core/types/src/dml/index.ts +++ b/packages/core/types/src/dml/index.ts @@ -15,7 +15,6 @@ export type IDmlEntityConfig = | { name?: string tableName: string - disableSoftDeleteFilter?: boolean } export type InferDmlEntityNameFromConfig = diff --git a/packages/core/utils/src/dml/entity.ts b/packages/core/utils/src/dml/entity.ts index fe3b62c06695b..0db09781da485 100644 --- a/packages/core/utils/src/dml/entity.ts +++ b/packages/core/utils/src/dml/entity.ts @@ -26,11 +26,9 @@ function extractNameAndTableName( const result = { name: "", tableName: "", - disableSoftDeleteFilter: false, } as { name: InferDmlEntityNameFromConfig tableName: string - disableSoftDeleteFilter: boolean } if (isString(nameOrConfig)) { @@ -58,8 +56,6 @@ function extractNameAndTableName( toCamelCase(name) ) as InferDmlEntityNameFromConfig result.tableName = nameOrConfig.tableName - result.disableSoftDeleteFilter = - nameOrConfig.disableSoftDeleteFilter ?? false } return result @@ -81,19 +77,15 @@ export class DmlEntity< readonly #tableName: string #cascades: EntityCascades = {} - #params: Record + #indexes: EntityIndex[] = [] #checks: CheckConstraint[] = [] constructor(nameOrConfig: TConfig, schema: Schema) { - const { name, tableName, disableSoftDeleteFilter } = - extractNameAndTableName(nameOrConfig) + const { name, tableName } = extractNameAndTableName(nameOrConfig) this.schema = schema this.name = name this.#tableName = tableName - this.#params = { - disableSoftDeleteFilter, - } } /** @@ -116,7 +108,6 @@ export class DmlEntity< schema: DMLSchema cascades: EntityCascades indexes: EntityIndex[] - params: Record checks: CheckConstraint[] } { return { @@ -125,7 +116,6 @@ export class DmlEntity< schema: this.schema, cascades: this.#cascades, indexes: this.#indexes, - params: this.#params, checks: this.#checks, } } diff --git a/packages/modules/order/integration-tests/__tests__/order-claim.ts b/packages/modules/order/integration-tests/__tests__/order-claim.ts index 98be3664d4779..a7d1992d1b57a 100644 --- a/packages/modules/order/integration-tests/__tests__/order-claim.ts +++ b/packages/modules/order/integration-tests/__tests__/order-claim.ts @@ -103,7 +103,7 @@ moduleIntegrationTestRunner({ customer_id: "joe", } as CreateOrderDTO - it.only("should claim an item and add two new items to the order", async function () { + it("should claim an item and add two new items to the order", async function () { const createdOrder = await service.createOrders(input) createdOrder.items = createdOrder.items!.sort((a, b) => a.title.localeCompare(b.title) diff --git a/packages/modules/order/integration-tests/__tests__/order-return.ts b/packages/modules/order/integration-tests/__tests__/order-return.ts index 8d8ffbac083b2..d1e7961dae7d9 100644 --- a/packages/modules/order/integration-tests/__tests__/order-return.ts +++ b/packages/modules/order/integration-tests/__tests__/order-return.ts @@ -627,7 +627,7 @@ moduleIntegrationTestRunner({ "items.detail.return_received_quantity", "shipping_methods.id", ], - relations: ["items", "items.detail"], + relations: ["items", "items.detail", "shipping_methods"], }) serializedOrder = JSON.parse(JSON.stringify(getOrder)) diff --git a/packages/modules/order/src/models/address.ts b/packages/modules/order/src/models/address.ts index b186380e3e6b1..69a9571b4090a 100644 --- a/packages/modules/order/src/models/address.ts +++ b/packages/modules/order/src/models/address.ts @@ -4,7 +4,6 @@ const _OrderAddress = model .define( { tableName: "order_address", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "ordaddr" }).primaryKey(), diff --git a/packages/modules/order/src/models/claim-item.ts b/packages/modules/order/src/models/claim-item.ts index a636b2cd0dc93..b2ce81348fdbb 100644 --- a/packages/modules/order/src/models/claim-item.ts +++ b/packages/modules/order/src/models/claim-item.ts @@ -7,7 +7,6 @@ const _OrderClaimItem = model .define( { tableName: "order_claim_item", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "claitem" }).primaryKey(), diff --git a/packages/modules/order/src/models/claim.ts b/packages/modules/order/src/models/claim.ts index cfc93f8e09954..8d0552ca0806f 100644 --- a/packages/modules/order/src/models/claim.ts +++ b/packages/modules/order/src/models/claim.ts @@ -52,12 +52,7 @@ const _OrderClaim = model ), }) .cascades({ - delete: [ - "additional_items", - "claim_items", - "shipping_methods", - "transactions", - ], + delete: ["additional_items", "claim_items", "transactions"], }) .indexes([ { diff --git a/packages/modules/order/src/models/exchange-item.ts b/packages/modules/order/src/models/exchange-item.ts index b286a4fca26c5..adbc18dd506e9 100644 --- a/packages/modules/order/src/models/exchange-item.ts +++ b/packages/modules/order/src/models/exchange-item.ts @@ -6,7 +6,6 @@ const _OrderExchangeItem = model .define( { tableName: "order_exchange_item", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "oexcitem" }).primaryKey(), diff --git a/packages/modules/order/src/models/line-item-adjustment.ts b/packages/modules/order/src/models/line-item-adjustment.ts index 3e25c07a010e2..6b1ecc0cb6171 100644 --- a/packages/modules/order/src/models/line-item-adjustment.ts +++ b/packages/modules/order/src/models/line-item-adjustment.ts @@ -5,7 +5,6 @@ const _OrderLineItemAdjustment = model .define( { tableName: "order_line_item_adjustment", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "ordliadj" }).primaryKey(), 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 9c6cba59dd437..b8f43729796c8 100644 --- a/packages/modules/order/src/models/line-item-tax-line.ts +++ b/packages/modules/order/src/models/line-item-tax-line.ts @@ -5,7 +5,6 @@ const _OrderLineItemTaxLine = model .define( { tableName: "order_line_item_tax_line", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "ordlitxl" }).primaryKey(), diff --git a/packages/modules/order/src/models/order-change-action.ts b/packages/modules/order/src/models/order-change-action.ts index c9c68a50cfc06..34cb83b73a699 100644 --- a/packages/modules/order/src/models/order-change-action.ts +++ b/packages/modules/order/src/models/order-change-action.ts @@ -46,17 +46,6 @@ const _OrderChangeAction = model }) .nullable(), }) - /* - .hooks({ - creating: (entity: any) => { - entity.order_id ??= entity.order_change?.order_id ?? null - entity.return_id ??= entity.order_change?.return_id ?? null - entity.claim_id ??= entity.order_change?.claim_id ?? null - entity.exchange_id ??= entity.order_change?.exchange_id ?? null - entity.version ??= entity.order_change?.version ?? null - }, - }) - */ .indexes([ { name: "IDX_order_change_action_order_change_id", diff --git a/packages/modules/order/src/models/order-change.ts b/packages/modules/order/src/models/order-change.ts index 20260b8ec25ab..910b747714161 100644 --- a/packages/modules/order/src/models/order-change.ts +++ b/packages/modules/order/src/models/order-change.ts @@ -49,10 +49,7 @@ const _OrderChange = model }) .nullable(), actions: model.hasMany<() => typeof OrderChangeAction>( - () => OrderChangeAction, - { - mappedBy: "order_change", - } + () => OrderChangeAction ), }) .cascades({ diff --git a/packages/modules/order/src/models/order-item.ts b/packages/modules/order/src/models/order-item.ts index 0a29a6f292c5a..0e9c604150300 100644 --- a/packages/modules/order/src/models/order-item.ts +++ b/packages/modules/order/src/models/order-item.ts @@ -7,7 +7,6 @@ const _OrderItem = model .define( { tableName: "order_item", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "orditem" }).primaryKey(), @@ -26,17 +25,12 @@ const _OrderItem = model order: model.belongsTo<() => typeof Order>(() => Order, { mappedBy: "items", }), - item: model - .hasOne<() => typeof OrderLineItem>(() => OrderLineItem, { - mappedBy: undefined, - foreignKey: true, - }) - .nullable(), + item: model.hasOne<() => typeof OrderLineItem>(() => OrderLineItem, { + mappedBy: undefined, + foreignKey: true, + }), } ) - .cascades({ - delete: ["item"], - }) .indexes([ { name: "IDX_order_item_order_id", diff --git a/packages/modules/order/src/models/order-shipping-method.ts b/packages/modules/order/src/models/order-shipping-method.ts index 5345a152d4683..855001af10a69 100644 --- a/packages/modules/order/src/models/order-shipping-method.ts +++ b/packages/modules/order/src/models/order-shipping-method.ts @@ -9,7 +9,6 @@ const _OrderShipping = model .define( { tableName: "order_shipping", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "ordspmv" }).primaryKey(), diff --git a/packages/modules/order/src/models/order-summary.ts b/packages/modules/order/src/models/order-summary.ts index 92394920ed466..d1da43a456db3 100644 --- a/packages/modules/order/src/models/order-summary.ts +++ b/packages/modules/order/src/models/order-summary.ts @@ -5,7 +5,6 @@ const _OrderSummary = model .define( { tableName: "order_summary", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "ordsum" }).primaryKey(), diff --git a/packages/modules/order/src/models/order.ts b/packages/modules/order/src/models/order.ts index 98da7665a4e4d..daa0ac84856aa 100644 --- a/packages/modules/order/src/models/order.ts +++ b/packages/modules/order/src/models/order.ts @@ -10,7 +10,6 @@ const _Order = model .define( { tableName: "order", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "order" }).primaryKey(), diff --git a/packages/modules/order/src/models/return-item.ts b/packages/modules/order/src/models/return-item.ts index edf5be8bdeef0..ca597903c7a8a 100644 --- a/packages/modules/order/src/models/return-item.ts +++ b/packages/modules/order/src/models/return-item.ts @@ -7,7 +7,6 @@ const _ReturnItem = model .define( { tableName: "return_item", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "retitem" }).primaryKey(), diff --git a/packages/modules/order/src/models/shipping-method-adjustment.ts b/packages/modules/order/src/models/shipping-method-adjustment.ts index c6a2dd3e4f0a6..e9d923b1dd923 100644 --- a/packages/modules/order/src/models/shipping-method-adjustment.ts +++ b/packages/modules/order/src/models/shipping-method-adjustment.ts @@ -5,7 +5,6 @@ const _OrderShippingMethodAdjustment = model .define( { tableName: "order_shipping_method_adjustment", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "ordsmadj" }).primaryKey(), 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 b5e1664f6050a..362300f5114a9 100644 --- a/packages/modules/order/src/models/shipping-method-tax-line.ts +++ b/packages/modules/order/src/models/shipping-method-tax-line.ts @@ -5,7 +5,6 @@ const _OrderShippingMethodTaxLine = model .define( { tableName: "order_shipping_method_tax_line", - disableSoftDeleteFilter: true, }, { id: model.id({ prefix: "ordsmtxl" }).primaryKey(), diff --git a/packages/modules/order/src/services/order-module-service.ts b/packages/modules/order/src/services/order-module-service.ts index f22c6578286c0..4771e1104e74c 100644 --- a/packages/modules/order/src/services/order-module-service.ts +++ b/packages/modules/order/src/services/order-module-service.ts @@ -142,7 +142,7 @@ const generateMethodForModels = { { const MikroORMEntity = toMikroORMEntity(OrderChangeAction) MikroORMEntity.prototype["onInit_OrderChangeAction"] = function () { - this.version ??= this.order?.version ?? null + this.version ??= this.order_change?.version ?? null this.order ??= rel( toMikroORMEntity(Order), @@ -178,6 +178,10 @@ const generateMethodForModels = { toMikroORMEntity(OrderExchange), this.exchange?.id ?? null ) + this.shipping_method ??= rel( + toMikroORMEntity(OrderShippingMethod), + this.shipping_method?.id ?? null + ) } OnInit()(MikroORMEntity.prototype, "onInit_OrderShipping") BeforeCreate()(MikroORMEntity.prototype, "onInit_OrderShipping") @@ -2966,8 +2970,8 @@ export default class OrderModuleService ], }, sharedContext - // TODO: investigate issue while using sharedContext in receive return action ) + orders = formatOrder(orders, { entity: Order, }) as OrderDTO[] diff --git a/packages/modules/order/src/utils/base-repository-find.ts b/packages/modules/order/src/utils/base-repository-find.ts index f3f72fca6ccf1..b9c3d85106478 100644 --- a/packages/modules/order/src/utils/base-repository-find.ts +++ b/packages/modules/order/src/utils/base-repository-find.ts @@ -84,7 +84,6 @@ export function setFindMethods(klass: Constructor, entity: any) { } config.where ??= {} - config.where.deleted_at ??= null return await manager.find(this.entity, config.where, config.options) } @@ -172,10 +171,16 @@ function configurePopulateWhere( if (isRelatedEntity) { popWhere.order ??= {} + popWhere.order.version = version if (hasRelation("shipping_methods")) { popWhere.shipping_methods ??= {} - popWhere.shipping_methods.deleted_at ??= null + popWhere.shipping_methods.version = version + } + + if (hasRelation("shipping_methods")) { + popWhere.shipping_methods ??= {} + popWhere.shipping_methods.version = version } } @@ -186,15 +191,13 @@ function configurePopulateWhere( orderWhere.summary.version = version } - if (hasRelation("items")) { + if (hasRelation("items") || hasRelation("order.items")) { orderWhere.items ??= {} orderWhere.items.version = version - orderWhere.items.deleted_at ??= null } if (hasRelation("shipping_methods")) { orderWhere.shipping_methods ??= {} orderWhere.shipping_methods.version = version - orderWhere.shipping_methods.deleted_at ??= null } }