chore(): Reorganize modules (#7210)

**What**
Move all modules to the modules directory
This commit is contained in:
Adrien de Peretti
2024-05-02 17:33:34 +02:00
committed by GitHub
parent 7a351eef09
commit 4eae25e1ef
870 changed files with 91 additions and 62 deletions

View File

@@ -0,0 +1,95 @@
import { DAL } from "@medusajs/types"
import {
DALUtils,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Entity,
Filter,
OnInit,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
type OptionalAddressProps = DAL.SoftDeletableEntityDateColumns
@Entity({ tableName: "cart_address" })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class Address {
[OptionalProps]: OptionalAddressProps
@PrimaryKey({ columnType: "text" })
id!: string
@Property({ columnType: "text", nullable: true })
customer_id: string | null = null
@Property({ columnType: "text", nullable: true })
company: string | null = null
@Property({ columnType: "text", nullable: true })
first_name: string | null = null
@Property({ columnType: "text", nullable: true })
last_name: string | null = null
@Property({ columnType: "text", nullable: true })
address_1: string | null = null
@Property({ columnType: "text", nullable: true })
address_2: string | null = null
@Property({ columnType: "text", nullable: true })
city: string | null = null
@Property({ columnType: "text", nullable: true })
country_code: string | null = null
@Property({ columnType: "text", nullable: true })
province: string | null = null
@Property({ columnType: "text", nullable: true })
postal_code: string | null = null
@Property({ columnType: "text", nullable: true })
phone: string | null = null
@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null
@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
@createPsqlIndexStatementHelper({
tableName: "cart_address",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
}).MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "caaddr")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "caaddr")
}
}

View File

@@ -0,0 +1,49 @@
import { DAL } from "@medusajs/types"
import { BigNumber, MikroOrmBigNumberProperty } from "@medusajs/utils"
import { OptionalProps, PrimaryKey, Property } from "@mikro-orm/core"
type OptionalAdjustmentLineProps = DAL.SoftDeletableEntityDateColumns
/**
* As per the Mikro ORM docs, superclasses should use the abstract class definition
* Source: https://mikro-orm.io/docs/inheritance-mapping
*/
export default abstract class AdjustmentLine {
[OptionalProps]: OptionalAdjustmentLineProps
@PrimaryKey({ columnType: "text" })
id: string
@Property({ columnType: "text", nullable: true })
description: string | null = null
@Property({ columnType: "text", nullable: true })
code: string | null = null
@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",
defaultRaw: "now()",
})
created_at: Date
@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Date
}

View File

@@ -0,0 +1,177 @@
import { DAL } from "@medusajs/types"
import {
DALUtils,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Cascade,
Collection,
Entity,
Filter,
ManyToOne,
OnInit,
OneToMany,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import Address from "./address"
import LineItem from "./line-item"
import ShippingMethod from "./shipping-method"
type OptionalCartProps =
| "shipping_address"
| "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 {
[OptionalProps]?: OptionalCartProps
@PrimaryKey({ columnType: "text" })
id: string
@RegionIdIndex()
@Property({ columnType: "text", nullable: true })
region_id: string | null = null
@CustomerIdIndex()
@Property({ columnType: "text", nullable: true })
customer_id: string | null = null
@SalesChannelIdIndex()
@Property({ columnType: "text", nullable: true })
sales_channel_id: string | null = null
@Property({ columnType: "text", nullable: true })
email: string | null = null
@CurrencyCodeIndex()
@Property({ columnType: "text" })
currency_code: string
@ShippingAddressIdIndex()
@ManyToOne({
entity: () => Address,
columnType: "text",
fieldName: "shipping_address_id",
mapToPk: true,
nullable: true,
})
shipping_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,
})
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
@OneToMany(() => LineItem, (lineItem) => lineItem.cart, {
cascade: [Cascade.PERSIST, "soft-remove"] as any,
})
items = new Collection<LineItem>(this)
@OneToMany(() => ShippingMethod, (shippingMethod) => shippingMethod.cart, {
cascade: [Cascade.PERSIST, "soft-remove"] as any,
})
shipping_methods = new Collection<ShippingMethod>(this)
@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
@DeletedAtIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "cart")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "cart")
}
}

View File

