chore(payment): Payment module DML (#10553)

* chore(payment): Payment module DML

* rm log

* migration
This commit is contained in:
Carlos R. L. Rodrigues
2024-12-11 13:09:10 -03:00
committed by GitHub
parent 91cd9aad47
commit 0264294ab5
14 changed files with 706 additions and 1039 deletions

View File

@@ -1,77 +1,21 @@
import { BigNumberRawValue } from "@medusajs/framework/types"
import {
BigNumber,
MikroOrmBigNumberProperty,
generateEntityId,
} from "@medusajs/framework/utils"
import {
BeforeCreate,
Entity,
ManyToOne,
OnInit,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import { model } from "@medusajs/framework/utils"
import Payment from "./payment"
type OptionalCaptureProps = "created_at"
@Entity({ tableName: "capture" })
export default class Capture {
[OptionalProps]?: OptionalCaptureProps
@PrimaryKey({ columnType: "text" })
id: string
@MikroOrmBigNumberProperty()
amount: BigNumber | number
@Property({ columnType: "jsonb" })
raw_amount: BigNumberRawValue
@ManyToOne(() => Payment, {
onDelete: "cascade",
index: "IDX_capture_payment_id",
fieldName: "payment_id",
const Capture = model
.define("Capture", {
id: model.id({ prefix: "capt" }).primaryKey(),
amount: model.bigNumber(),
payment: model.belongsTo(() => Payment, {
mappedBy: "captures",
}),
metadata: model.json().nullable(),
created_by: model.text().nullable(),
})
payment!: Payment
.indexes([
{
name: "IDX_capture_payment_id",
on: ["payment_id"],
},
])
@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
@Property({
columnType: "timestamptz",
nullable: true,
index: "IDX_capture_deleted_at",
})
deleted_at: Date | null = null
@Property({ columnType: "text", nullable: true })
created_by: string | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "capt")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "capt")
}
}
export default Capture