feat(cart): Partial module service implementation (#6012)

Awaiting #6000 #6008  

**What**
- CRUD for Address in Cart Module service
- Tests for CRUD Carts + Address

**Not**
- Line items, shipping methods, tax lines, adjustment lines
This commit is contained in:
Oli Juhl
2024-01-12 10:30:57 +00:00
committed by GitHub
parent 8472460f53
commit 192bc336cc
16 changed files with 433 additions and 39 deletions
+20 -12
View File
@@ -5,9 +5,10 @@ import {
Cascade,
Collection,
Entity,
Index,
ManyToOne,
OnInit,
OneToMany,
OneToOne,
OptionalProps,
PrimaryKey,
Property,
@@ -19,7 +20,7 @@ import ShippingMethod from "./shipping-method"
type OptionalCartProps =
| "shipping_address"
| "billing_address"
| DAL.EntityDateColumns // TODO: To be revisited when more clear
| DAL.EntityDateColumns
@Entity({ tableName: "cart" })
export default class Cart {
@@ -47,18 +48,22 @@ export default class Cart {
@Property({ columnType: "text" })
currency_code: string
@OneToOne({
entity: () => Address,
joinColumn: "shipping_address_id",
cascade: [Cascade.REMOVE],
@Index({ name: "IDX_cart_shipping_address_id" })
@Property({ columnType: "text", nullable: true })
shipping_address_id?: string | null
@ManyToOne(() => Address, {
fieldName: "shipping_address_id",
nullable: true,
})
shipping_address?: Address | null
@OneToOne({
entity: () => Address,
joinColumn: "billing_address_id",
cascade: [Cascade.REMOVE],
@Index({ name: "IDX_cart_billing_address_id" })
@Property({ columnType: "text", nullable: true })
billing_address_id?: string | null
@ManyToOne(() => Address, {
fieldName: "billing_address_id",
nullable: true,
})
billing_address?: Address | null
@@ -116,7 +121,7 @@ export default class Cart {
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Date
created_at?: Date
@Property({
onCreate: () => new Date(),
@@ -124,7 +129,10 @@ export default class Cart {
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Date
updated_at?: Date
@Property({ columnType: "timestamptz", nullable: true })
deleted_at?: Date
@BeforeCreate()
onCreate() {
+1
View File
@@ -6,3 +6,4 @@ export { default as LineItemTaxLine } from "./line-item-tax-line"
export { default as ShippingMethod } from "./shipping-method"
export { default as ShippingMethodAdjustmentLine } from "./shipping-method-adjustment-line"
export { default as ShippingMethodTaxLine } from "./shipping-method-tax-line"