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,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",
|
||||
|
||||
Reference in New Issue
Block a user