Feat(order): return reason and transaction methods (#7303)

This commit is contained in:
Carlos R. L. Rodrigues authored and GitHub committed 2024-05-13 16:15:25 +00:00
1 parent 8958214350
commit 6c94d0205c
23 files changed
+1036 -6

No files matched your search

@@ -8,6 +8,7 @@ export { default as OrderChangeAction } from "./order-change-action"
export { default as OrderItem } from "./order-item"
export { default as OrderShippingMethod } from "./order-shipping-method"
export { default as OrderSummary } from "./order-summary"
export { default as ReturnReason } from "./return-reason"
export { default as ShippingMethod } from "./shipping-method"
export { default as ShippingMethodAdjustment } from "./shipping-method-adjustment"
export { default as ShippingMethodTaxLine } from "./shipping-method-tax-line"
@@ -0,0 +1,105 @@
import { DAL } from "@medusajs/types"
import {
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Cascade,
Entity,
ManyToOne,
OnInit,
OneToMany,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
const DeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "return_reason",
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})
const ValueIndex = createPsqlIndexStatementHelper({
tableName: "return_reason",
columns: "value",
where: "deleted_at IS NOT NULL",
})
const ParentIndex = createPsqlIndexStatementHelper({
tableName: "return_reason",
columns: "parent_return_reason_id",
where: "deleted_at IS NOT NULL",
})
type OptionalOrderProps = "parent_return_reason" | DAL.EntityDateColumns
@Entity({ tableName: "return_reason" })
export default class ReturnReason {
[OptionalProps]?: OptionalOrderProps
@PrimaryKey({ columnType: "text" })
id: string
@Property({ columnType: "text" })
@ValueIndex.MikroORMIndex()
value: string
@Property({ columnType: "text" })
label: string
@Property({ columnType: "text", nullable: true })
description: string | null = null
@Property({ columnType: "text", nullable: true })
@ParentIndex.MikroORMIndex()
parent_return_reason_id?: string | null
@ManyToOne({
entity: () => ReturnReason,
fieldName: "parent_return_reason_id",
nullable: true,
cascade: [Cascade.PERSIST],
})
parent_return_reason?: ReturnReason | null
@OneToMany(
() => ReturnReason,
(return_reason) => return_reason.parent_return_reason,
{ cascade: [Cascade.PERSIST] }
)
return_reason_children: ReturnReason[]
@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 })
@DeletedAtIndex.MikroORMIndex()
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "rr")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "rr")
}
}