Skip to content

Commit

Permalink
order
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-r-l-rodrigues committed Dec 21, 2024
1 parent 0ed533a commit 5ae3a0c
Show file tree
Hide file tree
Showing 21 changed files with 24 additions and 64 deletions.
1 change: 0 additions & 1 deletion packages/core/types/src/dml/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export type IDmlEntityConfig =
| {
name?: string
tableName: string
disableSoftDeleteFilter?: boolean
}

export type InferDmlEntityNameFromConfig<TConfig extends IDmlEntityConfig> =
Expand Down
14 changes: 2 additions & 12 deletions packages/core/utils/src/dml/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ function extractNameAndTableName<const Config extends IDmlEntityConfig>(
const result = {
name: "",
tableName: "",
disableSoftDeleteFilter: false,
} as {
name: InferDmlEntityNameFromConfig<Config>
tableName: string
disableSoftDeleteFilter: boolean
}

if (isString(nameOrConfig)) {
Expand Down Expand Up @@ -58,8 +56,6 @@ function extractNameAndTableName<const Config extends IDmlEntityConfig>(
toCamelCase(name)
) as InferDmlEntityNameFromConfig<Config>
result.tableName = nameOrConfig.tableName
result.disableSoftDeleteFilter =
nameOrConfig.disableSoftDeleteFilter ?? false
}

return result
Expand All @@ -81,19 +77,15 @@ export class DmlEntity<

readonly #tableName: string
#cascades: EntityCascades<string[], string[]> = {}
#params: Record<string, unknown>

#indexes: EntityIndex<Schema>[] = []
#checks: CheckConstraint<Schema>[] = []

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,
}
}

/**
Expand All @@ -116,7 +108,6 @@ export class DmlEntity<
schema: DMLSchema
cascades: EntityCascades<string[], string[]>
indexes: EntityIndex<Schema>[]
params: Record<string, unknown>
checks: CheckConstraint<Schema>[]
} {
return {
Expand All @@ -125,7 +116,6 @@ export class DmlEntity<
schema: this.schema,
cascades: this.#cascades,
indexes: this.#indexes,
params: this.#params,
checks: this.#checks,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
"items.detail.return_received_quantity",
"shipping_methods.id",
],
relations: ["items", "items.detail"],
relations: ["items", "items.detail", "shipping_methods"],
})

serializedOrder = JSON.parse(JSON.stringify(getOrder))
Expand Down
1 change: 0 additions & 1 deletion packages/modules/order/src/models/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const _OrderAddress = model
.define(
{
tableName: "order_address",
disableSoftDeleteFilter: true,
},
{
id: model.id({ prefix: "ordaddr" }).primaryKey(),
Expand Down
1 change: 0 additions & 1 deletion packages/modules/order/src/models/claim-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const _OrderClaimItem = model
.define(
{
tableName: "order_claim_item",
disableSoftDeleteFilter: true,
},
{
id: model.id({ prefix: "claitem" }).primaryKey(),
Expand Down
7 changes: 1 addition & 6 deletions packages/modules/order/src/models/claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ const _OrderClaim = model
),
})
.cascades({
delete: [
"additional_items",
"claim_items",
"shipping_methods",
"transactions",
],
delete: ["additional_items", "claim_items", "transactions"],
})
.indexes([
{
Expand Down
1 change: 0 additions & 1 deletion packages/modules/order/src/models/exchange-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const _OrderExchangeItem = model
.define(
{
tableName: "order_exchange_item",
disableSoftDeleteFilter: true,
},
{
id: model.id({ prefix: "oexcitem" }).primaryKey(),
Expand Down
1 change: 0 additions & 1 deletion packages/modules/order/src/models/line-item-adjustment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const _OrderLineItemAdjustment = model
.define(
{
tableName: "order_line_item_adjustment",
disableSoftDeleteFilter: true,
},
{
id: model.id({ prefix: "ordliadj" }).primaryKey(),
Expand Down
1 change: 0 additions & 1 deletion packages/modules/order/src/models/line-item-tax-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const _OrderLineItemTaxLine = model
.define(
{
tableName: "order_line_item_tax_line",
disableSoftDeleteFilter: true,
},
{
id: model.id({ prefix: "ordlitxl" }).primaryKey(),
Expand Down
11 changes: 0 additions & 11 deletions packages/modules/order/src/models/order-change-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 1 addition & 4 deletions packages/modules/order/src/models/order-change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ const _OrderChange = model
})
.nullable(),
actions: model.hasMany<() => typeof OrderChangeAction>(
() => OrderChangeAction,
{
mappedBy: "order_change",
}
() => OrderChangeAction
),
})
.cascades({
Expand Down
14 changes: 4 additions & 10 deletions packages/modules/order/src/models/order-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const _OrderItem = model
.define(
{
tableName: "order_item",
disableSoftDeleteFilter: true,
},
{
id: model.id({ prefix: "orditem" }).primaryKey(),
Expand All @@ -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",
Expand Down
1 change: 0 additions & 1 deletion packages/modules/order/src/models/order-shipping-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const _OrderShipping = model
.define(
{
tableName: "order_shipping",
disableSoftDeleteFilter: true,
},
{
id: model.id({ prefix: "ordspmv" }).primaryKey(),
Expand Down
1 change: 0 additions & 1 deletion packages/modules/order/src/models/order-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const _OrderSummary = model
.define(
{
tableName: "order_summary",
disableSoftDeleteFilter: true,
},
{
id: model.id({ prefix: "ordsum" }).primaryKey(),
Expand Down
1 change: 0 additions & 1 deletion packages/modules/order/src/models/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const _Order = model
.define(
{
tableName: "order",
disableSoftDeleteFilter: true,
},
{
id: model.id({ prefix: "order" }).primaryKey(),
Expand Down
1 change: 0 additions & 1 deletion packages/modules/order/src/models/return-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const _ReturnItem = model
.define(
{
tableName: "return_item",
disableSoftDeleteFilter: true,
},
{
id: model.id({ prefix: "retitem" }).primaryKey(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const _OrderShippingMethodAdjustment = model
.define(
{
tableName: "order_shipping_method_adjustment",
disableSoftDeleteFilter: true,
},
{
id: model.id({ prefix: "ordsmadj" }).primaryKey(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const _OrderShippingMethodTaxLine = model
.define(
{
tableName: "order_shipping_method_tax_line",
disableSoftDeleteFilter: true,
},
{
id: model.id({ prefix: "ordsmtxl" }).primaryKey(),
Expand Down
8 changes: 6 additions & 2 deletions packages/modules/order/src/services/order-module-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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[]
Expand Down
13 changes: 8 additions & 5 deletions packages/modules/order/src/utils/base-repository-find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export function setFindMethods<T>(klass: Constructor<T>, entity: any) {
}

config.where ??= {}
config.where.deleted_at ??= null

return await manager.find(this.entity, config.where, config.options)
}
Expand Down Expand Up @@ -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
}
}

Expand All @@ -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
}
}

0 comments on commit 5ae3a0c

Please sign in to comment.