102 lines
2.2 KiB
TypeScript
102 lines
2.2 KiB
TypeScript
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 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",
|
|
})
|
|
payment!: Rel<Payment>
|
|
|
|
@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
|
|
}
|
|
}
|