@@ -0,0 +1,9 @@
export { default as Address } from "./address"
export { default as Cart } from "./cart"
export { default as LineItem } from "./line-item"
export { default as LineItemAdjustment } from "./line-item-adjustment"
export { default as LineItemTaxLine } from "./line-item-tax-line"
export { default as ShippingMethod } from "./shipping-method"
export { default as ShippingMethodAdjustment } from "./shipping-method-adjustment"
export { default as ShippingMethodTaxLine } from "./shipping-method-tax-line"

View File

@@ -0,0 +1,73 @@
import {
DALUtils,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Check,
Entity,
Filter,
ManyToOne,
OnInit,
Property,
} from "@mikro-orm/core"
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, persist: false })
item: LineItem
@LineItemIdIndex()
@ManyToOne({
entity: () => LineItem,
columnType: "text",
fieldName: "item_id",
mapToPk: true,
})
item_id: string
@PromotionIdIndex()
@Property({ columnType: "text", nullable: true })
promotion_id: string | null = null
@DeletedAtIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "caliadj")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "caliadj")
}
}

View File

@@ -0,0 +1,69 @@
import {
DALUtils,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Entity,
Filter,
ManyToOne,
OnInit,
Property,
} from "@mikro-orm/core"
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, persist: false })
item: LineItem
@LineItemIdIndex()
@ManyToOne({
entity: () => LineItem,
columnType: "text",
fieldName: "item_id",
mapToPk: true,
})
item_id: string
@TaxRateIdIndex()
@Property({ columnType: "text", nullable: true })
tax_rate_id: string | null = null
@DeletedAtIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "calitxl")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "calitxl")
}
}

View File

@@ -0,0 +1,193 @@
import { BigNumberRawValue, DAL } from "@medusajs/types"
import {
BigNumber,
DALUtils,
MikroOrmBigNumberProperty,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Cascade,
Collection,
Entity,
Filter,
ManyToOne,
OnInit,
OneToMany,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import Cart from "./cart"
import LineItemAdjustment from "./line-item-adjustment"
import LineItemTaxLine from "./line-item-tax-line"
type OptionalLineItemProps =
| "is_discoutable"
| "is_tax_inclusive"
| "compare_at_unit_price"
| "requires_shipping"
| "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 {
[OptionalProps]?: OptionalLineItemProps
@PrimaryKey({ columnType: "text" })
id: string
@CartIdIndex()
@ManyToOne({
entity: () => Cart,
columnType: "text",
fieldName: "cart_id",
mapToPk: true,
})
cart_id: string
@ManyToOne({ entity: () => Cart, persist: false })
cart: Cart
@Property({ columnType: "text" })
title: string
@Property({ columnType: "text", nullable: true })
subtitle: string | null = null
@Property({ columnType: "text", nullable: true })
thumbnail: string | null = null
@Property({ columnType: "integer" })
quantity: number
@VariantIdIndex()
@Property({ columnType: "text", nullable: true })
variant_id: string | null = null
@ProductIdIndex()
@Property({ columnType: "text", nullable: true })
product_id: string | null = null
@Property({ columnType: "text", nullable: true })
product_title: string | null = null
@Property({ columnType: "text", nullable: true })
product_description: string | null = null
@Property({ columnType: "text", nullable: true })
product_subtitle: string | null = null
@Property({ columnType: "text", nullable: true })
product_type: string | null = null
@Property({ columnType: "text", nullable: true })
product_collection: string | null = null
@Property({ columnType: "text", nullable: true })
product_handle: string | null = null
@Property({ columnType: "text", nullable: true })
variant_sku: string | null = null
@Property({ columnType: "text", nullable: true })
variant_barcode: string | null = null
@Property({ columnType: "text", nullable: true })
variant_title: string | null = null
@Property({ columnType: "jsonb", nullable: true })
variant_option_values: Record<string, unknown> | null = null
@Property({ columnType: "boolean" })
requires_shipping = true
@Property({ columnType: "boolean" })
is_discountable = true
@Property({ columnType: "boolean" })
is_tax_inclusive = false
@MikroOrmBigNumberProperty({ nullable: true })
compare_at_unit_price?: BigNumber | number | null = null
@Property({ columnType: "jsonb", nullable: true })
raw_compare_at_unit_price: BigNumberRawValue | null = null
@MikroOrmBigNumberProperty()
unit_price: BigNumber | number
@Property({ columnType: "jsonb" })
raw_unit_price: BigNumberRawValue
@OneToMany(() => LineItemTaxLine, (taxLine) => taxLine.item, {
cascade: [Cascade.PERSIST, "soft-remove"] as any,
})
tax_lines = new Collection<LineItemTaxLine>(this)
@OneToMany(() => LineItemAdjustment, (adjustment) => adjustment.item, {
cascade: [Cascade.PERSIST, "soft-remove"] as any,
})
adjustments = new Collection<LineItemAdjustment>(this)
@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null
@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
@DeletedAtIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "cali")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "cali")
}
}

