chore(): Reorganize modules (#7210)
**What** Move all modules to the modules directory
This commit is contained in:
committed by
GitHub
parent
7a351eef09
commit
4eae25e1ef
107
packages/modules/order/src/models/transaction.ts
Normal file
107
packages/modules/order/src/models/transaction.ts
Normal file
@@ -0,0 +1,107 @@
|
||||
import { BigNumberRawValue, DAL } from "@medusajs/types"
|
||||
import {
|
||||
BigNumber,
|
||||
MikroOrmBigNumberProperty,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import Order from "./order"
|
||||
|
||||
type OptionalLineItemProps = DAL.EntityDateColumns
|
||||
|
||||
const ReferenceIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_transaction",
|
||||
columns: "reference_id",
|
||||
})
|
||||
|
||||
const OrderIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_transaction",
|
||||
columns: "order_id",
|
||||
})
|
||||
|
||||
const CurrencyCodeIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_transaction",
|
||||
columns: "currency_code",
|
||||
})
|
||||
|
||||
@Entity({ tableName: "order_transaction" })
|
||||
export default class Transaction {
|
||||
[OptionalProps]?: OptionalLineItemProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@ManyToOne({
|
||||
entity: () => Order,
|
||||
columnType: "text",
|
||||
fieldName: "order_id",
|
||||
onDelete: "cascade",
|
||||
mapToPk: true,
|
||||
})
|
||||
@OrderIdIndex.MikroORMIndex()
|
||||
order_id: string
|
||||
|
||||
@ManyToOne(() => Order, {
|
||||
persist: false,
|
||||
})
|
||||
order: Order
|
||||
|
||||
@MikroOrmBigNumberProperty()
|
||||
amount: BigNumber | number
|
||||
|
||||
@Property({ columnType: "jsonb" })
|
||||
raw_amount: BigNumberRawValue
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
@CurrencyCodeIndex.MikroORMIndex()
|
||||
currency_code: string
|
||||
|
||||
@Property({
|
||||
columnType: "text",
|
||||
nullable: true,
|
||||
})
|
||||
reference: string | null = null
|
||||
|
||||
@Property({
|
||||
columnType: "text",
|
||||
nullable: true,
|
||||
})
|
||||
@ReferenceIdIndex.MikroORMIndex()
|
||||
reference_id: string | 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
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "ordtrx")
|
||||
this.order_id ??= this.order?.id
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "ordtrx")
|
||||
this.order_id ??= this.order?.id
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user