breaking: rename package names to be consistent and under @medusajs scope (#9580)

This commit is contained in:
Harminder Virk
2024-10-16 22:28:09 +05:30
committed by GitHub
parent cc1a25abb2
commit 68560787e5
289 changed files with 483 additions and 474 deletions

View File

@@ -0,0 +1,3 @@
export * from "./reservation-item"
export * from "./inventory-item"
export * from "./inventory-level"

View File

@@ -0,0 +1,156 @@
import {
createPsqlIndexStatementHelper,
DALUtils,
generateEntityId,
Searchable,
} from "@medusajs/framework/utils"
import {
BeforeCreate,
Collection,
Entity,
Filter,
Formula,
OneToMany,
OnInit,
OptionalProps,
PrimaryKey,
Property,
Rel,
} from "@mikro-orm/core"
import { DAL } from "@medusajs/framework/types"
import { InventoryLevel } from "./inventory-level"
import { ReservationItem } from "./reservation-item"
const InventoryItemDeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "inventory_item",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})
const InventoryItemSkuIndex = createPsqlIndexStatementHelper({
tableName: "inventory_item",
columns: "sku",
unique: true,
where: "deleted_at IS NULL",
})
type InventoryItemOptionalProps = DAL.SoftDeletableModelDateColumns
@Entity()
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export class InventoryItem {
[OptionalProps]: InventoryItemOptionalProps
@PrimaryKey({ columnType: "text" })
id: string
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Date
@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Date
@InventoryItemDeletedAtIndex.MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@InventoryItemSkuIndex.MikroORMIndex()
@Searchable()
@Property({ columnType: "text", nullable: true })
sku: string | null = null
@Property({ columnType: "text", nullable: true })
origin_country: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
hs_code: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
mid_code: string | null = null
@Property({ columnType: "text", nullable: true })
material: string | null = null
@Property({ type: "int", nullable: true })
weight: number | null = null
@Property({ type: "int", nullable: true })
length: number | null = null
@Property({ type: "int", nullable: true })
height: number | null = null
@Property({ type: "int", nullable: true })
width: number | null = null
@Property({ columnType: "boolean" })
requires_shipping: boolean = true
@Searchable()
@Property({ columnType: "text", nullable: true })
description: string | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
title: string | null = null
@Property({ columnType: "text", nullable: true })
thumbnail: string | null = null
@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null
@OneToMany(
() => InventoryLevel,
(inventoryLevel) => inventoryLevel.inventory_item,
{
cascade: ["soft-remove" as any],
}
)
location_levels = new Collection<Rel<InventoryLevel>>(this)
@OneToMany(
() => ReservationItem,
(reservationItem) => reservationItem.inventory_item,
{
cascade: ["soft-remove" as any],
}
)
reservation_items = new Collection<Rel<ReservationItem>>(this)
@Formula(
(item) =>
`(SELECT SUM(reserved_quantity) FROM inventory_level il WHERE il.inventory_item_id = ${item}.id AND il.deleted_at IS NULL)`,
{ lazy: true, serializer: Number, hidden: true }
)
reserved_quantity: number
@Formula(
(item) =>
`(SELECT SUM(stocked_quantity) FROM inventory_level il WHERE il.inventory_item_id = ${item}.id AND il.deleted_at IS NULL)`,
{ lazy: true, serializer: Number, hidden: true }
)
stocked_quantity: number
@BeforeCreate()
beforeCreate(): void {
this.id = generateEntityId(this.id, "iitem")
}
@OnInit()
onInit(): void {
this.id = generateEntityId(this.id, "iitem")
}
}

View File

