feat: optional props, update fields

This commit is contained in:
fPolic
2024-01-12 11:46:08 +01:00
parent b601212398
commit 1b882a90ed
8 changed files with 134 additions and 77 deletions
+8 -3
View File
@@ -3,6 +3,7 @@ import {
Entity,
ManyToOne,
OnInit,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
@@ -10,8 +11,12 @@ import {
import { generateEntityId } from "@medusajs/utils"
import Payment from "./payment"
type OptionalCaptureProps = "created_by" | "created_at" | "completed_at"
@Entity({ tableName: "capture" })
export default class Capture {
[OptionalProps]?: OptionalCaptureProps
@PrimaryKey({ columnType: "text" })
id: string
@@ -34,16 +39,16 @@ export default class Capture {
})
created_at: Date
@Property({ nullable: true })
@Property({ columnType: "text", nullable: true })
created_by: string | null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "capture")
this.id = generateEntityId(this.id, "cap")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "capture")
this.id = generateEntityId(this.id, "cap")
}
}
@@ -7,9 +7,11 @@ import {
ManyToMany,
OneToMany,
OnInit,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import { DAL } from "@medusajs/types"
import { DALUtils, generateEntityId } from "@medusajs/utils"
import PaymentProvider from "./payment-provider"
@@ -44,9 +46,19 @@ export enum PaymentCollectionStatus {
CANCELED = "canceled",
}
type OptionalPaymentCollectionProps =
| "currency_code"
| "authorized_amount"
| "refunded_amount"
| "region_id"
| "completed_at"
| DAL.SoftDeletableEntityDateColumns
@Entity({ tableName: "payment-collection" })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class PaymentCollection {
[OptionalProps]?: OptionalPaymentCollectionProps
@PrimaryKey({ columnType: "text" })
id: string
@@ -2,42 +2,51 @@ import {
BeforeCreate,
Entity,
OnInit,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import { generateEntityId } from "@medusajs/utils"
type OptionalPaymentMethodTokenProps =
| "data"
| "type_detail"
| "description_detail"
| "metadata"
@Entity({ tableName: "payment-method-token" })
export default class PaymentMethodToken {
[OptionalProps]?: OptionalPaymentMethodTokenProps
@PrimaryKey({ columnType: "text" })
id: string
@Property({ columnType: "jsonb", nullable: true })
data?: Record<string, unknown> | null
@Property()
name: string
@Property()
type_detail: string
@Property()
description_detail: string
@Property({ columnType: "jsonb", nullable: true })
metadata?: Record<string, unknown> | null
@Property({ columnType: "text" })
provider_id: string
@Property({ columnType: "jsonb", nullable: true })
data?: Record<string, unknown> | null
@Property({ columnType: "text" })
name: string
@Property({ columnType: "text", nullable: true })
type_detail: string | null
@Property({ columnType: "text", nullable: true })
description_detail: string | null
@Property({ columnType: "jsonb", nullable: true })
metadata?: Record<string, unknown> | null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "pmt")
this.id = generateEntityId(this.id, "paymt")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "pmt")
this.id = generateEntityId(this.id, "paymt")
}
}
+15 -3
View File
@@ -5,11 +5,14 @@ import {
ManyToOne,
OneToOne,
OnInit,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import PaymentCollection from "./payment-collection"
import { DAL } from "@medusajs/types"
import { generateEntityId } from "@medusajs/utils"
import PaymentCollection from "./payment-collection"
import Payment from "./payment"
/**
@@ -40,8 +43,17 @@ export enum PaymentSessionStatus {
CANCELED = "canceled",
}
type OptionalPaymentSessionProps =
| "currency_code"
| "data"
| "is_selected"
| "authorised_at"
| DAL.EntityDateColumns
@Entity({ tableName: "payment-session" })
export default class PaymentSession {
[OptionalProps]?: OptionalPaymentSessionProps
@PrimaryKey({ columnType: "text" })
id: string
@@ -65,7 +77,7 @@ export default class PaymentSession {
})
status: PaymentSessionStatus
@Property({ nullable: true })
@Property({ columnType: "boolean", nullable: true })
is_selected: boolean | null
@Property({
@@ -84,7 +96,7 @@ export default class PaymentSession {
mappedBy: (payment) => payment.session,
cascade: ["soft-remove"] as any,
})
payment: Payment
payment!: Payment
@BeforeCreate()
onCreate() {
+21 -7
View File
@@ -7,9 +7,11 @@ import {
OneToMany,
OneToOne,
OnInit,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import { DAL } from "@medusajs/types"
import { DALUtils, generateEntityId } from "@medusajs/utils"
import Refund from "./refund"
@@ -17,9 +19,21 @@ import Capture from "./capture"
import PaymentSession from "./payment-session"
import PaymentCollection from "./payment-collection"
type OptionalPaymentProps =
| "authorized_amount"
| "cart_id"
| "order_id"
| "customer_id"
| "data"
| "captured_at"
| "canceled_at"
| DAL.SoftDeletableEntityDateColumns
@Entity({ tableName: "payment" })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class Payment {
[OptionalProps]?: OptionalPaymentProps
@PrimaryKey({ columnType: "text" })
id: string
@@ -36,19 +50,19 @@ export default class Payment {
})
authorized_amount: number | null
@Property()
@Property({ columnType: "text" })
currency_code: string
@Property({ columnType: "text" })
provider_id: string
@Property({ nullable: true })
currency_code: string | null
@Property({ nullable: true })
@Property({ columnType: "text", nullable: true })
cart_id: string | null
@Property({ nullable: true })
@Property({ columnType: "text", nullable: true })
order_id: string | null
@Property({ nullable: true })
@Property({ columnType: "text", nullable: true })
customer_id: string | null
@Property({ columnType: "jsonb", nullable: true })
+8 -3
View File
@@ -3,6 +3,7 @@ import {
Entity,
ManyToOne,
OnInit,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
@@ -10,8 +11,12 @@ import {
import { generateEntityId } from "@medusajs/utils"
import Payment from "./payment"
type OptionalRefundProps = "created_by" | "completed_at"
@Entity({ tableName: "refund" })
export default class Refund {
[OptionalProps]?: OptionalRefundProps
@PrimaryKey({ columnType: "text" })
id: string
@@ -34,16 +39,16 @@ export default class Refund {
})
created_at: Date
@Property({ nullable: true })
@Property({ columnType: "text", nullable: true })
created_by: string | null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "refund")
this.id = generateEntityId(this.id, "ref")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "refund")
this.id = generateEntityId(this.id, "ref")
}
}