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,101 +1,28 @@
import { BigNumberRawValue, DAL } from "@medusajs/framework/types"
import {
BigNumber,
MikroOrmBigNumberProperty,
generateEntityId,
} from "@medusajs/framework/utils"
import {
BeforeCreate,
Entity,
ManyToOne,
OnInit,
OptionalProps,
PrimaryKey,
Property,
Rel,
} from "@mikro-orm/core"
import { model } from "@medusajs/framework/utils"
import Payment from "./payment"
import RefundReason from "./refund-reason"
type OptionalProps =
| "note"
| "refund_reason_id"
| "refund_reason"
| DAL.ModelDateColumns
@Entity({ tableName: "refund" })
export default class Refund {
[OptionalProps]?: OptionalProps
@PrimaryKey({ columnType: "text" })
id: string
@MikroOrmBigNumberProperty()
amount: BigNumber | number
@Property({ columnType: "jsonb" })
raw_amount: BigNumberRawValue
@ManyToOne(() => Payment, {
onDelete: "cascade",
index: "IDX_refund_payment_id",
fieldName: "payment_id",
const Refund = model
.define("Refund", {
id: model.id({ prefix: "ref" }).primaryKey(),
amount: model.bigNumber(),
payment: model.belongsTo(() => Payment, {
mappedBy: "refunds",
}),
refund_reason: model
.belongsTo(() => RefundReason, {
mappedBy: "refunds",
})
.nullable(),
note: model.text().nullable(),
created_by: model.text().nullable(),
metadata: model.json().nullable(),
})
payment!: Rel<Payment>
.indexes([
{
name: "IDX_refund_payment_id",
on: ["payment_id"],
},
])
@Property({ columnType: "text", nullable: true })
payment_id: string
@ManyToOne(() => RefundReason, {
columnType: "text",
mapToPk: true,
fieldName: "refund_reason_id",
nullable: true,
})
refund_reason_id: string | null = null
@ManyToOne(() => RefundReason, { persist: false, nullable: true })
refund_reason: Rel<RefundReason> | null = null
@Property({ columnType: "text", nullable: true })
note: string | null = null
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Date
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Date
@Property({
columnType: "timestamptz",
nullable: true,
index: "IDX_refund_deleted_at",
})
deleted_at: Date | null = null
@Property({ columnType: "text", nullable: true })
created_by: string | null = null
@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "ref")
this.refund_reason_id ??= this.refund_reason?.id || null
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "ref")
this.refund_reason_id ??= this.refund_reason?.id || null
}
}
export default Refund