feat(order): Claim and Exchange entities (#7681)
This commit is contained in:
@@ -12,8 +12,10 @@ import {
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { Return } from "@models"
|
||||
import Claim from "./claim"
|
||||
import Exchange from "./exchange"
|
||||
import Order from "./order"
|
||||
import Return from "./return"
|
||||
import ShippingMethod from "./shipping-method"
|
||||
|
||||
type OptionalShippingMethodProps = DAL.EntityDateColumns
|
||||
@@ -30,6 +32,18 @@ const ReturnIdIndex = createPsqlIndexStatementHelper({
|
||||
where: "return_id IS NOT NULL AND deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const ExchangeIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_shipping",
|
||||
columns: ["exchange_id"],
|
||||
where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const ClaimIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_shipping",
|
||||
columns: ["claim_id"],
|
||||
where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const OrderVersionIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_shipping",
|
||||
columns: ["version"],
|
||||
@@ -84,6 +98,36 @@ export default class OrderShippingMethod {
|
||||
})
|
||||
return: Return
|
||||
|
||||
@ManyToOne({
|
||||
entity: () => Exchange,
|
||||
mapToPk: true,
|
||||
fieldName: "exchange_id",
|
||||
columnType: "text",
|
||||
nullable: true,
|
||||
})
|
||||
@ExchangeIdIndex.MikroORMIndex()
|
||||
exchange_id: string | null
|
||||
|
||||
@ManyToOne(() => Exchange, {
|
||||
persist: false,
|
||||
})
|
||||
exchange: Exchange
|
||||
|
||||
@ManyToOne({
|
||||
entity: () => Claim,
|
||||
mapToPk: true,
|
||||
fieldName: "claim_id",
|
||||
columnType: "text",
|
||||
nullable: true,
|
||||
})
|
||||
@ClaimIdIndex.MikroORMIndex()
|
||||
claim_id: string | null
|
||||
|
||||
@ManyToOne(() => Claim, {
|
||||
persist: false,
|
||||
})
|
||||
claim: Claim
|
||||
|
||||
@Property({ columnType: "integer" })
|
||||
@OrderVersionIndex.MikroORMIndex()
|
||||
version: number
|
||||
@@ -125,6 +169,8 @@ export default class OrderShippingMethod {
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "ordspmv")
|
||||
this.order_id ??= this.order?.id
|
||||
this.return_id ??= this.return?.id
|
||||
this.exchange_id ??= this.exchange?.id
|
||||
this.shipping_method_id ??= this.shipping_method?.id
|
||||
this.version ??= this.order?.version
|
||||
}
|
||||
@@ -133,6 +179,8 @@ export default class OrderShippingMethod {
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "ordspmv")
|
||||
this.order_id ??= this.order?.id
|
||||
this.return_id ??= this.return?.id
|
||||
this.exchange_id ??= this.exchange?.id
|
||||
this.shipping_method_id ??= this.shipping_method?.id
|
||||
this.version ??= this.order?.version
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user