feat(client-types, types, medusa, inventory): Inventory item and reservation item datamodel updates (#3971)
* add fields * add title in migration * update api endpoints to reflect datamodel changes * update migration exports for inventory module * add changeset * add created_by for reservation item
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
import { IInventoryService } from "@medusajs/types"
|
||||
import { MedusaError } from "@medusajs/utils"
|
||||
import { IsNumber, IsObject, IsOptional, IsString } from "class-validator"
|
||||
import { EntityManager } from "typeorm"
|
||||
import {
|
||||
ProductVariantInventoryService,
|
||||
ProductVariantService,
|
||||
} from "../../../../services"
|
||||
|
||||
import { EntityManager } from "typeorm"
|
||||
import { FindParams } from "../../../../types/common"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
import { IInventoryService } from "@medusajs/types"
|
||||
import { MedusaError } from "@medusajs/utils"
|
||||
import { createInventoryItemTransaction } from "./transaction/create-inventory-item"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
|
||||
/**
|
||||
* @oas [post] /admin/inventory-items
|
||||
@@ -221,6 +222,18 @@ export class AdminPostInventoryItemsReq {
|
||||
@IsOptional()
|
||||
material?: string
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
title?: string
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
description?: string
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
thumbnail?: string
|
||||
|
||||
@IsObject()
|
||||
@IsOptional()
|
||||
metadata?: Record<string, unknown>
|
||||
|
||||
+15
-8
@@ -1,11 +1,3 @@
|
||||
import { IInventoryService, InventoryItemDTO } from "@medusajs/types"
|
||||
import { MedusaError } from "@medusajs/utils"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import {
|
||||
ProductVariantInventoryService,
|
||||
ProductVariantService,
|
||||
} from "../../../../../services"
|
||||
import {
|
||||
DistributedTransaction,
|
||||
TransactionHandlerType,
|
||||
@@ -14,6 +6,15 @@ import {
|
||||
TransactionState,
|
||||
TransactionStepsDefinition,
|
||||
} from "../../../../../utils/transaction"
|
||||
import { IInventoryService, InventoryItemDTO } from "@medusajs/types"
|
||||
import {
|
||||
ProductVariantInventoryService,
|
||||
ProductVariantService,
|
||||
} from "../../../../../services"
|
||||
|
||||
import { EntityManager } from "typeorm"
|
||||
import { MedusaError } from "@medusajs/utils"
|
||||
import { ulid } from "ulid"
|
||||
|
||||
enum actions {
|
||||
createInventoryItem = "createInventoryItem",
|
||||
@@ -53,6 +54,9 @@ type CreateInventoryItemInput = {
|
||||
origin_country?: string
|
||||
mid_code?: string
|
||||
material?: string
|
||||
title?: string
|
||||
description?: string
|
||||
thumbnail?: string
|
||||
metadata?: Record<string, unknown>
|
||||
}
|
||||
|
||||
@@ -84,6 +88,9 @@ export const createInventoryItemTransaction = async (
|
||||
length: input.length,
|
||||
height: input.height,
|
||||
width: input.width,
|
||||
title: input.title,
|
||||
description: input.description,
|
||||
thumbnail: input.thumbnail,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { IInventoryService } from "@medusajs/types"
|
||||
import { IsBoolean, IsNumber, IsOptional, IsString } from "class-validator"
|
||||
import { Request, Response } from "express"
|
||||
|
||||
import { EntityManager } from "typeorm"
|
||||
import { FindParams } from "../../../../types/common"
|
||||
import { IInventoryService } from "@medusajs/types"
|
||||
|
||||
/**
|
||||
* @oas [post] /admin/inventory-items/{id}
|
||||
@@ -159,6 +160,18 @@ export class AdminPostInventoryItemsInventoryItemReq {
|
||||
@IsNumber()
|
||||
width?: number
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
title?: string
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
description?: string
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
thumbnail?: string
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
requires_shipping?: boolean
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { IsNumber, IsObject, IsOptional, IsString } from "class-validator"
|
||||
|
||||
import { IInventoryService } from "@medusajs/types"
|
||||
import { isDefined } from "@medusajs/utils"
|
||||
import { IsNumber, IsObject, IsOptional, IsString } from "class-validator"
|
||||
import { validateUpdateReservationQuantity } from "./utils/validate-reservation-quantity"
|
||||
|
||||
/**
|
||||
@@ -73,6 +74,8 @@ export default async (req, res) => {
|
||||
const inventoryService: IInventoryService =
|
||||
req.scope.resolve("inventoryService")
|
||||
|
||||
const userId: string = req.user.id || req.user.userId
|
||||
|
||||
if (isDefined(validatedBody.line_item_id)) {
|
||||
await validateUpdateReservationQuantity(
|
||||
validatedBody.line_item_id,
|
||||
@@ -84,9 +87,10 @@ export default async (req, res) => {
|
||||
)
|
||||
}
|
||||
|
||||
const reservation = await inventoryService.createReservationItem(
|
||||
validatedBody
|
||||
)
|
||||
const reservation = await inventoryService.createReservationItem({
|
||||
...validatedBody,
|
||||
created_by: userId,
|
||||
})
|
||||
|
||||
res.status(200).json({ reservation })
|
||||
}
|
||||
@@ -128,6 +132,10 @@ export class AdminPostReservationsReq {
|
||||
@IsNumber()
|
||||
quantity: number
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
description?: string
|
||||
|
||||
@IsObject()
|
||||
@IsOptional()
|
||||
metadata?: Record<string, unknown>
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { IInventoryService } from "@medusajs/types"
|
||||
import { isDefined } from "@medusajs/utils"
|
||||
import { IsNumber, IsObject, IsOptional, IsString } from "class-validator"
|
||||
|
||||
import { EntityManager } from "typeorm"
|
||||
import { IInventoryService } from "@medusajs/types"
|
||||
import { LineItemService } from "../../../../services"
|
||||
import { isDefined } from "@medusajs/utils"
|
||||
import { validateUpdateReservationQuantity } from "./utils/validate-reservation-quantity"
|
||||
|
||||
/**
|
||||
@@ -120,6 +121,10 @@ export class AdminPostReservationsReservationReq {
|
||||
@IsOptional()
|
||||
location_id?: string
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
description?: string
|
||||
|
||||
@IsObject()
|
||||
@IsOptional()
|
||||
metadata?: Record<string, unknown>
|
||||
|
||||
Reference in New Issue
Block a user