feat(order): Claim and Exchange entities (#7681)
This commit is contained in:
1 parent
85d487d90b
commit
75811cd4b3
18 files changed
+877
-56
No files matched your search
@@ -0,0 +1,86 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import ClaimItem from "./claim-item"
|
||||
|
||||
type OptionalClaimItemImageProps = DAL.EntityDateColumns
|
||||
|
||||
const ClaimItemImageDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_claim_item_image",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const ClaimItemIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_claim_item_image",
|
||||
columns: ["claim_item_id"],
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName: "order_claim_item_image" })
|
||||
export default class ClaimItemImage {
|
||||
[OptionalProps]?: OptionalClaimItemImageProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@ManyToOne({
|
||||
entity: () => ClaimItem,
|
||||
mapToPk: true,
|
||||
fieldName: "claim_item_id",
|
||||
columnType: "text",
|
||||
})
|
||||
@ClaimItemIdIndex.MikroORMIndex()
|
||||
claim_item_id: string
|
||||
|
||||
@ManyToOne(() => ClaimItem, {
|
||||
persist: false,
|
||||
})
|
||||
item: ClaimItem
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
url: string
|
||||
|
||||
@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 })
|
||||
@ClaimItemImageDeletedAtIndex.MikroORMIndex()
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "ordclaimimg")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "ordclaimimg")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
ClaimReason,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Collection,
|
||||
Entity,
|
||||
Enum,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OneToMany,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import Claim from "./claim"
|
||||
import ClaimItemImage from "./claim-item-image"
|
||||
import LineItem from "./line-item"
|
||||
|
||||
type OptionalLineItemProps = DAL.EntityDateColumns
|
||||
|
||||
const ClaimIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_claim_item",
|
||||
columns: "claim_id",
|
||||
})
|
||||
|
||||
const ItemIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_claim_item",
|
||||
columns: "item_id",
|
||||
})
|
||||
|
||||
@Entity({ tableName: "order_claim_item" })
|
||||
export default class OrderClaimItem {
|
||||
[OptionalProps]?: OptionalLineItemProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@OneToMany(() => ClaimItemImage, (ci) => ci.item, {
|
||||
cascade: [Cascade.PERSIST, Cascade.REMOVE],
|
||||
})
|
||||
images = new Collection<ClaimItemImage>(this)
|
||||
|
||||
@Enum({ items: () => ClaimReason })
|
||||
reason: ClaimReason
|
||||
|
||||
@ManyToOne(() => Claim, {
|
||||
columnType: "text",
|
||||
fieldName: "claim_id",
|
||||
mapToPk: true,
|
||||
onDelete: "cascade",
|
||||
})
|
||||
@ClaimIdIndex.MikroORMIndex()
|
||||
claim_id: string
|
||||
|
||||
@ManyToOne(() => Claim, {
|
||||
persist: false,
|
||||
})
|
||||
claim: Claim
|
||||
|
||||
@ManyToOne({
|
||||
entity: () => LineItem,
|
||||
fieldName: "item_id",
|
||||
mapToPk: true,
|
||||
columnType: "text",
|
||||
})
|
||||
@ItemIdIndex.MikroORMIndex()
|
||||
item_id: string
|
||||
|
||||
@ManyToOne(() => LineItem, {
|
||||
persist: false,
|
||||
})
|
||||
item: LineItem
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
note: string
|
||||
|
||||
@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
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "ordclaimitem")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "ordclaimitem")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
import { BigNumberRawValue, DAL } from "@medusajs/types"
|
||||
import {
|
||||
BigNumber,
|
||||
ClaimType,
|
||||
MikroOrmBigNumberProperty,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Collection,
|
||||
Entity,
|
||||
Enum,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OneToMany,
|
||||
OneToOne,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import ClaimItem from "./claim-item"
|
||||
import Order from "./order"
|
||||
import OrderItem from "./order-item"
|
||||
import OrderShippingMethod from "./order-shipping-method"
|
||||
import Return from "./return"
|
||||
|
||||
type OptionalOrderClaimProps = DAL.EntityDateColumns
|
||||
|
||||
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" })
|
||||
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: Order
|
||||
|
||||
@OneToOne({
|
||||
entity: () => Return,
|
||||
mappedBy: (ret) => ret.claim,
|
||||
cascade: ["soft-remove"] as any,
|
||||
fieldName: "return_id",
|
||||
nullable: true,
|
||||
owner: true,
|
||||
})
|
||||
return: Return
|
||||
|
||||
@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: ClaimType
|
||||
|
||||
@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(() => OrderItem, (itemDetail) => itemDetail.claim, {
|
||||
cascade: [Cascade.PERSIST],
|
||||
})
|
||||
items = new Collection<OrderItem>(this)
|
||||
|
||||
@OneToMany(() => ClaimItem, (itemDetail) => itemDetail.claim, {
|
||||
cascade: [Cascade.PERSIST],
|
||||
})
|
||||
claim_items = new Collection<ClaimItem>(this)
|
||||
|
||||
@OneToMany(
|
||||
() => OrderShippingMethod,
|
||||
(shippingMethod) => shippingMethod.claim,
|
||||
{
|
||||
cascade: [Cascade.PERSIST],
|
||||
}
|
||||
)
|
||||
shipping_methods = new Collection<OrderShippingMethod>(this)
|
||||
|
||||
@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 })
|
||||
@OrderClaimDeletedAtIndex.MikroORMIndex()
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
canceled_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "ordclaim")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "ordclaim")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
import { BigNumberRawValue, DAL } from "@medusajs/types"
|
||||
import {
|
||||
BigNumber,
|
||||
MikroOrmBigNumberProperty,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Collection,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OneToMany,
|
||||
OneToOne,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import Order from "./order"
|
||||
import OrderItem from "./order-item"
|
||||
import OrderShippingMethod from "./order-shipping-method"
|
||||
import Return from "./return"
|
||||
|
||||
type OptionalOrderExchangeProps = DAL.EntityDateColumns
|
||||
|
||||
const DisplayIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_exchange",
|
||||
columns: "display_id",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const OrderExchangeDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_exchange",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const OrderIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_exchange",
|
||||
columns: ["order_id"],
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const ReturnIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_exchange",
|
||||
columns: "return_id",
|
||||
where: "return_id IS NOT NULL AND deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName: "order_exchange" })
|
||||
export default class OrderExchange {
|
||||
[OptionalProps]?: OptionalOrderExchangeProps
|
||||
|
||||
@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: Order
|
||||
|
||||
@OneToOne({
|
||||
entity: () => Return,
|
||||
mappedBy: (ret) => ret.exchange,
|
||||
cascade: ["soft-remove"] as any,
|
||||
fieldName: "return_id",
|
||||
nullable: true,
|
||||
owner: true,
|
||||
})
|
||||
return: Return
|
||||
|
||||
@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
|
||||
|
||||
@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
|
||||
|
||||
@MikroOrmBigNumberProperty({
|
||||
nullable: true,
|
||||
})
|
||||
difference_due: BigNumber | number
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
raw_difference_due: BigNumberRawValue
|
||||
|
||||
@Property({ columnType: "boolean", default: false })
|
||||
allow_backorder: boolean = false
|
||||
|
||||
@OneToMany(() => OrderItem, (itemDetail) => itemDetail.exchange, {
|
||||
cascade: [Cascade.PERSIST],
|
||||
})
|
||||
items = new Collection<OrderItem>(this)
|
||||
|
||||
@OneToMany(
|
||||
() => OrderShippingMethod,
|
||||
(shippingMethod) => shippingMethod.exchange,
|
||||
{
|
||||
cascade: [Cascade.PERSIST],
|
||||
}
|
||||
)
|
||||
shipping_methods = new Collection<OrderShippingMethod>(this)
|
||||
|
||||
@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 })
|
||||
@OrderExchangeDeletedAtIndex.MikroORMIndex()
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
canceled_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "ordexchange")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "ordexchange")
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
export { default as Address } from "./address"
|
||||
export { default as Claim } from "./claim"
|
||||
export { default as ClaimItem } from "./claim-item"
|
||||
export { default as ClaimItemImage } from "./claim-item-image"
|
||||
export { default as Exchange } from "./exchange"
|
||||
export { default as LineItem } from "./line-item"
|
||||
export { default as LineItemAdjustment } from "./line-item-adjustment"
|
||||
export { default as LineItemTaxLine } from "./line-item-tax-line"
|
||||
|
||||
@@ -19,12 +19,7 @@ import {
|
||||
import LineItemAdjustment from "./line-item-adjustment"
|
||||
import LineItemTaxLine from "./line-item-tax-line"
|
||||
|
||||
type OptionalLineItemProps =
|
||||
| "is_discoutable"
|
||||
| "is_tax_inclusive"
|
||||
| "compare_at_unit_price"
|
||||
| "requires_shipping"
|
||||
| DAL.EntityDateColumns
|
||||
type OptionalLineItemProps = DAL.EntityDateColumns
|
||||
|
||||
const ProductIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_line_item",
|
||||
|
||||
@@ -14,9 +14,9 @@ import {
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { Return } from "@models"
|
||||
import Order from "./order"
|
||||
import OrderChange from "./order-change"
|
||||
import Return from "./return"
|
||||
|
||||
type OptionalLineItemProps = DAL.EntityDateColumns
|
||||
|
||||
|
||||
@@ -16,10 +16,10 @@ import {
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { Return } from "@models"
|
||||
import { OrderChangeStatus, OrderChangeType } from "@types"
|
||||
import Order from "./order"
|
||||
import OrderChangeAction from "./order-change-action"
|
||||
import Return from "./return"
|
||||
|
||||
type OptionalLineItemProps = DAL.EntityDateColumns
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { Order } from "@models"
|
||||
import Order from "./order"
|
||||
|
||||
type OrderSummaryTotals = {
|
||||
total: BigNumber
|
||||
|
||||
@@ -15,12 +15,16 @@ import {
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OneToMany,
|
||||
OneToOne,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { OrderItem, OrderShippingMethod } from "@models"
|
||||
import Claim from "./claim"
|
||||
import Exchange from "./exchange"
|
||||
import Order from "./order"
|
||||
import OrderItem from "./order-item"
|
||||
import OrderShippingMethod from "./order-shipping-method"
|
||||
|
||||
type OptionalReturnProps = DAL.EntityDateColumns
|
||||
|
||||
@@ -42,18 +46,18 @@ const OrderIdIndex = createPsqlIndexStatementHelper({
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const ExchangeIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "return",
|
||||
columns: ["exchange_id"],
|
||||
where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const ClaimIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "return",
|
||||
columns: ["claim_id"],
|
||||
where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const ExchageIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "return",
|
||||
columns: ["exchange_id"],
|
||||
where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName: "return" })
|
||||
export default class Return {
|
||||
[OptionalProps]?: OptionalReturnProps
|
||||
@@ -75,37 +79,29 @@ export default class Return {
|
||||
})
|
||||
order: Order
|
||||
|
||||
/*
|
||||
@ManyToOne({
|
||||
entity: () => Claim,
|
||||
mapToPk: true,
|
||||
fieldName: "claim_id",
|
||||
columnType: "text",
|
||||
nullable: true,
|
||||
})
|
||||
@ClaimIdIndex.MikroORMIndex()
|
||||
claim_id: string | null
|
||||
|
||||
@ManyToOne(() => Claim, {
|
||||
persist: false,
|
||||
})
|
||||
claim: Claim | null
|
||||
|
||||
@ManyToOne({
|
||||
@OneToOne({
|
||||
entity: () => Exchange,
|
||||
mapToPk: true,
|
||||
cascade: ["soft-remove"] as any,
|
||||
fieldName: "exchange_id",
|
||||
columnType: "text",
|
||||
nullable: true,
|
||||
})
|
||||
@ExchangeIdIndex.MikroORMIndex()
|
||||
exchange_id: string | null
|
||||
exchange: Exchange
|
||||
|
||||
@ManyToOne(() => Exchange, {
|
||||
persist: false,
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
@ExchangeIdIndex.MikroORMIndex()
|
||||
exchange_id: string | null = null
|
||||
|
||||
@OneToOne({
|
||||
entity: () => Claim,
|
||||
cascade: ["soft-remove"] as any,
|
||||
fieldName: "claim_id",
|
||||
nullable: true,
|
||||
})
|
||||
exchange: Exchange | null
|
||||
*/
|
||||
claim: Claim
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
@ClaimIdIndex.MikroORMIndex()
|
||||
claim_id: string | null = null
|
||||
|
||||
@Property({
|
||||
columnType: "integer",
|
||||
|
||||
@@ -14,8 +14,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"
|
||||
|
||||
type OptionalLineItemProps = DAL.EntityDateColumns
|
||||
|
||||
@@ -37,6 +39,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 CurrencyCodeIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_transaction",
|
||||
columns: "currency_code",
|
||||
@@ -93,6 +107,36 @@ export default class Transaction {
|
||||
})
|
||||
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",
|
||||
defaultRaw: "1",
|
||||
|
||||
Reference in new issue
Block a user