feat(medusa, core-flows): add ppdate inventory item endpoint (#6735)
* init update inventory item * prep for pr
This commit is contained in:
@@ -4,8 +4,12 @@ import {
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
|
||||
import {
|
||||
deleteInventoryItemWorkflow,
|
||||
updateInventoryItemsWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
|
||||
import { deleteInventoryItemWorkflow } from "@medusajs/core-flows"
|
||||
import { AdminPostInventoryItemsInventoryItemReq } from "../validators"
|
||||
|
||||
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||
const { id } = req.params
|
||||
@@ -38,6 +42,36 @@ export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||
})
|
||||
}
|
||||
|
||||
// Update inventory item
|
||||
export const POST = async (
|
||||
req: MedusaRequest<AdminPostInventoryItemsInventoryItemReq>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
await updateInventoryItemsWorkflow(req.scope).run({
|
||||
input: {
|
||||
updates: [{ id, ...req.validatedBody }],
|
||||
},
|
||||
})
|
||||
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const [inventory_item] = await remoteQuery(
|
||||
remoteQueryObjectFromString({
|
||||
entryPoint: "inventory",
|
||||
variables: {
|
||||
id,
|
||||
},
|
||||
fields: req.retrieveConfig.select as string[],
|
||||
})
|
||||
)
|
||||
|
||||
res.status(200).json({
|
||||
inventory_item,
|
||||
})
|
||||
}
|
||||
|
||||
export const DELETE = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||
const id = req.params.id
|
||||
const deleteInventoryItems = deleteInventoryItemWorkflow(req.scope)
|
||||
|
||||
@@ -3,6 +3,8 @@ import * as QueryConfig from "./query-config"
|
||||
import {
|
||||
AdminGetInventoryItemsItemParams,
|
||||
AdminGetInventoryItemsParams,
|
||||
AdminPostInventoryItemsInventoryItemParams,
|
||||
AdminPostInventoryItemsInventoryItemReq,
|
||||
AdminPostInventoryItemsItemLocationLevelsReq,
|
||||
AdminPostInventoryItemsReq,
|
||||
} from "./validators"
|
||||
@@ -53,4 +55,15 @@ export const adminInventoryRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/inventory-items/:id",
|
||||
middlewares: [
|
||||
transformBody(AdminPostInventoryItemsInventoryItemReq),
|
||||
transformQuery(
|
||||
AdminPostInventoryItemsInventoryItemParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
@@ -257,3 +257,102 @@ export class AdminPostInventoryItemsReq {
|
||||
@IsOptional()
|
||||
metadata?: Record<string, unknown>
|
||||
}
|
||||
|
||||
/**
|
||||
* @schema AdminPostInventoryItemsInventoryItemReq
|
||||
* type: object
|
||||
* description: "The attributes to update in an inventory item."
|
||||
* properties:
|
||||
* hs_code:
|
||||
* description: The Harmonized System code of the Inventory Item. May be used by Fulfillment Providers to pass customs information to shipping carriers.
|
||||
* type: string
|
||||
* origin_country:
|
||||
* description: The country in which the Inventory Item was produced. May be used by Fulfillment Providers to pass customs information to shipping carriers.
|
||||
* type: string
|
||||
* mid_code:
|
||||
* description: The Manufacturers Identification code that identifies the manufacturer of the Inventory Item. May be used by Fulfillment Providers to pass customs information to shipping carriers.
|
||||
* type: string
|
||||
* material:
|
||||
* description: The material and composition that the Inventory Item is made of, May be used by Fulfillment Providers to pass customs information to shipping carriers.
|
||||
* type: string
|
||||
* weight:
|
||||
* description: The weight of the Inventory Item. May be used in shipping rate calculations.
|
||||
* type: number
|
||||
* height:
|
||||
* description: The height of the Inventory Item. May be used in shipping rate calculations.
|
||||
* type: number
|
||||
* width:
|
||||
* description: The width of the Inventory Item. May be used in shipping rate calculations.
|
||||
* type: number
|
||||
* length:
|
||||
* description: The length of the Inventory Item. May be used in shipping rate calculations.
|
||||
* type: number
|
||||
* title:
|
||||
* description: The inventory item's title.
|
||||
* type: string
|
||||
* description:
|
||||
* description: The inventory item's description.
|
||||
* type: string
|
||||
* thumbnail:
|
||||
* description: The inventory item's thumbnail.
|
||||
* type: string
|
||||
* requires_shipping:
|
||||
* description: Whether the item requires shipping.
|
||||
* type: boolean
|
||||
*/
|
||||
|
||||
export class AdminPostInventoryItemsInventoryItemReq {
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
sku?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
origin_country?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
hs_code?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
mid_code?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
material?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
weight?: number
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
height?: number
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
length?: number
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
width?: number
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
title?: string
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
description?: string
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
thumbnail?: string
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
requires_shipping?: boolean
|
||||
}
|
||||
|
||||
export class AdminPostInventoryItemsInventoryItemParams extends FindParams {}
|
||||
|
||||
Reference in New Issue
Block a user