fix(medusa): Allow method.data to be passed when creating/updating ShippingMethods in ClaimService (#3205)

**What**
- Allows passing data on shipping methods during claim creation and updates. Defaults to an empty object.

**Testing** 
- Updates a test so it also passes along shipping method data.
This commit is contained in:
Kasper Fabricius Kristensen
2023-02-08 07:37:35 -05:00
committed by GitHub
parent 86c87c7b10
commit b9bda3bf4e
6 changed files with 35 additions and 4 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
fix(medusa): Allows passing data object on shipping methods during claim creation and updates

View File

@@ -1346,6 +1346,7 @@ describe("/admin/orders", () => {
it("creates a claim on a swap", async () => {
const api = useApi()
const shippingOption = await simpleShippingOptionFactory(dbConnection)
const claimOnClaim = await api
.post(
@@ -1367,6 +1368,15 @@ describe("/admin/orders", () => {
quantity: 1,
},
],
shipping_methods: [
{
option_id: shippingOption.id,
price: 1000,
data: {
test: "test",
},
},
],
},
adminReqConfig
)

View File

@@ -383,6 +383,9 @@ export default async (req, res) => {
* price:
* description: The price to charge for the Shipping Method
* type: integer
* data:
* description: An optional set of key-value pairs to hold additional information.
* type: object
* shipping_address:
* type: object
* description: "An optional shipping address to send the claim to. Defaults to the parent order's shipping address"
@@ -466,6 +469,10 @@ class ShippingMethod {
@IsInt()
@IsOptional()
price?: number
@IsObject()
@IsOptional()
data?: Record<string, unknown>
}
class Item {

View File

@@ -1,4 +1,3 @@
import { ClaimService, OrderService } from "../../../../services"
import {
IsArray,
IsBoolean,
@@ -10,10 +9,11 @@ import {
ValidateNested,
} from "class-validator"
import { defaultAdminOrdersFields, defaultAdminOrdersRelations } from "."
import { ClaimService, OrderService } from "../../../../services"
import { Type } from "class-transformer"
import { validator } from "../../../../utils/validator"
import { EntityManager } from "typeorm"
import { validator } from "../../../../utils/validator"
/**
* @oas [post] /order/{id}/claims/{claim_id}
@@ -178,6 +178,9 @@ export default async (req, res) => {
* price:
* description: The price to charge for the Shipping Method
* type: integer
* data:
* description: An optional set of key-value pairs to hold additional information.
* type: object
* no_notification:
* description: If set to true no notification will be send related to this Swap.
* type: boolean
@@ -219,6 +222,10 @@ class ShippingMethod {
@IsInt()
@IsOptional()
price?: number
@IsObject()
@IsOptional()
data?: Record<string, unknown>
}
class Item {

View File

@@ -166,7 +166,7 @@ export default class ClaimService extends TransactionBaseService {
} else {
await shippingOptionServiceTx.createShippingMethod(
method.option_id as string,
(method as any).data,
method.data ?? {},
{
claim_order_id: claim.id,
price: method.price,
@@ -403,7 +403,7 @@ export default class ClaimService extends TransactionBaseService {
} else {
await shippingOptionServiceTx.createShippingMethod(
method.option_id as string,
(method as any).data,
method.data ?? {},
{
claim_order_id: result.id,
price: method.price,

View File

@@ -29,6 +29,7 @@ type CreateClaimShippingMethodInput = {
id?: string
option_id?: string
price?: number
data?: Record<string, unknown>
}
export type CreateClaimItemInput = {
@@ -59,6 +60,7 @@ type UpdateClaimShippingMethodInput = {
id?: string
option_id?: string
price?: number
data?: Record<string, unknown>
}
type UpdateClaimItemInput = {