Feat(order): order changes (#6614)
This is a PR to keep them relatively small. Very likely changes, validations and other features will be added. What: Basic methods to cancel, confirm or decline order changes Apply order changes to modify and create a new version of an order Things related to calculation, Order and Item totals are not covered in this PR. Properties won't match with definition, etc. Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
e4acde1aa2
commit
43399c8d0d
@@ -1,11 +1,11 @@
|
||||
import { OrderTypes } from "@medusajs/types"
|
||||
import { isDefined } from "@medusajs/utils"
|
||||
import { deduplicate, isDefined } from "@medusajs/utils"
|
||||
|
||||
export function formatOrder(
|
||||
order
|
||||
): OrderTypes.OrderDTO | OrderTypes.OrderDTO[] {
|
||||
const isArray = Array.isArray(order)
|
||||
const orders = isArray ? order : [order]
|
||||
const orders = [...(isArray ? order : [order])]
|
||||
|
||||
orders.map((order) => {
|
||||
order.items = order.items?.map((orderItem) => {
|
||||
@@ -21,6 +21,8 @@ export function formatOrder(
|
||||
}
|
||||
})
|
||||
|
||||
order.summary = order.summary?.[0]?.totals
|
||||
|
||||
return order
|
||||
})
|
||||
|
||||
@@ -35,25 +37,27 @@ export function mapRepositoryToOrderModel(config) {
|
||||
return
|
||||
}
|
||||
|
||||
return [
|
||||
...new Set<string>(
|
||||
obj[type].sort().map((rel) => {
|
||||
if (rel == "items.quantity") {
|
||||
if (type === "fields") {
|
||||
obj.populate.push("items.item")
|
||||
}
|
||||
return "items.item.quantity"
|
||||
} else if (rel.includes("items.detail")) {
|
||||
return rel.replace("items.detail", "items")
|
||||
} else if (rel == "items") {
|
||||
return "items.item"
|
||||
} else if (rel.includes("items.") && !rel.includes("items.item")) {
|
||||
return rel.replace("items.", "items.item.")
|
||||
return deduplicate(
|
||||
obj[type].sort().map((rel) => {
|
||||
if (rel == "items.quantity") {
|
||||
if (type === "fields") {
|
||||
obj.populate.push("items.item")
|
||||
}
|
||||
return rel
|
||||
})
|
||||
),
|
||||
]
|
||||
return "items.item.quantity"
|
||||
}
|
||||
if (rel == "summary" && type === "fields") {
|
||||
obj.populate.push("summary")
|
||||
return "summary.totals"
|
||||
} else if (rel.includes("items.detail")) {
|
||||
return rel.replace("items.detail", "items")
|
||||
} else if (rel == "items") {
|
||||
return "items.item"
|
||||
} else if (rel.includes("items.") && !rel.includes("items.item")) {
|
||||
return rel.replace("items.", "items.item.")
|
||||
}
|
||||
return rel
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
conf.options.fields = replace(config.options, "fields")
|
||||
|
||||
Reference in New Issue
Block a user