import { BigNumberRawValue, DAL } from "@medusajs/framework/types" import { BigNumber, ClaimType, DALUtils, MikroOrmBigNumberProperty, createPsqlIndexStatementHelper, generateEntityId, } from "@medusajs/framework/utils" import { BeforeCreate, Cascade, Collection, Entity, Enum, Filter, ManyToOne, OnInit, OneToMany, OneToOne, OptionalProps, PrimaryKey, Property, Rel, } from "@mikro-orm/core" import ClaimItem from "./claim-item" import Order from "./order" import OrderShipping from "./order-shipping-method" import Return from "./return" import OrderTransaction from "./transaction" type OptionalOrderClaimProps = DAL.ModelDateColumns const DisplayIdIndex = createPsqlIndexStatementHelper({ tableName: "order_claim", columns: "display_id", where: "deleted_at IS NOT NULL", }) const OrderClaimDeletedAtIndex = createPsqlIndexStatementHelper({ tableName: "order_claim", columns: "deleted_at", where: "deleted_at IS NOT NULL", }) const OrderIdIndex = createPsqlIndexStatementHelper({ tableName: "order_claim", columns: ["order_id"], where: "deleted_at IS NOT NULL", }) const ReturnIdIndex = createPsqlIndexStatementHelper({ tableName: "order_claim", columns: "return_id", where: "return_id IS NOT NULL AND deleted_at IS NOT NULL", }) @Entity({ tableName: "order_claim" }) @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) export default class OrderClaim { [OptionalProps]?: OptionalOrderClaimProps @PrimaryKey({ columnType: "text" }) id: string @ManyToOne({ entity: () => Order, mapToPk: true, fieldName: "order_id", columnType: "text", }) @OrderIdIndex.MikroORMIndex() order_id: string @ManyToOne(() => Order, { persist: false, }) order: Rel @OneToOne({ entity: () => Return, mappedBy: (ret) => ret.claim, fieldName: "return_id", nullable: true, owner: true, }) return: Rel @Property({ columnType: "text", nullable: true }) @ReturnIdIndex.MikroORMIndex() return_id: string | null = null @Property({ columnType: "integer", }) order_version: number @Property({ autoincrement: true, primary: false }) @DisplayIdIndex.MikroORMIndex() display_id: number @Enum({ items: () => ClaimType }) type: Rel @Property({ columnType: "boolean", nullable: true }) no_notification: boolean | null = null @MikroOrmBigNumberProperty({ nullable: true, }) refund_amount: BigNumber | number @Property({ columnType: "jsonb", nullable: true }) raw_refund_amount: BigNumberRawValue @OneToMany(() => ClaimItem, (item) => item.claim, { cascade: [Cascade.PERSIST], }) additional_items = new Collection>(this) @OneToMany(() => ClaimItem, (item) => item.claim, { cascade: [Cascade.PERSIST], }) claim_items = new Collection>(this) @OneToMany(() => OrderShipping, (shippingMethod) => shippingMethod.claim, { cascade: [Cascade.PERSIST], }) shipping_methods = new Collection>(this) @OneToMany(() => OrderTransaction, (transaction) => transaction.claim, { cascade: [Cascade.PERSIST], }) transactions = new Collection(this) @Property({ columnType: "text", nullable: true }) created_by: string | null = null @Property({ columnType: "jsonb", nullable: true }) metadata: Record | 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 }) @OrderClaimDeletedAtIndex.MikroORMIndex() deleted_at: Date | null = null @Property({ columnType: "timestamptz", nullable: true }) canceled_at: Date | null = null @BeforeCreate() onCreate() { this.id = generateEntityId(this.id, "claim") } @OnInit() onInit() { this.id = generateEntityId(this.id, "claim") } }