fix(): Order constraint and receive return (#12889)
**What** - Fix missing `ON DELETE CASCADE` constraint on order credit lines - Fix `receiveReturn` miss usage - Make all order integration tests to run and rename them all to `*.spec.ts` - Fix package.json typo
This commit is contained in:
@@ -1311,6 +1311,7 @@
|
||||
"id"
|
||||
],
|
||||
"referencedTableName": "public.order",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Migration } from "@mikro-orm/migrations"
|
||||
|
||||
export class Migration20250704120229 extends Migration {
|
||||
override async up(): Promise<void> {
|
||||
this.addSql(
|
||||
`alter table if exists "order_credit_line" drop constraint if exists "order_credit_line_order_id_foreign";`
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
`alter table if exists "order_credit_line" add constraint "order_credit_line_order_id_foreign" foreign key ("order_id") references "order" ("id") on update cascade on delete cascade;`
|
||||
)
|
||||
}
|
||||
|
||||
override async down(): Promise<void> {
|
||||
this.addSql(
|
||||
`alter table if exists "order_credit_line" drop constraint if exists "order_credit_line_order_id_foreign";`
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
`alter table if exists "order_credit_line" add constraint "order_credit_line_order_id_foreign" foreign key ("order_id") references "order" ("id") on update cascade;`
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,13 @@ const _Order = model
|
||||
}),
|
||||
})
|
||||
.cascades({
|
||||
delete: ["summary", "items", "shipping_methods", "transactions"],
|
||||
delete: [
|
||||
"summary",
|
||||
"items",
|
||||
"shipping_methods",
|
||||
"transactions",
|
||||
"credit_lines",
|
||||
],
|
||||
})
|
||||
.indexes([
|
||||
{
|
||||
|
||||
@@ -897,13 +897,10 @@ export default class OrderModuleService
|
||||
(orderShipping) => orderShipping.shipping_method_id
|
||||
)
|
||||
|
||||
await promiseAll([
|
||||
this.orderAddressService_.delete(orderAddressIds, sharedContext),
|
||||
// Delete order changes & actions
|
||||
this.orderChangeService_.delete(orderChangeIds, sharedContext),
|
||||
])
|
||||
await this.orderAddressService_.delete(orderAddressIds, sharedContext)
|
||||
await this.orderChangeService_.delete(orderChangeIds, sharedContext)
|
||||
|
||||
// Delete order, order items, summary, shipping methods and transactions
|
||||
// Delete order, order items, summary, shipping methods, transactions and credit lines
|
||||
await super.deleteOrders(ids, sharedContext)
|
||||
|
||||
await promiseAll([
|
||||
@@ -3653,7 +3650,7 @@ export default class OrderModuleService
|
||||
): Promise<OrderTypes.ReturnDTO> {
|
||||
const ret = await this.receiveReturn_(data, sharedContext)
|
||||
|
||||
return await this.retrieveReturn(ret.id, {
|
||||
return await this.retrieveReturn(ret[0].id, {
|
||||
relations: [
|
||||
"items",
|
||||
"items.item",
|
||||
@@ -3668,7 +3665,7 @@ export default class OrderModuleService
|
||||
private async receiveReturn_(
|
||||
data: OrderTypes.ReceiveOrderReturnDTO,
|
||||
@MedusaContext() sharedContext?: Context
|
||||
): Promise<any> {
|
||||
): Promise<any[]> {
|
||||
return await BundledActions.receiveReturn.bind(this)(data, sharedContext)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user