fix(medusa): migrate cart service to typescript (#884)
* fix: migrate cart service to typescript * fix: jsdoc inventory service * fix: revert route unit test change * fix: typo * fix: revert integration test packages * fix: cleanup * fix: tests * fix: integration tests * fix: create props type guards * fix: move total field to common types
This commit is contained in:
@@ -50,46 +50,46 @@ export class Address {
|
||||
id: string
|
||||
|
||||
@Index()
|
||||
@Column({ nullable: true })
|
||||
customer_id: string
|
||||
@Column({ type: "text", nullable: true })
|
||||
customer_id: string | null
|
||||
|
||||
@ManyToOne(() => Customer)
|
||||
@JoinColumn({ name: "customer_id" })
|
||||
customer: Customer
|
||||
customer: Customer | null
|
||||
|
||||
@Column({ nullable: true })
|
||||
company: string
|
||||
@Column({ type: "text", nullable: true })
|
||||
company: string | null
|
||||
|
||||
@Column({ nullable: true })
|
||||
first_name: string
|
||||
@Column({ type: "text", nullable: true })
|
||||
first_name: string | null
|
||||
|
||||
@Column({ nullable: true })
|
||||
last_name: string
|
||||
@Column({ type: "text", nullable: true })
|
||||
last_name: string | null
|
||||
|
||||
@Column({ nullable: true })
|
||||
address_1: string
|
||||
@Column({ type: "text", nullable: true })
|
||||
address_1: string | null
|
||||
|
||||
@Column({ nullable: true })
|
||||
address_2: string
|
||||
@Column({ type: "text", nullable: true })
|
||||
address_2: string | null
|
||||
|
||||
@Column({ nullable: true })
|
||||
city: string
|
||||
@Column({ type: "text", nullable: true })
|
||||
city: string | null
|
||||
|
||||
@Column({ nullable: true })
|
||||
country_code: string
|
||||
@Column({ type: "text", nullable: true })
|
||||
country_code: string | null
|
||||
|
||||
@ManyToOne(() => Country)
|
||||
@JoinColumn({ name: "country_code", referencedColumnName: "iso_2" })
|
||||
country: Country
|
||||
country: Country | null
|
||||
|
||||
@Column({ nullable: true })
|
||||
province: string
|
||||
@Column({ type: "text", nullable: true })
|
||||
province: string | null
|
||||
|
||||
@Column({ nullable: true })
|
||||
postal_code: string
|
||||
@Column({ type: "text", nullable: true })
|
||||
postal_code: string | null
|
||||
|
||||
@Column({ nullable: true })
|
||||
phone: string
|
||||
@Column({ type: "text", nullable: true })
|
||||
phone: string | null
|
||||
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
@@ -98,7 +98,7 @@ export class Address {
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
deleted_at: Date | null
|
||||
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@@ -145,7 +145,7 @@ export class Cart {
|
||||
cascade: ["insert", "remove", "soft-remove"],
|
||||
})
|
||||
@JoinColumn({ name: "shipping_address_id" })
|
||||
shipping_address: Address
|
||||
shipping_address: Address | null
|
||||
|
||||
@OneToMany(() => LineItem, (lineItem) => lineItem.cart, {
|
||||
cascade: ["insert", "remove"],
|
||||
@@ -172,7 +172,7 @@ export class Cart {
|
||||
referencedColumnName: "id",
|
||||
},
|
||||
})
|
||||
discounts: Discount
|
||||
discounts: Discount[]
|
||||
|
||||
@ManyToMany(() => GiftCard)
|
||||
@JoinTable({
|
||||
@@ -186,7 +186,7 @@ export class Cart {
|
||||
referencedColumnName: "id",
|
||||
},
|
||||
})
|
||||
gift_cards: GiftCard
|
||||
gift_cards: GiftCard[]
|
||||
|
||||
@Index()
|
||||
@Column({ nullable: true })
|
||||
@@ -196,7 +196,7 @@ export class Cart {
|
||||
@JoinColumn({ name: "customer_id" })
|
||||
customer: Customer
|
||||
|
||||
payment_session: PaymentSession
|
||||
payment_session: PaymentSession | null
|
||||
|
||||
@OneToMany(() => PaymentSession, (paymentSession) => paymentSession.cart, {
|
||||
cascade: true,
|
||||
@@ -217,7 +217,7 @@ export class Cart {
|
||||
shipping_methods: ShippingMethod[]
|
||||
|
||||
@DbAwareColumn({ type: "enum", enum: CartType, default: "default" })
|
||||
type: boolean
|
||||
type: CartType
|
||||
|
||||
@Column({ type: resolveDbType("timestamptz"), nullable: true })
|
||||
completed_at: Date
|
||||
@@ -243,15 +243,14 @@ export class Cart {
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
context: any
|
||||
|
||||
// Total fields
|
||||
shipping_total: number
|
||||
discount_total: number
|
||||
tax_total: number
|
||||
refunded_total: number
|
||||
total: number
|
||||
subtotal: number
|
||||
refundable_amount: number
|
||||
gift_card_total: number
|
||||
shipping_total?: number
|
||||
discount_total?: number
|
||||
tax_total?: number
|
||||
refunded_total?: number
|
||||
total?: number
|
||||
subtotal?: number
|
||||
refundable_amount?: number
|
||||
gift_card_total?: number
|
||||
|
||||
@BeforeInsert()
|
||||
private beforeInsert(): undefined | void {
|
||||
|
||||
@@ -32,10 +32,7 @@ export class PaymentSession {
|
||||
@Column()
|
||||
cart_id: string
|
||||
|
||||
@ManyToOne(
|
||||
() => Cart,
|
||||
cart => cart.payment_sessions
|
||||
)
|
||||
@ManyToOne(() => Cart, (cart) => cart.payment_sessions)
|
||||
@JoinColumn({ name: "cart_id" })
|
||||
cart: Cart
|
||||
|
||||
@@ -43,8 +40,8 @@ export class PaymentSession {
|
||||
@Column()
|
||||
provider_id: string
|
||||
|
||||
@Column({ nullable: true })
|
||||
is_selected: boolean
|
||||
@Column({ type: "boolean", nullable: true })
|
||||
is_selected: boolean | null
|
||||
|
||||
@DbAwareColumn({ type: "enum", enum: PaymentSessionStatus })
|
||||
status: string
|
||||
|
||||
Reference in New Issue
Block a user