Merge pull request #284 from medusajs/fix/idable-fields

fix: adds transformer to map field names to field_id names
This commit is contained in:
Sebastian Rindom authored and GitHub committed 2021-06-16 08:54:14 +02:00
commit 0d3e8f717d
5 files changed
+144 -12

No files matched your search

@@ -1,4 +1,8 @@
import { MedusaError, Validator } from "medusa-core-utils"
import {
MedusaError,
Validator,
transformIdableFields,
} from "medusa-core-utils"
import { defaultFields, defaultRelations } from "."
/**
@@ -133,11 +137,13 @@ export default async (req, res) => {
metadata: Validator.object().optional(),
})
const { value, error } = schema.validate(req.body)
let { value, error } = schema.validate(req.body)
if (error) {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
}
value = transformIdableFields(value, ["shipping_address", "billing_address"])
try {
const draftOrderService = req.scope.resolve("draftOrderService")
let draftOrder = await draftOrderService.create(value)
+8 -10
View File
@@ -306,8 +306,8 @@ class CartService extends BaseService {
const regCountries = region.countries.map(({ iso_2 }) => iso_2)
if (data.shipping_address && typeof data.shipping_address === `string`) {
const addr = await addressRepo.findOne(data.shipping_address)
if (data.shipping_address_id) {
const addr = await addressRepo.findOne(data.shipping_address_id)
data.shipping_address = addr
}
@@ -650,16 +650,14 @@ class CartService extends BaseService {
}
const addrRepo = manager.getCustomRepository(this.addressRepository_)
if ("shipping_address" in update) {
await this.updateShippingAddress_(
cart,
update.shipping_address,
addrRepo
)
if ("shipping_address_id" in update || "shipping_address" in update) {
const address = update.shipping_address_id || update.shipping_address
await this.updateShippingAddress_(cart, address, addrRepo)
}
if ("billing_address" in update) {
await this.updateBillingAddress_(cart, update.billing_address, addrRepo)
if ("billing_address_id" in update || "billing_address" in update) {
const address = update.billing_address_id || update.billing_address
await this.updateBillingAddress_(cart, address, addrRepo)
}
if ("discounts" in update) {