chore(order): dml (#10292)
* ../../core/types/src/dml/index.ts * ../../core/types/src/dml/index.ts * fix: relationships mapping * handle nullable foreign keys types * handle nullable foreign keys types * handle nullable foreign keys types * continue to update product category repository * fix all product category repositories issues * fix product category service types * fix product module service types * fix product module service types * fix repository template type * refactor: use a singleton DMLToMikroORM factory instance Since the MikroORM MetadataStorage is global, we will also have to turn DML to MikroORM entities conversion use a global bucket as well * refactor: update product module to use DML in tests * wip: tests * WIP product linkable fixes * continue type fixing and start test fixing * test: fix more tests * fix repository * fix pivot table computaion + fix mikro orm repository * fix many to many management and configuration * fix many to many management and configuration * fix many to many management and configuration * update product tag relation configuration * Introduce experimental dml hooks to fix some issues with categories * more fixes * fix product tests * add missing id prefixes * fix product category handle management * test: fix more failing tests * test: make it all green * test: fix breaking tests * fix: build issues * fix: build issues * fix: more breaking tests * refactor: fix issues after merge * refactor: fix issues after merge * refactor: surpress types error * test: fix DML failing tests * improve many to many inference + tests * Wip fix columns from product entity * remove product model before create hook and manage handle validation and transformation at the service level * test: fix breaking unit tests * fix: product module service to not update handle on product update * fix define link and joiner config * test: fix joiner config test * test: fix joiner config test * fix joiner config primary keys * Fix joiner config builder * Fix joiner config builder * test: remove only modifier from test * refactor: remove hooks usage from product collection * refactor: remove hooks usage from product-option * refactor: remove hooks usage for computing category handle * refactor: remove hooks usage from productCategory model * refactor: remove hooks from DML * refactor: remove cruft * order dml * cleanup * re add foerign key indexes * wip * chore: remove unused types * wip * changes * rm raw * autoincrement * wip * rel * refactor: cleanup * migration and models configuration adjustments * cleanup * number searchable * fix random ordering * fix * test: fix product-category tests * test: update breaking DML tests * test: array assertion to not care about ordering * fix: temporarily apply id ordering for products * types * wip * WIP type improvements * update order models * partially fix types temporarely * rel * fix: recursive type issue * improve type inference breaks * improve type inference breaks * update models * rm nullable * default value * repository * update default value handling * fix unit tests * WIP * toMikroORM * fix relations * cascades * fix * experimental dml hooks * rm migration * serial * nullable autoincrement * fix model * model changes * fix one to one DML * order test * fix addresses * fix unit tests * Re align dml entity name inference * update model table name config * update model table name config * revert * update return relation * WIP * hasOne * models * fix * model * initial commit * cart service * order module * utils unit test * index engine * changeset * merge * fix hasOne with fk * update * free text filter per entity * tests * prod category * property string many to many * fix big number * link modules migration set names * merge * shipping option rules * serializer * unit test * fix test mikro orm init * fix test mikro orm init * Maintain merge object properties * fix test mikro orm init * prevent unit test from connecting to db * wip * fix test * fix test * link test * schema * models * auto increment * hook * model hooks * order * wip * orm version * request return field * fix return configuration on order model * workflows * core flows * unit test * test * base repo * test * base repo * test fix * inventory move * locking inventory * test * free text fix * rm timeout mock * migrate fulfillment values * v6.4.3 * cleanup * link-modules update sql * revert test * remove fake timers --------- Co-authored-by: adrien2p <adrien.deperetti@gmail.com> Co-authored-by: Harminder Virk <virk.officials@gmail.com> Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
co-authored by
adrien2p
Harminder Virk
Oli Juhl
parent
05c8a67d8e
commit
cc73802ab3
@@ -11,11 +11,12 @@ import {
|
||||
getShippingMethodsTotals,
|
||||
isString,
|
||||
promiseAll,
|
||||
toMikroORMEntity,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { OrderClaim, OrderClaimItem, Return, ReturnItem } from "@models"
|
||||
|
||||
function createClaimAndReturnEntities(em, data, order) {
|
||||
const claimReference = em.create(OrderClaim, {
|
||||
const claimReference = em.create(toMikroORMEntity(OrderClaim), {
|
||||
order_id: data.order_id,
|
||||
order_version: order.version,
|
||||
type: data.type as ClaimType,
|
||||
@@ -25,16 +26,16 @@ function createClaimAndReturnEntities(em, data, order) {
|
||||
|
||||
const returnReference =
|
||||
data.type === ClaimType.REPLACE
|
||||
? em.create(Return, {
|
||||
? em.create(toMikroORMEntity(Return), {
|
||||
order_id: data.order_id,
|
||||
order_version: order.version,
|
||||
status: ReturnStatus.REQUESTED,
|
||||
claim_id: claimReference.id,
|
||||
claim: claimReference.id,
|
||||
refund_amount: (data.refund_amount as unknown) ?? null,
|
||||
})
|
||||
: undefined
|
||||
|
||||
claimReference.return_id = returnReference?.id
|
||||
claimReference.return = returnReference?.id
|
||||
|
||||
return { claimReference, returnReference }
|
||||
}
|
||||
@@ -51,7 +52,7 @@ function createReturnItem(em, item, claimReference, returnReference, actions) {
|
||||
},
|
||||
})
|
||||
|
||||
return em.create(ReturnItem, {
|
||||
return em.create(toMikroORMEntity(ReturnItem), {
|
||||
item_id: item.id,
|
||||
return_id: returnReference.id,
|
||||
quantity: item.quantity,
|
||||
@@ -67,7 +68,7 @@ function createClaimAndReturnItems(
|
||||
returnReference,
|
||||
actions
|
||||
) {
|
||||
const returnItems: ReturnItem[] = []
|
||||
const returnItems: (typeof ReturnItem)[] = []
|
||||
const claimItems = data.claim_items?.map((item) => {
|
||||
actions.push({
|
||||
action: ChangeActionType.WRITE_OFF_ITEM,
|
||||
@@ -86,7 +87,7 @@ function createClaimAndReturnItems(
|
||||
: undefined
|
||||
)
|
||||
|
||||
return em.create(OrderClaimItem, {
|
||||
return em.create(toMikroORMEntity(OrderClaimItem), {
|
||||
item_id: item.id,
|
||||
reason: item.reason,
|
||||
quantity: item.quantity,
|
||||
@@ -108,8 +109,8 @@ async function processAdditionalItems(
|
||||
sharedContext
|
||||
) {
|
||||
const itemsToAdd: any[] = []
|
||||
const additionalNewItems: OrderClaimItem[] = []
|
||||
const additionalItems: OrderClaimItem[] = []
|
||||
const additionalNewItems: any[] = []
|
||||
const additionalItems: any[] = []
|
||||
data.additional_items?.forEach((item) => {
|
||||
const hasItem = item.id
|
||||
? order.items.find((o) => o.item.id === item.id)
|
||||
@@ -131,7 +132,7 @@ async function processAdditionalItems(
|
||||
})
|
||||
|
||||
additionalItems.push(
|
||||
em.create(OrderClaimItem, {
|
||||
em.create(toMikroORMEntity(OrderClaimItem), {
|
||||
item_id: item.id,
|
||||
quantity: item.quantity,
|
||||
note: item.note,
|
||||
@@ -143,7 +144,7 @@ async function processAdditionalItems(
|
||||
itemsToAdd.push(item)
|
||||
|
||||
additionalNewItems.push(
|
||||
em.create(OrderClaimItem, {
|
||||
em.create(toMikroORMEntity(OrderClaimItem), {
|
||||
quantity: item.quantity,
|
||||
unit_price: item.unit_price,
|
||||
note: item.note,
|
||||
|
||||
@@ -10,11 +10,12 @@ import {
|
||||
getShippingMethodsTotals,
|
||||
isString,
|
||||
promiseAll,
|
||||
toMikroORMEntity,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { OrderExchange, OrderExchangeItem, Return, ReturnItem } from "@models"
|
||||
|
||||
function createExchangeAndReturnEntities(em, data, order) {
|
||||
const exchangeReference = em.create(OrderExchange, {
|
||||
const exchangeReference = em.create(toMikroORMEntity(OrderExchange), {
|
||||
order_id: data.order_id,
|
||||
order_version: order.version,
|
||||
no_notification: data.no_notification,
|
||||
@@ -22,7 +23,7 @@ function createExchangeAndReturnEntities(em, data, order) {
|
||||
difference_due: data.difference_due,
|
||||
})
|
||||
|
||||
const returnReference = em.create(Return, {
|
||||
const returnReference = em.create(toMikroORMEntity(Return), {
|
||||
order_id: data.order_id,
|
||||
order_version: order.version,
|
||||
status: ReturnStatus.REQUESTED,
|
||||
@@ -30,7 +31,7 @@ function createExchangeAndReturnEntities(em, data, order) {
|
||||
refund_amount: (data.refund_amount as unknown) ?? null,
|
||||
})
|
||||
|
||||
exchangeReference.return_id = returnReference.id
|
||||
exchangeReference.return = returnReference
|
||||
|
||||
return { exchangeReference, returnReference }
|
||||
}
|
||||
@@ -54,7 +55,7 @@ function createReturnItems(
|
||||
},
|
||||
})
|
||||
|
||||
return em.create(ReturnItem, {
|
||||
return em.create(toMikroORMEntity(ReturnItem), {
|
||||
item_id: item.id,
|
||||
return_id: returnReference.id,
|
||||
reason: item.reason,
|
||||
@@ -75,8 +76,8 @@ async function processAdditionalItems(
|
||||
sharedContext
|
||||
) {
|
||||
const itemsToAdd: any[] = []
|
||||
const additionalNewItems: OrderExchangeItem[] = []
|
||||
const additionalItems: OrderExchangeItem[] = []
|
||||
const additionalNewItems: any[] = []
|
||||
const additionalItems: any[] = []
|
||||
data.additional_items?.forEach((item) => {
|
||||
const hasItem = item.id
|
||||
? order.items.find((o) => o.item.id === item.id)
|
||||
@@ -98,7 +99,7 @@ async function processAdditionalItems(
|
||||
})
|
||||
|
||||
additionalItems.push(
|
||||
em.create(OrderExchangeItem, {
|
||||
em.create(toMikroORMEntity(OrderExchangeItem), {
|
||||
item_id: item.id,
|
||||
quantity: item.quantity,
|
||||
note: item.note,
|
||||
@@ -110,7 +111,7 @@ async function processAdditionalItems(
|
||||
itemsToAdd.push(item)
|
||||
|
||||
additionalNewItems.push(
|
||||
em.create(OrderExchangeItem, {
|
||||
em.create(toMikroORMEntity(OrderExchangeItem), {
|
||||
quantity: item.quantity,
|
||||
unit_price: item.unit_price,
|
||||
note: item.note,
|
||||
@@ -313,6 +314,5 @@ export async function createExchange(
|
||||
this.createOrderExchanges([exchangeReference], sharedContext),
|
||||
this.confirmOrderChange(change[0].id, sharedContext),
|
||||
])
|
||||
|
||||
return exchangeReference
|
||||
}
|
||||
|
||||
@@ -11,11 +11,12 @@ import {
|
||||
isDefined,
|
||||
isString,
|
||||
promiseAll,
|
||||
toMikroORMEntity,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { Return, ReturnItem } from "@models"
|
||||
|
||||
function createReturnReference(em, data, order) {
|
||||
return em.create(Return, {
|
||||
return em.create(toMikroORMEntity(Return), {
|
||||
order_id: data.order_id,
|
||||
order_version: order.version,
|
||||
status: ReturnStatus.REQUESTED,
|
||||
@@ -39,7 +40,7 @@ function createReturnItems(em, data, returnRef, actions) {
|
||||
},
|
||||
})
|
||||
|
||||
return em.create(ReturnItem, {
|
||||
return em.create(toMikroORMEntity(ReturnItem), {
|
||||
reason_id: item.reason_id,
|
||||
return_id: returnRef.id,
|
||||
item_id: item.id,
|
||||
|
||||
@@ -85,7 +85,7 @@ export async function receiveReturn(
|
||||
data.return_id,
|
||||
{
|
||||
select: ["id", "order_id"],
|
||||
relations: ["items"],
|
||||
relations: ["items", "items.item"],
|
||||
},
|
||||
sharedContext
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user