Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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