View File

@@ -0,0 +1,69 @@
import {
DALUtils,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Entity,
Filter,
ManyToOne,
OnInit,
Property,
} from "@mikro-orm/core"
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, persist: false })
shipping_method: ShippingMethod
@ShippingMethodIdIndex()
@ManyToOne({
entity: () => ShippingMethod,
columnType: "text",
fieldName: "shipping_method_id",
mapToPk: true,
})
shipping_method_id: string
@PromotionIdIndex()
@Property({ columnType: "text", nullable: true })
promotion_id: string | null = null
@DeletedAtIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "casmadj")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "casmadj")
}
}

View File

@@ -0,0 +1,69 @@
import {
DALUtils,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Entity,
Filter,
ManyToOne,
OnInit,
Property,
} from "@mikro-orm/core"
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, persist: false })
shipping_method: ShippingMethod
@ShippingMethodIdIndex()
@ManyToOne({
entity: () => ShippingMethod,
columnType: "text",
fieldName: "shipping_method_id",
mapToPk: true,
})
shipping_method_id: string
@TaxRateIdIndex()
@Property({ columnType: "text", nullable: true })
tax_rate_id: string | null = null
@DeletedAtIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "casmtxl")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "casmtxl")
}
}

View File

@@ -0,0 +1,144 @@
import { BigNumberRawValue, DAL } from "@medusajs/types"
import {
BigNumber,
DALUtils,
MikroOrmBigNumberProperty,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Cascade,
Check,
Collection,
Entity,
Filter,
ManyToOne,
OnInit,
OneToMany,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import Cart from "./cart"
import ShippingMethodAdjustment from "./shipping-method-adjustment"
import ShippingMethodTaxLine from "./shipping-method-tax-line"
type OptionalShippingMethodProps =
| "cart"
| "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)
export default class ShippingMethod {
[OptionalProps]?: OptionalShippingMethodProps
@PrimaryKey({ columnType: "text" })
id: string
@CartIdIndex()
@ManyToOne({
entity: () => Cart,
columnType: "text",
fieldName: "cart_id",
mapToPk: true,
})
cart_id: string
@ManyToOne({ entity: () => Cart, persist: false })
cart: Cart
@Property({ columnType: "text" })
name: string
@Property({ columnType: "jsonb", nullable: true })
description: string | null = null
@MikroOrmBigNumberProperty()
amount: BigNumber | number
@Property({ columnType: "jsonb" })
raw_amount: BigNumberRawValue
@Property({ columnType: "boolean" })
is_tax_inclusive = false
@ShippingOptionIdIndex()
@Property({ columnType: "text", nullable: true })
shipping_option_id: string | null = null
@Property({ columnType: "jsonb", nullable: true })
data: Record<string, unknown> | null = null
@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null
@OneToMany(
() => ShippingMethodTaxLine,
(taxLine) => taxLine.shipping_method,
{
cascade: [Cascade.PERSIST, "soft-remove"] as any,
}
)
tax_lines = new Collection<ShippingMethodTaxLine>(this)
@OneToMany(
() => ShippingMethodAdjustment,
(adjustment) => adjustment.shipping_method,
{
cascade: [Cascade.PERSIST, "soft-remove"] as any,
}
)
adjustments = new Collection<ShippingMethodAdjustment>(this)
@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
@DeletedAtIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "casm")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "casm")
}
}

View File

@@ -0,0 +1,45 @@
import { DAL } from "@medusajs/types"
import { OptionalProps, PrimaryKey, Property } from "@mikro-orm/core"
type OptionalTaxLineProps = DAL.SoftDeletableEntityDateColumns
/**
* As per the Mikro ORM docs, superclasses should use the abstract class definition
* Source: https://mikro-orm.io/docs/inheritance-mapping
*/
export default abstract class TaxLine {
[OptionalProps]?: OptionalTaxLineProps
@PrimaryKey({ columnType: "text" })
id: string
@Property({ columnType: "text", nullable: true })
description?: string | null
@Property({ columnType: "text" })
code: string
@Property({ columnType: "numeric", serializer: Number })
rate: number
@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",
defaultRaw: "now()",
})
created_at: Date
@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Date
}