@@ -0,0 +1,135 @@
import { DALUtils, isDefined, MathBN } from "@medusajs/framework/utils"
import {
BeforeCreate,
Entity,
Filter,
ManyToOne,
OnInit,
OnLoad,
PrimaryKey,
Property,
Rel,
} from "@mikro-orm/core"
import { BigNumberRawValue } from "@medusajs/framework/types"
import {
BigNumber,
createPsqlIndexStatementHelper,
generateEntityId,
MikroOrmBigNumberProperty,
} from "@medusajs/framework/utils"
import { InventoryItem } from "./inventory-item"
const InventoryLevelDeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "inventory_level",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})
const InventoryLevelInventoryItemIdIndex = createPsqlIndexStatementHelper({
tableName: "inventory_level",
columns: "inventory_item_id",
where: "deleted_at IS NULL",
})
const InventoryLevelLocationIdIndex = createPsqlIndexStatementHelper({
tableName: "inventory_level",
columns: "location_id",
where: "deleted_at IS NULL",
})
const InventoryLevelLocationIdInventoryItemIdIndex =
createPsqlIndexStatementHelper({
tableName: "inventory_level",
columns: ["inventory_item_id", "location_id"],
unique: true,
where: "deleted_at IS NULL",
})
@Entity()
@InventoryLevelLocationIdInventoryItemIdIndex.MikroORMIndex()
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export class InventoryLevel {
@PrimaryKey({ columnType: "text" })
id: string
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Date
@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Date
@InventoryLevelDeletedAtIndex.MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@ManyToOne(() => InventoryItem, {
fieldName: "inventory_item_id",
type: "text",
mapToPk: true,
onDelete: "cascade",
})
@InventoryLevelInventoryItemIdIndex.MikroORMIndex()
inventory_item_id: string
@InventoryLevelLocationIdIndex.MikroORMIndex()
@Property({ type: "text" })
location_id: string
@MikroOrmBigNumberProperty()
stocked_quantity: BigNumber | number = 0
@Property({ columnType: "jsonb" })
raw_stocked_quantity: BigNumberRawValue
@MikroOrmBigNumberProperty()
reserved_quantity: BigNumber | number = 0
@Property({ columnType: "jsonb" })
raw_reserved_quantity: BigNumberRawValue
@MikroOrmBigNumberProperty()
incoming_quantity: BigNumber | number = 0
@Property({ columnType: "jsonb" })
raw_incoming_quantity: BigNumberRawValue
@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null
@ManyToOne(() => InventoryItem, {
persist: false,
})
inventory_item: Rel<InventoryItem>
available_quantity: BigNumber | number | null = null
@BeforeCreate()
beforeCreate(): void {
this.id = generateEntityId(this.id, "ilev")
this.inventory_item_id ??= this.inventory_item?.id
}
@OnInit()
onInit(): void {
this.id = generateEntityId(this.id, "ilev")
}
@OnLoad()
onLoad(): void {
if (isDefined(this.stocked_quantity) && isDefined(this.reserved_quantity)) {
this.available_quantity = new BigNumber(
MathBN.sub(this.raw_stocked_quantity, this.raw_reserved_quantity)
)
}
}
}

View File

@@ -0,0 +1,122 @@
import {
BeforeCreate,
Entity,
Filter,
ManyToOne,
OnInit,
PrimaryKey,
Property,
Rel,
} from "@mikro-orm/core"
import { BigNumberRawValue } from "@medusajs/framework/types"
import {
BigNumber,
DALUtils,
MikroOrmBigNumberProperty,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/framework/utils"
import { InventoryItem } from "./inventory-item"
const ReservationItemDeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "reservation_item",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})
const ReservationItemLineItemIdIndex = createPsqlIndexStatementHelper({
tableName: "reservation_item",
columns: "line_item_id",
where: "deleted_at IS NULL",
})
const ReservationItemInventoryItemIdIndex = createPsqlIndexStatementHelper({
tableName: "reservation_item",
columns: "inventory_item_id",
where: "deleted_at IS NULL",
})
const ReservationItemLocationIdIndex = createPsqlIndexStatementHelper({
tableName: "reservation_item",
columns: "location_id",
where: "deleted_at IS NULL",
})
@Entity()
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export class ReservationItem {
@PrimaryKey({ columnType: "text" })
id: string
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Date
@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Date
@ReservationItemDeletedAtIndex.MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@ReservationItemLineItemIdIndex.MikroORMIndex()
@Property({ type: "text", nullable: true })
line_item_id: string | null = null
@Property({ type: "boolean" })
allow_backorder: boolean = false
@ReservationItemLocationIdIndex.MikroORMIndex()
@Property({ type: "text" })
location_id: string
@MikroOrmBigNumberProperty()
quantity: BigNumber | number
@Property({ columnType: "jsonb" })
raw_quantity: BigNumberRawValue
@Property({ type: "text", nullable: true })
external_id: string | null = null
@Property({ type: "text", nullable: true })
description: string | null = null
@Property({ type: "text", nullable: true })
created_by: string | null = null
@Property({ type: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null
@ReservationItemInventoryItemIdIndex.MikroORMIndex()
@ManyToOne(() => InventoryItem, {
fieldName: "inventory_item_id",
type: "text",
mapToPk: true,
onDelete: "cascade",
})
inventory_item_id: string
@ManyToOne(() => InventoryItem, {
persist: false,
})
inventory_item: Rel<InventoryItem>
@BeforeCreate()
beforeCreate(): void {
this.id = generateEntityId(this.id, "resitem")
}
@OnInit()
onInit(): void {
this.id = generateEntityId(this.id, "resitem")
}
}