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:
8
.changeset/itchy-ligers-enjoy.md
Normal file
8
.changeset/itchy-ligers-enjoy.md
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
"@medusajs/client-types": patch
|
||||
"@medusajs/inventory": patch
|
||||
"@medusajs/medusa": patch
|
||||
"@medusajs/types": patch
|
||||
---
|
||||
|
||||
Feat(client-types, inventory, medusa, types): add `title`, `thumbnail` and `description to inventory item and `description` to reservation item.
|
||||
@@ -20,6 +20,18 @@ export interface InventoryItemDTO {
|
||||
* 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.
|
||||
*/
|
||||
mid_code?: string
|
||||
/**
|
||||
* Title of the inventory item
|
||||
*/
|
||||
title?: string
|
||||
/**
|
||||
* Description of the inventory item
|
||||
*/
|
||||
description?: string
|
||||
/**
|
||||
* Thumbnail for the inventory item
|
||||
*/
|
||||
thumbnail?: string
|
||||
/**
|
||||
* The material and composition that the Inventory Item is made of, May be used by Fulfillment Providers to pass customs information to shipping carriers.
|
||||
*/
|
||||
|
||||
@@ -19,6 +19,14 @@ export interface ReservationItemDTO {
|
||||
* The id of the inventory item the reservation relates to
|
||||
*/
|
||||
inventory_item_id: string
|
||||
/**
|
||||
* Description of the reservation item
|
||||
*/
|
||||
description?: string
|
||||
/**
|
||||
* UserId of user who created the reservation item
|
||||
*/
|
||||
created_by?: string
|
||||
/**
|
||||
* The id of the reservation item
|
||||
*/
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as setup from "./schema-migrations/1665748086258-inventory_setup"
|
||||
import * as addExternalId from "./schema-migrations/1675761451145-add_reservation_external_id"
|
||||
import * as descriptionsAndThumbnail from "./schema-migrations/1682927363119-item_descriptions_and_thumbnail"
|
||||
import * as setup from "./schema-migrations/1665748086258-inventory_setup"
|
||||
|
||||
export default [setup, addExternalId]
|
||||
export default [setup, addExternalId, descriptionsAndThumbnail]
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm"
|
||||
|
||||
export class itemDescriptionsAndThumbnail1682927363119
|
||||
implements MigrationInterface
|
||||
{
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE inventory_item
|
||||
ADD "title" character varying,
|
||||
ADD "description" character varying,
|
||||
ADD "thumbnail" character varying;
|
||||
`)
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE "reservation_item"
|
||||
ADD "description" character varying,
|
||||
ADD "created_by" character varying;
|
||||
`)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE reservation_item
|
||||
DROP COLUMN "title",
|
||||
DROP COLUMN "description",
|
||||
DROP COLUMN "thumbnail";
|
||||
`)
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE "reservation_item"
|
||||
DROP COLUMN "description",
|
||||
DROP COLUMN "created_by";
|
||||
`)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { generateEntityId, SoftDeletableEntity } from "@medusajs/utils"
|
||||
import { BeforeInsert, Column, Entity, Index } from "typeorm"
|
||||
import { SoftDeletableEntity, generateEntityId } from "@medusajs/utils"
|
||||
|
||||
@Entity()
|
||||
export class InventoryItem extends SoftDeletableEntity {
|
||||
@@ -34,6 +34,15 @@ export class InventoryItem extends SoftDeletableEntity {
|
||||
@Column({ default: true })
|
||||
requires_shipping: boolean
|
||||
|
||||
@Column({ type: "text", nullable: true })
|
||||
description: string | null
|
||||
|
||||
@Column({ type: "text", nullable: true })
|
||||
title: string | null
|
||||
|
||||
@Column({ type: "text", nullable: true })
|
||||
thumbnail: string | null
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { generateEntityId, SoftDeletableEntity } from "@medusajs/utils"
|
||||
import { BeforeInsert, Column, Entity, Index } from "typeorm"
|
||||
import { SoftDeletableEntity, generateEntityId } from "@medusajs/utils"
|
||||
|
||||
@Entity()
|
||||
export class ReservationItem extends SoftDeletableEntity {
|
||||
@@ -21,6 +21,12 @@ export class ReservationItem extends SoftDeletableEntity {
|
||||
@Column({ type: "text", nullable: true })
|
||||
external_id: string | null
|
||||
|
||||
@Column({ type: "text", nullable: true })
|
||||
description: string | null
|
||||
|
||||
@Column({ type: "text", nullable: true })
|
||||
created_by: string | null
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null
|
||||
|
||||
|
||||
@@ -135,6 +135,9 @@ export default class InventoryItemService {
|
||||
height: data.height,
|
||||
width: data.width,
|
||||
requires_shipping: data.requires_shipping,
|
||||
description: data.description,
|
||||
thumbnail: data.thumbnail,
|
||||
title: data.title,
|
||||
})
|
||||
|
||||
const result = await itemRepository.save(inventoryItem)
|
||||
|
||||
@@ -141,6 +141,8 @@ export default class ReservationItemService {
|
||||
quantity: data.quantity,
|
||||
metadata: data.metadata,
|
||||
external_id: data.external_id,
|
||||
description: data.description,
|
||||
created_by: data.created_by,
|
||||
})
|
||||
|
||||
const [newReservationItem] = await Promise.all([
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -21,6 +21,15 @@ import {
|
||||
* 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
|
||||
* title:
|
||||
* description: "Title of the inventory item"
|
||||
* type: string
|
||||
* description:
|
||||
* description: "Description of the inventory item"
|
||||
* type: string
|
||||
* thumbnail:
|
||||
* description: "Thumbnail for the inventory item"
|
||||
* 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
|
||||
@@ -68,6 +77,9 @@ export type InventoryItemDTO = {
|
||||
length?: number | null
|
||||
height?: number | null
|
||||
width?: number | null
|
||||
title?: string | null
|
||||
description?: string | null
|
||||
thumbnail?: string | null
|
||||
metadata?: Record<string, unknown> | null
|
||||
created_at: string | Date
|
||||
updated_at: string | Date
|
||||
@@ -94,6 +106,12 @@ export type InventoryItemDTO = {
|
||||
* inventory_item_id:
|
||||
* description: "The id of the inventory item the reservation relates to"
|
||||
* type: string
|
||||
* description:
|
||||
* description: "Description of the reservation item"
|
||||
* type: string
|
||||
* created_by:
|
||||
* description: "UserId of user who created the reservation item"
|
||||
* type: string
|
||||
* quantity:
|
||||
* description: "The id of the reservation item"
|
||||
* type: number
|
||||
@@ -120,6 +138,8 @@ export type ReservationItemDTO = {
|
||||
inventory_item_id: string
|
||||
quantity: number
|
||||
line_item_id?: string | null
|
||||
description?: string | null
|
||||
created_by?: string | null
|
||||
metadata: Record<string, unknown> | null
|
||||
created_at: string | Date
|
||||
updated_at: string | Date
|
||||
@@ -184,6 +204,8 @@ export type FilterableReservationItemProps = {
|
||||
line_item_id?: string | string[]
|
||||
inventory_item_id?: string | string[]
|
||||
location_id?: string | string[]
|
||||
description?: string
|
||||
created_by?: string | string[]
|
||||
quantity?: number | NumericalComparisonOperator
|
||||
}
|
||||
|
||||
@@ -206,6 +228,9 @@ export type CreateInventoryItemInput = {
|
||||
length?: number
|
||||
height?: number
|
||||
width?: number
|
||||
title?: string
|
||||
description?: string
|
||||
thumbnail?: string
|
||||
metadata?: Record<string, unknown> | null
|
||||
hs_code?: string
|
||||
requires_shipping?: boolean
|
||||
@@ -216,8 +241,10 @@ export type CreateReservationItemInput = {
|
||||
inventory_item_id: string
|
||||
location_id: string
|
||||
quantity: number
|
||||
metadata?: Record<string, unknown> | null
|
||||
description?: string
|
||||
created_by?: string
|
||||
external_id?: string
|
||||
metadata?: Record<string, unknown> | null
|
||||
}
|
||||
|
||||
export type FilterableInventoryLevelProps = {
|
||||
@@ -244,6 +271,7 @@ export type UpdateInventoryLevelInput = {
|
||||
export type UpdateReservationItemInput = {
|
||||
quantity?: number
|
||||
location_id?: string
|
||||
description?: string
|
||||
metadata?: Record<string, unknown> | null
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user