feat(order): Claim and Exchange entities (#7681)

This commit is contained in:
Carlos R. L. Rodrigues
2024-06-12 14:49:15 -03:00
committed by GitHub
parent 85d487d90b
commit 75811cd4b3
18 changed files with 877 additions and 56 deletions
@@ -14,9 +14,11 @@ import {
PrimaryKey,
Property,
} from "@mikro-orm/core"
import { Return } from "@models"
import Claim from "./claim"
import Exchange from "./exchange"
import LineItem from "./line-item"
import Order from "./order"
import Return from "./return"
type OptionalLineItemProps = DAL.EntityDateColumns
@@ -32,6 +34,18 @@ const ReturnIdIndex = createPsqlIndexStatementHelper({
where: "return_id IS NOT NULL AND deleted_at IS NOT NULL",
})
const ExchangeIdIndex = createPsqlIndexStatementHelper({
tableName: "order_item",
columns: ["exchange_id"],
where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL",
})
const ClaimIdIndex = createPsqlIndexStatementHelper({
tableName: "order_item",
columns: ["claim_id"],
where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL",
})
const OrderVersionIndex = createPsqlIndexStatementHelper({
tableName: "order_item",
columns: ["version"],
@@ -86,6 +100,36 @@ export default class OrderItem {
})
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
@@ -172,6 +216,9 @@ export default class OrderItem {
onCreate() {
this.id = generateEntityId(this.id, "orditem")
this.order_id ??= this.order?.id
this.return_id ??= this.return?.id
this.exchange_id ??= this.exchange?.id
this.claim_id ??= this.claim?.id
this.item_id ??= this.item?.id
this.version ??= this.order?.version
}
@@ -180,6 +227,9 @@ export default class OrderItem {
onInit() {
this.id = generateEntityId(this.id, "orditem")
this.order_id ??= this.order?.id
this.return_id ??= this.return?.id
this.exchange_id ??= this.exchange?.id
this.claim_id ??= this.claim?.id
this.item_id ??= this.item?.id
this.version ??= this.order?.version
}