feat: Line Items API Routes (#6478)
**What** - `POST /store/carts/:id/line-items` - `POST /store/carts/:id/line-items/:id` - `DELETE /store/carts/:id/line-items/:id` **Outstanding** - Integration tests - Module integrations: Payment, Fulfillment, Promotions Depends on #6475 and #6449.
This commit is contained in:
1 parent
f5c2256286
commit
3ee0f599c1
30 files changed
+937
-208
No files matched your search
@@ -658,6 +658,15 @@
|
||||
"nullable": false,
|
||||
"mappedType": "json"
|
||||
},
|
||||
"metadata": {
|
||||
"name": "metadata",
|
||||
"type": "jsonb",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "json"
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamptz",
|
||||
@@ -798,6 +807,15 @@
|
||||
"nullable": false,
|
||||
"mappedType": "decimal"
|
||||
},
|
||||
"raw_amount": {
|
||||
"name": "raw_amount",
|
||||
"type": "jsonb",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"mappedType": "json"
|
||||
},
|
||||
"provider_id": {
|
||||
"name": "provider_id",
|
||||
"type": "text",
|
||||
@@ -807,6 +825,15 @@
|
||||
"nullable": true,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"metadata": {
|
||||
"name": "metadata",
|
||||
"type": "jsonb",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "json"
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamptz",
|
||||
@@ -957,6 +984,15 @@
|
||||
"nullable": true,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"metadata": {
|
||||
"name": "metadata",
|
||||
"type": "jsonb",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "json"
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamptz",
|
||||
@@ -1283,6 +1319,15 @@
|
||||
"nullable": false,
|
||||
"mappedType": "decimal"
|
||||
},
|
||||
"raw_amount": {
|
||||
"name": "raw_amount",
|
||||
"type": "jsonb",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"mappedType": "json"
|
||||
},
|
||||
"provider_id": {
|
||||
"name": "provider_id",
|
||||
"type": "text",
|
||||
@@ -1323,6 +1368,15 @@
|
||||
"nullable": false,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"metadata": {
|
||||
"name": "metadata",
|
||||
"type": "jsonb",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "json"
|
||||
},
|
||||
"promotion_id": {
|
||||
"name": "promotion_id",
|
||||
"type": "text",
|
||||
@@ -1436,6 +1490,15 @@
|
||||
"nullable": true,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"metadata": {
|
||||
"name": "metadata",
|
||||
"type": "jsonb",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "json"
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamptz",
|
||||
@@ -1534,4 +1597,4 @@
|
||||
"foreignKeys": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -85,6 +85,7 @@ export class Migration20240222170223 extends Migration {
|
||||
"raw_compare_at_unit_price" JSONB NULL,
|
||||
"unit_price" NUMERIC NOT NULL,
|
||||
"raw_unit_price" JSONB NOT NULL,
|
||||
"metadata" JSONB NULL,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
"deleted_at" TIMESTAMPTZ NULL,
|
||||
@@ -106,7 +107,9 @@ export class Migration20240222170223 extends Migration {
|
||||
"promotion_id" TEXT NULL,
|
||||
"code" TEXT NULL,
|
||||
"amount" NUMERIC NOT NULL,
|
||||
"raw_amount" JSONB NOT NULL,
|
||||
"provider_id" TEXT NULL,
|
||||
"metadata" JSONB NULL,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
"deleted_at" TIMESTAMPTZ NULL,
|
||||
@@ -125,6 +128,7 @@ export class Migration20240222170223 extends Migration {
|
||||
"code" TEXT NOT NULL,
|
||||
"rate" NUMERIC NOT NULL,
|
||||
"provider_id" TEXT NULL,
|
||||
"metadata" JSONB NULL,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
"deleted_at" TIMESTAMPTZ NULL,
|
||||
@@ -162,7 +166,9 @@ export class Migration20240222170223 extends Migration {
|
||||
"promotion_id" TEXT NULL,
|
||||
"code" TEXT NULL,
|
||||
"amount" NUMERIC NOT NULL,
|
||||
"raw_amount" JSONB NOT NULL,
|
||||
"provider_id" TEXT NULL,
|
||||
"metadata" JSONB NULL,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
"deleted_at" TIMESTAMPTZ NULL,
|
||||
@@ -180,6 +186,7 @@ export class Migration20240222170223 extends Migration {
|
||||
"code" TEXT NOT NULL,
|
||||
"rate" NUMERIC NOT NULL,
|
||||
"provider_id" TEXT NULL,
|
||||
"metadata" JSONB NULL,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
"deleted_at" TIMESTAMPTZ NULL,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import { BigNumber, MikroOrmBigNumberProperty } from "@medusajs/utils"
|
||||
import { OptionalProps, PrimaryKey, Property } from "@mikro-orm/core"
|
||||
|
||||
type OptionalAdjustmentLineProps = DAL.SoftDeletableEntityDateColumns
|
||||
@@ -19,12 +20,18 @@ export default abstract class AdjustmentLine {
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
code: string | null = null
|
||||
|
||||
@Property({ columnType: "numeric", serializer: Number })
|
||||
amount: number
|
||||
@MikroOrmBigNumberProperty()
|
||||
amount: BigNumber | number
|
||||
|
||||
@Property({ columnType: "jsonb" })
|
||||
raw_amount: Record<string, unknown>
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
provider_id: string | null = null
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null = null
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
|
||||
@@ -26,6 +26,54 @@ type OptionalCartProps =
|
||||
| "billing_address"
|
||||
| DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const RegionIdIndex = createPsqlIndexStatementHelper({
|
||||
name: "IDX_cart_region_id",
|
||||
tableName: "cart",
|
||||
columns: "region_id",
|
||||
where: "deleted_at IS NULL AND region_id IS NOT NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
const CustomerIdIndex = createPsqlIndexStatementHelper({
|
||||
name: "IDX_cart_customer_id",
|
||||
tableName: "cart",
|
||||
columns: "customer_id",
|
||||
where: "deleted_at IS NULL AND customer_id IS NOT NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
const SalesChannelIdIndex = createPsqlIndexStatementHelper({
|
||||
name: "IDX_cart_sales_channel_id",
|
||||
tableName: "cart",
|
||||
columns: "sales_channel_id",
|
||||
where: "deleted_at IS NULL AND sales_channel_id IS NOT NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
const CurrencyCodeIndex = createPsqlIndexStatementHelper({
|
||||
name: "IDX_cart_curency_code",
|
||||
tableName: "cart",
|
||||
columns: "currency_code",
|
||||
where: "deleted_at IS NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
const ShippingAddressIdIndex = createPsqlIndexStatementHelper({
|
||||
name: "IDX_cart_shipping_address_id",
|
||||
tableName: "cart",
|
||||
columns: "shipping_address_id",
|
||||
where: "deleted_at IS NULL AND shipping_address_id IS NOT NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
const BillingAddressIdIndex = createPsqlIndexStatementHelper({
|
||||
name: "IDX_cart_billing_address_id",
|
||||
tableName: "cart",
|
||||
columns: "billing_address_id",
|
||||
where: "deleted_at IS NULL AND billing_address_id IS NOT NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
const DeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "cart",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
@Entity({ tableName: "cart" })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class Cart {
|
||||
@@ -34,77 +82,56 @@ export default class Cart {
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
name: "IDX_cart_region_id",
|
||||
tableName: "cart",
|
||||
columns: "region_id",
|
||||
where: "deleted_at IS NULL AND region_id IS NOT NULL",
|
||||
}).MikroORMIndex()
|
||||
@RegionIdIndex()
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
region_id: string | null = null
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
name: "IDX_cart_customer_id",
|
||||
tableName: "cart",
|
||||
columns: "customer_id",
|
||||
where: "deleted_at IS NULL AND customer_id IS NOT NULL",
|
||||
}).MikroORMIndex()
|
||||
@CustomerIdIndex()
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
customer_id: string | null = null
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
name: "IDX_cart_sales_channel_id",
|
||||
tableName: "cart",
|
||||
columns: "sales_channel_id",
|
||||
where: "deleted_at IS NULL AND sales_channel_id IS NOT NULL",
|
||||
}).MikroORMIndex()
|
||||
@Property({
|
||||
columnType: "text",
|
||||
nullable: true,
|
||||
index: "IDX_cart_sales_channel_id",
|
||||
})
|
||||
@SalesChannelIdIndex()
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
sales_channel_id: string | null = null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
email: string | null = null
|
||||
|
||||
@Property({ columnType: "text", index: "IDX_cart_curency_code" })
|
||||
@CurrencyCodeIndex()
|
||||
@Property({ columnType: "text" })
|
||||
currency_code: string
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
name: "IDX_cart_shipping_address_id",
|
||||
tableName: "cart",
|
||||
columns: "shipping_address_id",
|
||||
where: "deleted_at IS NULL AND shipping_address_id IS NOT NULL",
|
||||
}).MikroORMIndex()
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
shipping_address_id?: string | null
|
||||
|
||||
@ShippingAddressIdIndex()
|
||||
@ManyToOne({
|
||||
entity: () => Address,
|
||||
columnType: "text",
|
||||
fieldName: "shipping_address_id",
|
||||
mapToPk: true,
|
||||
nullable: true,
|
||||
cascade: [Cascade.PERSIST],
|
||||
})
|
||||
shipping_address?: Address | null
|
||||
shipping_address_id: string | null
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
name: "IDX_cart_billing_address_id",
|
||||
tableName: "cart",
|
||||
columns: "billing_address_id",
|
||||
where: "deleted_at IS NULL AND billing_address_id IS NOT NULL",
|
||||
}).MikroORMIndex()
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
billing_address_id?: string | null
|
||||
@ManyToOne(() => Address, {
|
||||
cascade: [Cascade.PERSIST],
|
||||
nullable: true,
|
||||
})
|
||||
shipping_address: Address | null
|
||||
|
||||
@BillingAddressIdIndex()
|
||||
@ManyToOne({
|
||||
entity: () => Address,
|
||||
columnType: "text",
|
||||
fieldName: "billing_address_id",
|
||||
mapToPk: true,
|
||||
nullable: true,
|
||||
index: "IDX_cart_billing_address_id",
|
||||
cascade: [Cascade.PERSIST],
|
||||
})
|
||||
billing_address?: Address | null
|
||||
billing_address_id: string | null
|
||||
|
||||
@ManyToOne(() => Address, {
|
||||
cascade: [Cascade.PERSIST],
|
||||
nullable: true,
|
||||
})
|
||||
billing_address: Address | null
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null = null
|
||||
@@ -134,11 +161,7 @@ export default class Cart {
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
tableName: "cart",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
}).MikroORMIndex()
|
||||
@DeletedAtIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Check,
|
||||
Entity,
|
||||
Filter,
|
||||
@@ -16,41 +15,49 @@ import {
|
||||
import AdjustmentLine from "./adjustment-line"
|
||||
import LineItem from "./line-item"
|
||||
|
||||
const LineItemIdIndex = createPsqlIndexStatementHelper({
|
||||
name: "IDX_adjustment_item_id",
|
||||
tableName: "cart_line_item_adjustment",
|
||||
columns: "item_id",
|
||||
where: "deleted_at IS NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
const PromotionIdIndex = createPsqlIndexStatementHelper({
|
||||
name: "IDX_line_item_adjustment_promotion_id",
|
||||
tableName: "cart_line_item_adjustment",
|
||||
columns: "promotion_id",
|
||||
where: "deleted_at IS NULL AND promotion_id IS NOT NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
const DeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "cart_line_item_adjustment",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
@Entity({ tableName: "cart_line_item_adjustment" })
|
||||
@Check<LineItemAdjustment>({
|
||||
expression: (columns) => `${columns.amount} >= 0`,
|
||||
})
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class LineItemAdjustment extends AdjustmentLine {
|
||||
@ManyToOne({
|
||||
entity: () => LineItem,
|
||||
cascade: [Cascade.REMOVE, Cascade.PERSIST],
|
||||
})
|
||||
@ManyToOne({ entity: () => LineItem, persist: false })
|
||||
item: LineItem
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
name: "IDX_adjustment_item_id",
|
||||
tableName: "cart_line_item_adjustment",
|
||||
columns: "item_id",
|
||||
where: "deleted_at IS NULL",
|
||||
}).MikroORMIndex()
|
||||
@Property({ columnType: "text" })
|
||||
@LineItemIdIndex()
|
||||
@ManyToOne({
|
||||
entity: () => LineItem,
|
||||
columnType: "text",
|
||||
fieldName: "item_id",
|
||||
mapToPk: true,
|
||||
})
|
||||
item_id: string
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
name: "IDX_line_item_adjustment_promotion_id",
|
||||
tableName: "cart_line_item_adjustment",
|
||||
columns: "promotion_id",
|
||||
where: "deleted_at IS NULL and promotion_id IS NOT NULL",
|
||||
}).MikroORMIndex()
|
||||
@PromotionIdIndex()
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
promotion_id: string | null = null
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
tableName: "cart_line_item_adjustment",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
}).MikroORMIndex()
|
||||
@DeletedAtIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
@@ -15,38 +14,46 @@ import {
|
||||
import LineItem from "./line-item"
|
||||
import TaxLine from "./tax-line"
|
||||
|
||||
const LineItemIdIndex = createPsqlIndexStatementHelper({
|
||||
name: "IDX_tax_line_item_id",
|
||||
tableName: "cart_line_item_tax_line",
|
||||
columns: "item_id",
|
||||
where: "deleted_at IS NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
const TaxRateIdIndex = createPsqlIndexStatementHelper({
|
||||
name: "IDX_line_item_tax_line_tax_rate_id",
|
||||
tableName: "cart_line_item_tax_line",
|
||||
columns: "tax_rate_id",
|
||||
where: "deleted_at IS NULL AND tax_rate_id IS NOT NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
const DeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "cart_line_item_tax_line",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
@Entity({ tableName: "cart_line_item_tax_line" })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class LineItemTaxLine extends TaxLine {
|
||||
@ManyToOne({
|
||||
entity: () => LineItem,
|
||||
cascade: [Cascade.REMOVE, Cascade.PERSIST, "soft-remove"] as any,
|
||||
})
|
||||
@ManyToOne({ entity: () => LineItem, persist: false })
|
||||
item: LineItem
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
name: "IDX_tax_line_item_id",
|
||||
tableName: "cart_line_item_tax_line",
|
||||
columns: "item_id",
|
||||
where: "deleted_at IS NULL",
|
||||
}).MikroORMIndex()
|
||||
@Property({ columnType: "text" })
|
||||
@LineItemIdIndex()
|
||||
@ManyToOne({
|
||||
entity: () => LineItem,
|
||||
columnType: "text",
|
||||
fieldName: "item_id",
|
||||
mapToPk: true,
|
||||
})
|
||||
item_id: string
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
name: "IDX_line_item_tax_line_tax_rate_id",
|
||||
tableName: "cart_line_item_tax_line",
|
||||
columns: "tax_rate_id",
|
||||
where: "deleted_at IS NULL AND tax_rate_id IS NOT NULL",
|
||||
}).MikroORMIndex()
|
||||
@TaxRateIdIndex()
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
tax_rate_id: string | null = null
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
tableName: "cart_line_item_tax_line",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
}).MikroORMIndex()
|
||||
@DeletedAtIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
OneToMany,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
Property
|
||||
} from "@mikro-orm/core"
|
||||
import Cart from "./cart"
|
||||
import LineItemAdjustment from "./line-item-adjustment"
|
||||
@@ -31,6 +31,33 @@ type OptionalLineItemProps =
|
||||
| "cart"
|
||||
| DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const CartIdIndex = createPsqlIndexStatementHelper({
|
||||
name: "IDX_line_item_cart_id",
|
||||
tableName: "cart_line_item",
|
||||
columns: "cart_id",
|
||||
where: "deleted_at IS NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
const VariantIdIndex = createPsqlIndexStatementHelper({
|
||||
name: "IDX_line_item_variant_id",
|
||||
tableName: "cart_line_item",
|
||||
columns: "variant_id",
|
||||
where: "deleted_at IS NULL AND variant_id IS NOT NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
const ProductIdIndex = createPsqlIndexStatementHelper({
|
||||
name: "IDX_line_item_product_id",
|
||||
tableName: "cart_line_item",
|
||||
columns: "product_id",
|
||||
where: "deleted_at IS NULL AND product_id IS NOT NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
const DeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "cart_line_item",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
@Entity({ tableName: "cart_line_item" })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class LineItem {
|
||||
@@ -39,19 +66,16 @@ export default class LineItem {
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
name: "IDX_line_item_cart_id",
|
||||
tableName: "cart_line_item",
|
||||
columns: "cart_id",
|
||||
where: "deleted_at IS NULL",
|
||||
}).MikroORMIndex()
|
||||
@Property({ columnType: "text" })
|
||||
cart_id: string
|
||||
|
||||
@CartIdIndex()
|
||||
@ManyToOne({
|
||||
entity: () => Cart,
|
||||
cascade: [Cascade.REMOVE, Cascade.PERSIST, "soft-remove"] as any,
|
||||
columnType: "text",
|
||||
fieldName: "cart_id",
|
||||
mapToPk: true,
|
||||
})
|
||||
cart_id: string
|
||||
|
||||
@ManyToOne({ entity: () => Cart, persist: false })
|
||||
cart: Cart
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
@@ -66,21 +90,11 @@ export default class LineItem {
|
||||
@Property({ columnType: "integer" })
|
||||
quantity: number
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
name: "IDX_line_item_variant_id",
|
||||
tableName: "cart_line_item",
|
||||
columns: "variant_id",
|
||||
where: "deleted_at IS NULL AND variant_id IS NOT NULL",
|
||||
}).MikroORMIndex()
|
||||
@VariantIdIndex()
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
variant_id: string | null = null
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
name: "IDX_line_item_product_id",
|
||||
tableName: "cart_line_item",
|
||||
columns: "product_id",
|
||||
where: "deleted_at IS NULL AND product_id IS NOT NULL",
|
||||
}).MikroORMIndex()
|
||||
@ProductIdIndex()
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
product_id: string | null = null
|
||||
|
||||
@@ -145,6 +159,9 @@ export default class LineItem {
|
||||
})
|
||||
adjustments = new Collection<LineItemAdjustment>(this)
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null = null
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
@@ -160,11 +177,7 @@ export default class LineItem {
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
tableName: "cart_line_item",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
}).MikroORMIndex()
|
||||
@DeletedAtIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
@@ -15,38 +14,46 @@ import {
|
||||
import AdjustmentLine from "./adjustment-line"
|
||||
import ShippingMethod from "./shipping-method"
|
||||
|
||||
const ShippingMethodIdIndex = createPsqlIndexStatementHelper({
|
||||
name: "IDX_adjustment_shipping_method_id",
|
||||
tableName: "cart_shipping_method_adjustment",
|
||||
columns: "shipping_method_id",
|
||||
where: "deleted_at IS NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
const PromotionIdIndex = createPsqlIndexStatementHelper({
|
||||
name: "IDX_shipping_method_adjustment_promotion_id",
|
||||
tableName: "cart_shipping_method_adjustment",
|
||||
columns: "promotion_id",
|
||||
where: "deleted_at IS NULL AND promotion_id IS NOT NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
const DeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "cart_shipping_method_adjustment",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
@Entity({ tableName: "cart_shipping_method_adjustment" })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class ShippingMethodAdjustment extends AdjustmentLine {
|
||||
@ManyToOne({
|
||||
entity: () => ShippingMethod,
|
||||
cascade: [Cascade.REMOVE, Cascade.PERSIST],
|
||||
})
|
||||
@ManyToOne({ entity: () => ShippingMethod, persist: false })
|
||||
shipping_method: ShippingMethod
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
name: "IDX_adjustment_shipping_method_id",
|
||||
tableName: "cart_shipping_method_adjustment",
|
||||
columns: "shipping_method_id",
|
||||
where: "deleted_at IS NULL",
|
||||
}).MikroORMIndex()
|
||||
@Property({ columnType: "text" })
|
||||
@ShippingMethodIdIndex()
|
||||
@ManyToOne({
|
||||
entity: () => ShippingMethod,
|
||||
columnType: "text",
|
||||
fieldName: "shipping_method_id",
|
||||
mapToPk: true,
|
||||
})
|
||||
shipping_method_id: string
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
name: "IDX_shipping_method_adjustment_promotion_id",
|
||||
tableName: "cart_shipping_method_adjustment",
|
||||
columns: "promotion_id",
|
||||
where: "deleted_at IS NULL and promotion_id IS NOT NULL",
|
||||
}).MikroORMIndex()
|
||||
@PromotionIdIndex()
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
promotion_id: string | null = null
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
tableName: "cart_shipping_method_adjustment",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
}).MikroORMIndex()
|
||||
@DeletedAtIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
@@ -15,38 +14,46 @@ import {
|
||||
import ShippingMethod from "./shipping-method"
|
||||
import TaxLine from "./tax-line"
|
||||
|
||||
const ShippingMethodIdIndex = createPsqlIndexStatementHelper({
|
||||
name: "IDX_tax_line_shipping_method_id",
|
||||
tableName: "cart_shipping_method_tax_line",
|
||||
columns: "shipping_method_id",
|
||||
where: "deleted_at IS NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
const TaxRateIdIndex = createPsqlIndexStatementHelper({
|
||||
name: "IDX_shipping_method_tax_line_tax_rate_id",
|
||||
tableName: "cart_shipping_method_tax_line",
|
||||
columns: "tax_rate_id",
|
||||
where: "deleted_at IS NULL AND tax_rate_id IS NOT NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
const DeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "cart_shipping_method_tax_line",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
@Entity({ tableName: "cart_shipping_method_tax_line" })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class ShippingMethodTaxLine extends TaxLine {
|
||||
@ManyToOne({
|
||||
entity: () => ShippingMethod,
|
||||
cascade: [Cascade.REMOVE, Cascade.PERSIST, "soft-remove"] as any,
|
||||
})
|
||||
@ManyToOne({ entity: () => ShippingMethod, persist: false })
|
||||
shipping_method: ShippingMethod
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
name: "IDX_tax_line_shipping_method_id",
|
||||
tableName: "cart_shipping_method_tax_line",
|
||||
columns: "shipping_method_id",
|
||||
where: "deleted_at IS NULL",
|
||||
}).MikroORMIndex()
|
||||
@Property({ columnType: "text" })
|
||||
@ShippingMethodIdIndex()
|
||||
@ManyToOne({
|
||||
entity: () => ShippingMethod,
|
||||
columnType: "text",
|
||||
fieldName: "shipping_method_id",
|
||||
mapToPk: true,
|
||||
})
|
||||
shipping_method_id: string
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
name: "IDX_shipping_method_tax_line_tax_rate_id",
|
||||
tableName: "cart_shipping_method_tax_line",
|
||||
columns: "tax_rate_id",
|
||||
where: "deleted_at IS NULL AND tax_rate_id IS NOT NULL",
|
||||
}).MikroORMIndex()
|
||||
@TaxRateIdIndex()
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
tax_rate_id: string | null = null
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
tableName: "cart_shipping_method_tax_line",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
}).MikroORMIndex()
|
||||
@DeletedAtIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
|
||||
@@ -29,6 +29,26 @@ type OptionalShippingMethodProps =
|
||||
| "is_tax_inclusive"
|
||||
| DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const CartIdIndex = createPsqlIndexStatementHelper({
|
||||
name: "IDX_shipping_method_cart_id",
|
||||
tableName: "cart_shipping_method",
|
||||
columns: "cart_id",
|
||||
where: "deleted_at IS NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
const ShippingOptionIdIndex = createPsqlIndexStatementHelper({
|
||||
name: "IDX_shipping_method_option_id",
|
||||
tableName: "cart_shipping_method",
|
||||
columns: "shipping_option_id",
|
||||
where: "deleted_at IS NULL AND shipping_option_id IS NOT NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
const DeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "cart_shipping_method",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
}).MikroORMIndex
|
||||
|
||||
@Entity({ tableName: "cart_shipping_method" })
|
||||
@Check<ShippingMethod>({ expression: (columns) => `${columns.amount} >= 0` })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
@@ -38,19 +58,16 @@ export default class ShippingMethod {
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
name: "IDX_shipping_method_cart_id",
|
||||
tableName: "cart_shipping_method",
|
||||
columns: "cart_id",
|
||||
where: "deleted_at IS NULL",
|
||||
}).MikroORMIndex()
|
||||
@Property({ columnType: "text" })
|
||||
cart_id: string
|
||||
|
||||
@CartIdIndex()
|
||||
@ManyToOne({
|
||||
entity: () => Cart,
|
||||
cascade: [Cascade.REMOVE, Cascade.PERSIST],
|
||||
columnType: "text",
|
||||
fieldName: "cart_id",
|
||||
mapToPk: true,
|
||||
})
|
||||
cart_id: string
|
||||
|
||||
@ManyToOne({ entity: () => Cart, persist: false })
|
||||
cart: Cart
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
@@ -68,12 +85,7 @@ export default class ShippingMethod {
|
||||
@Property({ columnType: "boolean" })
|
||||
is_tax_inclusive = false
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
name: "IDX_shipping_method_option_id",
|
||||
tableName: "cart_shipping_method",
|
||||
columns: "shipping_option_id",
|
||||
where: "deleted_at IS NULL AND shipping_option_id IS NOT NULL",
|
||||
}).MikroORMIndex()
|
||||
@ShippingOptionIdIndex()
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
shipping_option_id: string | null = null
|
||||
|
||||
@@ -116,11 +128,7 @@ export default class ShippingMethod {
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@createPsqlIndexStatementHelper({
|
||||
tableName: "cart_shipping_method",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
}).MikroORMIndex()
|
||||
@DeletedAtIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
|
||||
@@ -25,6 +25,9 @@ export default abstract class TaxLine {
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
provider_id?: string | null
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null = null
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
|
||||
@@ -450,7 +450,7 @@ export default class CartModuleService<
|
||||
: [itemIdsOrSelector]
|
||||
}
|
||||
|
||||
await this.lineItemService_.delete(toDelete, sharedContext)
|
||||
await this.lineItemService_.softDelete(toDelete, sharedContext)
|
||||
}
|
||||
|
||||
async createAddresses(
|
||||
@@ -636,7 +636,7 @@ export default class CartModuleService<
|
||||
? methodIdsOrSelector
|
||||
: [methodIdsOrSelector]
|
||||
}
|
||||
await this.shippingMethodService_.delete(toDelete, sharedContext)
|
||||
await this.shippingMethodService_.softDelete(toDelete, sharedContext)
|
||||
}
|
||||
|
||||
async addLineItemAdjustments(
|
||||
@@ -736,7 +736,7 @@ export default class CartModuleService<
|
||||
})
|
||||
|
||||
if (toDelete.length) {
|
||||
await this.lineItemAdjustmentService_.delete(
|
||||
await this.lineItemAdjustmentService_.softDelete(
|
||||
toDelete.map((adj) => adj!.id),
|
||||
sharedContext
|
||||
)
|
||||
@@ -791,7 +791,7 @@ export default class CartModuleService<
|
||||
: [adjustmentIdsOrSelector]
|
||||
}
|
||||
|
||||
await this.lineItemAdjustmentService_.delete(ids, sharedContext)
|
||||
await this.lineItemAdjustmentService_.softDelete(ids, sharedContext)
|
||||
}
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
@@ -833,7 +833,7 @@ export default class CartModuleService<
|
||||
)
|
||||
|
||||
if (toDelete.length) {
|
||||
await this.shippingMethodAdjustmentService_.delete(
|
||||
await this.shippingMethodAdjustmentService_.softDelete(
|
||||
toDelete.map((adj) => adj!.id),
|
||||
sharedContext
|
||||
)
|
||||
@@ -960,7 +960,7 @@ export default class CartModuleService<
|
||||
: [adjustmentIdsOrSelector]
|
||||
}
|
||||
|
||||
await this.shippingMethodAdjustmentService_.delete(ids, sharedContext)
|
||||
await this.shippingMethodAdjustmentService_.softDelete(ids, sharedContext)
|
||||
}
|
||||
|
||||
addLineItemTaxLines(
|
||||
@@ -1058,7 +1058,7 @@ export default class CartModuleService<
|
||||
})
|
||||
|
||||
if (toDelete.length) {
|
||||
await this.lineItemTaxLineService_.delete(
|
||||
await this.lineItemTaxLineService_.softDelete(
|
||||
toDelete.map((taxLine) => taxLine!.id),
|
||||
sharedContext
|
||||
)
|
||||
@@ -1114,7 +1114,7 @@ export default class CartModuleService<
|
||||
: [taxLineIdsOrSelector]
|
||||
}
|
||||
|
||||
await this.lineItemTaxLineService_.delete(ids, sharedContext)
|
||||
await this.lineItemTaxLineService_.softDelete(ids, sharedContext)
|
||||
}
|
||||
|
||||
addShippingMethodTaxLines(
|
||||
@@ -1216,7 +1216,7 @@ export default class CartModuleService<
|
||||
})
|
||||
|
||||
if (toDelete.length) {
|
||||
await this.shippingMethodTaxLineService_.delete(
|
||||
await this.shippingMethodTaxLineService_.softDelete(
|
||||
toDelete.map((taxLine) => taxLine!.id),
|
||||
sharedContext
|
||||
)
|
||||
@@ -1271,6 +1271,6 @@ export default class CartModuleService<
|
||||
: [taxLineIdsOrSelector]
|
||||
}
|
||||
|
||||
await this.shippingMethodTaxLineService_.delete(ids, sharedContext)
|
||||
await this.shippingMethodTaxLineService_.softDelete(ids, sharedContext)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user