feat(cart): Line items operations (#6066)

This commit is contained in:
Oli Juhl
2024-01-16 15:44:49 +01:00
committed by GitHub
parent 6315a61189
commit a5e8bf06c6
18 changed files with 973 additions and 136 deletions
+1 -2
View File
@@ -11,7 +11,7 @@ import {
OneToMany,
OptionalProps,
PrimaryKey,
Property,
Property
} from "@mikro-orm/core"
import Address from "./address"
import LineItem from "./line-item"
@@ -78,7 +78,6 @@ export default class Cart {
@OneToMany(() => ShippingMethod, (shippingMethod) => shippingMethod.cart, {
cascade: [Cascade.REMOVE],
})
shipping_methods = new Collection<ShippingMethod>(this)
+12 -8
View File
@@ -22,6 +22,7 @@ type OptionalLineItemProps =
| "is_tax_inclusive"
| "compare_at_unit_price"
| "requires_shipping"
| "cart"
| DAL.EntityDateColumns
@Entity({ tableName: "cart_line_item" })
@@ -31,12 +32,15 @@ export default class LineItem {
@PrimaryKey({ columnType: "text" })
id: string
@Property({ columnType: "text" })
cart_id: string
@ManyToOne(() => Cart, {
onDelete: "cascade",
index: "IDX_line_item_cart_id",
fieldName: "cart_id",
nullable: true,
})
cart!: Cart
cart?: Cart | null
@Property({ columnType: "text" })
title: string
@@ -47,7 +51,7 @@ export default class LineItem {
@Property({ columnType: "text", nullable: true })
thumbnail?: string | null
@Property({ columnType: "text" })
@Property({ columnType: "integer" })
quantity: number
@Property({
@@ -90,13 +94,13 @@ export default class LineItem {
@Property({ columnType: "jsonb", nullable: true })
variant_option_values?: Record<string, unknown> | null
@Property({ columnType: "boolean" })
@Property({ columnType: "boolean", default: true })
requires_shipping = true
@Property({ columnType: "boolean" })
@Property({ columnType: "boolean", default: true })
is_discountable = true
@Property({ columnType: "boolean" })
@Property({ columnType: "boolean", default: false })
is_tax_inclusive = false
@Property({ columnType: "numeric", nullable: true })
@@ -147,7 +151,7 @@ export default class LineItem {
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Date
created_at?: Date
@Property({
onCreate: () => new Date(),
@@ -155,7 +159,7 @@ export default class LineItem {
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Date
updated_at?: Date
@BeforeCreate()
onCreate() {