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:
1 parent
86c87c7b10
commit
b9bda3bf4e
6 files changed
+35
-4
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(medusa): Allows passing data object on shipping methods during claim creation and updates
|
||||||
@@ -1346,6 +1346,7 @@ describe("/admin/orders", () => {
|
|||||||
|
|
||||||
it("creates a claim on a swap", async () => {
|
it("creates a claim on a swap", async () => {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
const shippingOption = await simpleShippingOptionFactory(dbConnection)
|
||||||
|
|
||||||
const claimOnClaim = await api
|
const claimOnClaim = await api
|
||||||
.post(
|
.post(
|
||||||
@@ -1367,6 +1368,15 @@ describe("/admin/orders", () => {
|
|||||||
quantity: 1,
|
quantity: 1,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
shipping_methods: [
|
||||||
|
{
|
||||||
|
option_id: shippingOption.id,
|
||||||
|
price: 1000,
|
||||||
|
data: {
|
||||||
|
test: "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
adminReqConfig
|
adminReqConfig
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -383,6 +383,9 @@ export default async (req, res) => {
|
|||||||
* price:
|
* price:
|
||||||
* description: The price to charge for the Shipping Method
|
* description: The price to charge for the Shipping Method
|
||||||
* type: integer
|
* type: integer
|
||||||
|
* data:
|
||||||
|
* description: An optional set of key-value pairs to hold additional information.
|
||||||
|
* type: object
|
||||||
* shipping_address:
|
* shipping_address:
|
||||||
* type: object
|
* type: object
|
||||||
* description: "An optional shipping address to send the claim to. Defaults to the parent order's shipping address"
|
* 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()
|
@IsInt()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
price?: number
|
price?: number
|
||||||
|
|
||||||
|
@IsObject()
|
||||||
|
@IsOptional()
|
||||||
|
data?: Record<string, unknown>
|
||||||
}
|
}
|
||||||
|
|
||||||
class Item {
|
class Item {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { ClaimService, OrderService } from "../../../../services"
|
|
||||||
import {
|
import {
|
||||||
IsArray,
|
IsArray,
|
||||||
IsBoolean,
|
IsBoolean,
|
||||||
@@ -10,10 +9,11 @@ import {
|
|||||||
ValidateNested,
|
ValidateNested,
|
||||||
} from "class-validator"
|
} from "class-validator"
|
||||||
import { defaultAdminOrdersFields, defaultAdminOrdersRelations } from "."
|
import { defaultAdminOrdersFields, defaultAdminOrdersRelations } from "."
|
||||||
|
import { ClaimService, OrderService } from "../../../../services"
|
||||||
|
|
||||||
import { Type } from "class-transformer"
|
import { Type } from "class-transformer"
|
||||||
import { validator } from "../../../../utils/validator"
|
|
||||||
import { EntityManager } from "typeorm"
|
import { EntityManager } from "typeorm"
|
||||||
|
import { validator } from "../../../../utils/validator"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [post] /order/{id}/claims/{claim_id}
|
* @oas [post] /order/{id}/claims/{claim_id}
|
||||||
@@ -178,6 +178,9 @@ export default async (req, res) => {
|
|||||||
* price:
|
* price:
|
||||||
* description: The price to charge for the Shipping Method
|
* description: The price to charge for the Shipping Method
|
||||||
* type: integer
|
* type: integer
|
||||||
|
* data:
|
||||||
|
* description: An optional set of key-value pairs to hold additional information.
|
||||||
|
* type: object
|
||||||
* no_notification:
|
* no_notification:
|
||||||
* description: If set to true no notification will be send related to this Swap.
|
* description: If set to true no notification will be send related to this Swap.
|
||||||
* type: boolean
|
* type: boolean
|
||||||
@@ -219,6 +222,10 @@ class ShippingMethod {
|
|||||||
@IsInt()
|
@IsInt()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
price?: number
|
price?: number
|
||||||
|
|
||||||
|
@IsObject()
|
||||||
|
@IsOptional()
|
||||||
|
data?: Record<string, unknown>
|
||||||
}
|
}
|
||||||
|
|
||||||
class Item {
|
class Item {
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ export default class ClaimService extends TransactionBaseService {
|
|||||||
} else {
|
} else {
|
||||||
await shippingOptionServiceTx.createShippingMethod(
|
await shippingOptionServiceTx.createShippingMethod(
|
||||||
method.option_id as string,
|
method.option_id as string,
|
||||||
(method as any).data,
|
method.data ?? {},
|
||||||
{
|
{
|
||||||
claim_order_id: claim.id,
|
claim_order_id: claim.id,
|
||||||
price: method.price,
|
price: method.price,
|
||||||
@@ -403,7 +403,7 @@ export default class ClaimService extends TransactionBaseService {
|
|||||||
} else {
|
} else {
|
||||||
await shippingOptionServiceTx.createShippingMethod(
|
await shippingOptionServiceTx.createShippingMethod(
|
||||||
method.option_id as string,
|
method.option_id as string,
|
||||||
(method as any).data,
|
method.data ?? {},
|
||||||
{
|
{
|
||||||
claim_order_id: result.id,
|
claim_order_id: result.id,
|
||||||
price: method.price,
|
price: method.price,
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ type CreateClaimShippingMethodInput = {
|
|||||||
id?: string
|
id?: string
|
||||||
option_id?: string
|
option_id?: string
|
||||||
price?: number
|
price?: number
|
||||||
|
data?: Record<string, unknown>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CreateClaimItemInput = {
|
export type CreateClaimItemInput = {
|
||||||
@@ -59,6 +60,7 @@ type UpdateClaimShippingMethodInput = {
|
|||||||
id?: string
|
id?: string
|
||||||
option_id?: string
|
option_id?: string
|
||||||
price?: number
|
price?: number
|
||||||
|
data?: Record<string, unknown>
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateClaimItemInput = {
|
type UpdateClaimItemInput = {
|
||||||
|
|||||||
Reference in new issue
Block a user