1 import { ModuleJoinerConfig } from "@medusajs/framework/types"
2 import { LINKS, Modules } from "@medusajs/framework/utils"
3
4 export const ProductVariantInventoryItem: ModuleJoinerConfig = {
5 serviceName: LINKS.ProductVariantInventoryItem,
6 isLink: true,
7 databaseConfig: {
8 tableName: "product_variant_inventory_item",
9 idPrefix: "pvitem",
10 extraFields: {
11 required_quantity: {
12 type: "decimal",
13 defaultValue: "1",
14 options: {
15 // unconstrained numeric, hydrated as a JS number (same shape the
16 // inventory module exposes for its bigNumber quantity columns)
17 columnType: "numeric",
18 runtimeType: "number",
19 },
20 },
21 },
22 },
23 alias: [
24 {
25 name: [
26 "product_variant_inventory_item",
27 "product_variant_inventory_items",
28 ],
29 entity: "LinkProductVariantInventoryItem",
30 },
31 ],
32 primaryKeys: ["id", "variant_id", "inventory_item_id"],
33 relationships: [
34 {
35 serviceName: Modules.PRODUCT,
36 entity: "ProductVariant",
37 primaryKey: "id",
38 foreignKey: "variant_id",
39 alias: "variant",
40 args: {
41 methodSuffix: "ProductVariants",
42 },
43 hasMany: true,
44 },
45 {
46 serviceName: Modules.INVENTORY,
47 entity: "InventoryItem",
48 primaryKey: "id",
49 foreignKey: "inventory_item_id",
50 alias: "inventory",
51 args: {
52 methodSuffix: "InventoryItems",
53 },
54 hasMany: true,
55 },
56 ],
57 extends: [
58 {
59 serviceName: Modules.PRODUCT,
60 entity: "ProductVariant",
61 fieldAlias: {
62 inventory: "inventory_items.inventory",
63 },
64 relationship: {
65 serviceName: LINKS.ProductVariantInventoryItem,
66 primaryKey: "variant_id",
67 foreignKey: "id",
68 alias: "inventory_items",
69 isList: true,
70 },
71 },
72 {
73 serviceName: Modules.INVENTORY,
74 entity: "InventoryItem",
75 fieldAlias: {
76 variants: {
77 path: "variant_link.variant",
78 isList: true,
79 },
80 },
81 relationship: {
82 serviceName: LINKS.ProductVariantInventoryItem,
83 primaryKey: "inventory_item_id",
84 foreignKey: "id",
85 alias: "variant_link",
86 isList: true,
87 },
88 },
89 ],
90 }