feat(medusa, medusa-plugin-brightpearl): Inventory management for Brightpearl (#3192)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import * as setup from "./schema-migrations/1665748086258-inventory_setup"
|
||||
import * as addExternalId from "./schema-migrations/1675761451145-add_reservation_external_id"
|
||||
|
||||
export default [setup]
|
||||
export default [setup, addExternalId]
|
||||
|
||||
@@ -26,7 +26,6 @@ export class inventorySetup1665748086258 implements MigrationInterface {
|
||||
|
||||
CREATE UNIQUE INDEX "IDX_inventory_item_sku" ON "inventory_item" ("sku") WHERE deleted_at IS NULL;
|
||||
|
||||
|
||||
CREATE TABLE "reservation_item" (
|
||||
"id" character varying NOT NULL,
|
||||
"created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm"
|
||||
|
||||
export class addReservationType1675761451145 implements MigrationInterface {
|
||||
name = "addReservationType1675761451145"
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE "reservation_item" ADD "external_id" character varying
|
||||
`)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE "reservation_item" DROP COLUMN "external_id";
|
||||
`)
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from "./reservation-item"
|
||||
export {ReservationItem} from "./reservation-item"
|
||||
export * from "./inventory-item"
|
||||
export * from "./inventory-level"
|
||||
|
||||
@@ -18,6 +18,9 @@ export class ReservationItem extends SoftDeletableEntity {
|
||||
@Column()
|
||||
quantity: number
|
||||
|
||||
@Column({ type: "text", nullable: true })
|
||||
external_id: string | null
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null
|
||||
|
||||
|
||||
@@ -132,18 +132,19 @@ export default class ReservationItemService {
|
||||
@MedusaContext() context: SharedContext = {}
|
||||
): Promise<ReservationItem> {
|
||||
const manager = context.transactionManager!
|
||||
const itemRepository = manager.getRepository(ReservationItem)
|
||||
const reservationItemRepository = manager.getRepository(ReservationItem)
|
||||
|
||||
const inventoryItem = itemRepository.create({
|
||||
const reservationItem = reservationItemRepository.create({
|
||||
inventory_item_id: data.inventory_item_id,
|
||||
line_item_id: data.line_item_id,
|
||||
location_id: data.location_id,
|
||||
quantity: data.quantity,
|
||||
metadata: data.metadata,
|
||||
external_id: data.external_id,
|
||||
})
|
||||
|
||||
const [newInventoryItem] = await Promise.all([
|
||||
itemRepository.save(inventoryItem),
|
||||
const [newReservationItem] = await Promise.all([
|
||||
reservationItemRepository.save(reservationItem),
|
||||
this.inventoryLevelService_.adjustReservedQuantity(
|
||||
data.inventory_item_id,
|
||||
data.location_id,
|
||||
@@ -153,10 +154,10 @@ export default class ReservationItemService {
|
||||
])
|
||||
|
||||
await this.eventBusService_?.emit?.(ReservationItemService.Events.CREATED, {
|
||||
id: newInventoryItem.id,
|
||||
id: newReservationItem.id,
|
||||
})
|
||||
|
||||
return newInventoryItem
|
||||
return newReservationItem
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user