Skip to content

Commit

Permalink
fix(medusa): Allow method.data to be passed when creating/updating …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
kasperkristensen authored and adrien2p committed Feb 13, 2023
1 parent 717d8df commit 3b69407
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/wise-dodos-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

fix(medusa): Allows passing data object on shipping methods during claim creation and updates
10 changes: 10 additions & 0 deletions integration-tests/api/__tests__/admin/order/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -1367,6 +1368,15 @@ describe("/admin/orders", () => {
quantity: 1,
},
],
shipping_methods: [
{
option_id: shippingOption.id,
price: 1000,
data: {
test: "test",
},
},
],
},
adminReqConfig
)
Expand Down
7 changes: 7 additions & 0 deletions packages/medusa/src/api/routes/admin/orders/create-claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -466,6 +469,10 @@ class ShippingMethod {
@IsInt()
@IsOptional()
price?: number

@IsObject()
@IsOptional()
data?: Record<string, unknown>
}

class Item {
Expand Down
11 changes: 9 additions & 2 deletions packages/medusa/src/api/routes/admin/orders/update-claim.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ClaimService, OrderService } from "../../../../services"
import {
IsArray,
IsBoolean,
Expand All @@ -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}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -219,6 +222,10 @@ class ShippingMethod {
@IsInt()
@IsOptional()
price?: number

@IsObject()
@IsOptional()
data?: Record<string, unknown>
}

class Item {
Expand Down
4 changes: 2 additions & 2 deletions packages/medusa/src/services/claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/medusa/src/types/claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type CreateClaimShippingMethodInput = {
id?: string
option_id?: string
price?: number
data?: Record<string, unknown>
}

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

type UpdateClaimItemInput = {
Expand Down

0 comments on commit 3b69407

Please sign in to comment.