feat(order): create claim and exchange (#7734)
This commit is contained in:
committed by
GitHub
parent
e0b14519f1
commit
cfa983001b
@@ -76,11 +76,13 @@ export default class ClaimItemImage {
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "ordclaimimg")
|
||||
this.id = generateEntityId(this.id, "climg")
|
||||
this.claim_item_id = this.item?.id
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "ordclaimimg")
|
||||
this.id = generateEntityId(this.id, "climg")
|
||||
this.claim_item_id = this.item?.id
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import { BigNumberRawValue, DAL } from "@medusajs/types"
|
||||
import {
|
||||
ClaimReason,
|
||||
MikroOrmBigNumberProperty,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
@@ -26,11 +27,19 @@ type OptionalLineItemProps = DAL.EntityDateColumns
|
||||
const ClaimIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_claim_item",
|
||||
columns: "claim_id",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const ItemIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_claim_item",
|
||||
columns: "item_id",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const DeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_claim_item_image",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName: "order_claim_item" })
|
||||
@@ -45,8 +54,14 @@ export default class OrderClaimItem {
|
||||
})
|
||||
images = new Collection<ClaimItemImage>(this)
|
||||
|
||||
@Enum({ items: () => ClaimReason })
|
||||
reason: ClaimReason
|
||||
@Enum({ items: () => ClaimReason, nullable: true })
|
||||
reason: ClaimReason | null = null
|
||||
|
||||
@MikroOrmBigNumberProperty()
|
||||
quantity: Number | number
|
||||
|
||||
@Property({ columnType: "jsonb" })
|
||||
raw_quantity: BigNumberRawValue
|
||||
|
||||
@ManyToOne(() => Claim, {
|
||||
columnType: "text",
|
||||
@@ -76,6 +91,9 @@ export default class OrderClaimItem {
|
||||
})
|
||||
item: LineItem
|
||||
|
||||
@Property({ columnType: "boolean", default: false })
|
||||
is_additional_item: boolean = false
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
note: string
|
||||
|
||||
@@ -97,13 +115,19 @@ export default class OrderClaimItem {
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
@DeletedAtIndex.MikroORMIndex()
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "ordclaimitem")
|
||||
this.id = generateEntityId(this.id, "claitem")
|
||||
this.claim_id = this.claim?.id
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "ordclaimitem")
|
||||
this.id = generateEntityId(this.id, "claitem")
|
||||
this.claim_id = this.claim?.id
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ import {
|
||||
} 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"
|
||||
import Transaction from "./transaction"
|
||||
|
||||
type OptionalOrderClaimProps = DAL.EntityDateColumns
|
||||
|
||||
@@ -110,12 +110,12 @@ export default class OrderClaim {
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
raw_refund_amount: BigNumberRawValue
|
||||
|
||||
@OneToMany(() => OrderItem, (itemDetail) => itemDetail.claim, {
|
||||
@OneToMany(() => ClaimItem, (item) => item.claim, {
|
||||
cascade: [Cascade.PERSIST],
|
||||
})
|
||||
items = new Collection<OrderItem>(this)
|
||||
additional_items = new Collection<ClaimItem>(this)
|
||||
|
||||
@OneToMany(() => ClaimItem, (itemDetail) => itemDetail.claim, {
|
||||
@OneToMany(() => ClaimItem, (item) => item.claim, {
|
||||
cascade: [Cascade.PERSIST],
|
||||
})
|
||||
claim_items = new Collection<ClaimItem>(this)
|
||||
@@ -129,6 +129,11 @@ export default class OrderClaim {
|
||||
)
|
||||
shipping_methods = new Collection<OrderShippingMethod>(this)
|
||||
|
||||
@OneToMany(() => Transaction, (transaction) => transaction.claim, {
|
||||
cascade: [Cascade.PERSIST],
|
||||
})
|
||||
transactions = new Collection<Transaction>(this)
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null = null
|
||||
|
||||
@@ -156,11 +161,11 @@ export default class OrderClaim {
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "ordclaim")
|
||||
this.id = generateEntityId(this.id, "claim")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "ordclaim")
|
||||
this.id = generateEntityId(this.id, "claim")
|
||||
}
|
||||
}
|
||||
|
||||
116
packages/modules/order/src/models/exchange-item.ts
Normal file
116
packages/modules/order/src/models/exchange-item.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
import { BigNumberRawValue, DAL } from "@medusajs/types"
|
||||
import {
|
||||
MikroOrmBigNumberProperty,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import Exchange from "./exchange"
|
||||
import LineItem from "./line-item"
|
||||
|
||||
type OptionalLineItemProps = DAL.EntityDateColumns
|
||||
|
||||
const ExchangeIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_exchange_item",
|
||||
columns: "exchange_id",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const ItemIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_exchange_item",
|
||||
columns: "item_id",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const DeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_claim_item_image",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName: "order_exchange_item" })
|
||||
export default class OrderExchangeItem {
|
||||
[OptionalProps]?: OptionalLineItemProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@MikroOrmBigNumberProperty()
|
||||
quantity: Number | number
|
||||
|
||||
@Property({ columnType: "jsonb" })
|
||||
raw_quantity: BigNumberRawValue
|
||||
|
||||
@ManyToOne(() => Exchange, {
|
||||
columnType: "text",
|
||||
fieldName: "exchange_id",
|
||||
mapToPk: true,
|
||||
onDelete: "cascade",
|
||||
})
|
||||
@ExchangeIdIndex.MikroORMIndex()
|
||||
exchange_id: string
|
||||
|
||||
@ManyToOne(() => Exchange, {
|
||||
persist: false,
|
||||
})
|
||||
exchange: Exchange
|
||||
|
||||
@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
|
||||
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
@DeletedAtIndex.MikroORMIndex()
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "oexcitem")
|
||||
this.exchange_id = this.exchange?.id
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "oexcitem")
|
||||
this.exchange_id = this.exchange?.id
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,8 @@ import {
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { ExchangeItem, Transaction } from "@models"
|
||||
import Order from "./order"
|
||||
import OrderItem from "./order-item"
|
||||
import OrderShippingMethod from "./order-shipping-method"
|
||||
import Return from "./return"
|
||||
|
||||
@@ -96,14 +96,6 @@ export default class OrderExchange {
|
||||
@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,
|
||||
})
|
||||
@@ -115,10 +107,10 @@ export default class OrderExchange {
|
||||
@Property({ columnType: "boolean", default: false })
|
||||
allow_backorder: boolean = false
|
||||
|
||||
@OneToMany(() => OrderItem, (itemDetail) => itemDetail.exchange, {
|
||||
@OneToMany(() => ExchangeItem, (item) => item.exchange, {
|
||||
cascade: [Cascade.PERSIST],
|
||||
})
|
||||
items = new Collection<OrderItem>(this)
|
||||
additional_items = new Collection<ExchangeItem>(this)
|
||||
|
||||
@OneToMany(
|
||||
() => OrderShippingMethod,
|
||||
@@ -129,6 +121,11 @@ export default class OrderExchange {
|
||||
)
|
||||
shipping_methods = new Collection<OrderShippingMethod>(this)
|
||||
|
||||
@OneToMany(() => Transaction, (transaction) => transaction.exchange, {
|
||||
cascade: [Cascade.PERSIST],
|
||||
})
|
||||
transactions = new Collection<Transaction>(this)
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null = null
|
||||
|
||||
@@ -156,11 +153,11 @@ export default class OrderExchange {
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "ordexchange")
|
||||
this.id = generateEntityId(this.id, "oexc")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "ordexchange")
|
||||
this.id = generateEntityId(this.id, "oexc")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
export { default as Address } from "./address"
|
||||
export { default as Claim } from "./claim"
|
||||
export { default as OrderClaim } 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 OrderExchange } from "./exchange"
|
||||
export { default as ExchangeItem } from "./exchange-item"
|
||||
export { default as LineItem } from "./line-item"
|
||||
export { default as LineItemAdjustment } from "./line-item-adjustment"
|
||||
export { default as LineItemTaxLine } from "./line-item-tax-line"
|
||||
@@ -13,6 +14,7 @@ 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 Return } from "./return"
|
||||
export { default as ReturnItem } from "./return-item"
|
||||
export { default as ReturnReason } from "./return-reason"
|
||||
export { default as ShippingMethod } from "./shipping-method"
|
||||
export { default as ShippingMethodAdjustment } from "./shipping-method-adjustment"
|
||||
|
||||
@@ -14,6 +14,8 @@ import {
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import OrderClaim from "./claim"
|
||||
import OrderExchange from "./exchange"
|
||||
import Order from "./order"
|
||||
import OrderChange from "./order-change"
|
||||
import Return from "./return"
|
||||
@@ -38,6 +40,18 @@ const ReturnIdIndex = createPsqlIndexStatementHelper({
|
||||
where: "return_id IS NOT NULL AND deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const OrderClaimIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_change_action",
|
||||
columns: "claim_id",
|
||||
where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const OrderExchangeIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_change_action",
|
||||
columns: "exchange_id",
|
||||
where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const DeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_change_action",
|
||||
columns: "deleted_at",
|
||||
@@ -93,6 +107,36 @@ export default class OrderChangeAction {
|
||||
})
|
||||
return: Return
|
||||
|
||||
@ManyToOne({
|
||||
entity: () => OrderClaim,
|
||||
mapToPk: true,
|
||||
fieldName: "claim_id",
|
||||
columnType: "text",
|
||||
nullable: true,
|
||||
})
|
||||
@OrderClaimIdIndex.MikroORMIndex()
|
||||
claim_id: string | null = null
|
||||
|
||||
@ManyToOne(() => OrderClaim, {
|
||||
persist: false,
|
||||
})
|
||||
claim: OrderClaim
|
||||
|
||||
@ManyToOne({
|
||||
entity: () => OrderExchange,
|
||||
mapToPk: true,
|
||||
fieldName: "exchange_id",
|
||||
columnType: "text",
|
||||
nullable: true,
|
||||
})
|
||||
@OrderExchangeIdIndex.MikroORMIndex()
|
||||
exchange_id: string | null = null
|
||||
|
||||
@ManyToOne(() => OrderExchange, {
|
||||
persist: false,
|
||||
})
|
||||
exchange: OrderExchange
|
||||
|
||||
@Property({ columnType: "integer", nullable: true })
|
||||
version: number | null = null
|
||||
|
||||
@@ -172,6 +216,10 @@ export default class OrderChangeAction {
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "ordchact")
|
||||
this.order_id ??= this.order?.id ?? this.order_change?.order_id ?? null
|
||||
this.return_id ??= this.return?.id ?? this.order_change?.return_id ?? null
|
||||
this.claim_id ??= this.claim?.id ?? this.order_change?.claim_id ?? null
|
||||
this.exchange_id ??=
|
||||
this.exchange?.id ?? this.order_change?.exchange_id ?? null
|
||||
this.order_change_id ??= this.order_change?.id ?? null
|
||||
this.version ??= this.order_change?.version ?? null
|
||||
}
|
||||
@@ -180,6 +228,10 @@ export default class OrderChangeAction {
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "ordchact")
|
||||
this.order_id ??= this.order?.id ?? this.order_change?.order_id ?? null
|
||||
this.return_id ??= this.return?.id ?? this.order_change?.return_id ?? null
|
||||
this.claim_id ??= this.claim?.id ?? this.order_change?.claim_id ?? null
|
||||
this.exchange_id ??=
|
||||
this.exchange?.id ?? this.order_change?.exchange_id ?? null
|
||||
this.order_change_id ??= this.order_change?.id ?? null
|
||||
this.version ??= this.order_change?.version ?? null
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ import {
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { OrderChangeStatus, OrderChangeType } from "@types"
|
||||
import OrderClaim from "./claim"
|
||||
import OrderExchange from "./exchange"
|
||||
import Order from "./order"
|
||||
import OrderChangeAction from "./order-change-action"
|
||||
import Return from "./return"
|
||||
@@ -35,6 +37,18 @@ const ReturnIdIndex = createPsqlIndexStatementHelper({
|
||||
where: "return_id IS NOT NULL AND deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const OrderClaimIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_change",
|
||||
columns: "claim_id",
|
||||
where: "claim_id IS NOT NULL AND deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const OrderExchangeIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_change",
|
||||
columns: "exchange_id",
|
||||
where: "exchange_id IS NOT NULL AND deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const OrderChangeStatusIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_change",
|
||||
columns: "status",
|
||||
@@ -97,6 +111,36 @@ export default class OrderChange {
|
||||
})
|
||||
return: Return
|
||||
|
||||
@ManyToOne({
|
||||
entity: () => OrderClaim,
|
||||
mapToPk: true,
|
||||
fieldName: "claim_id",
|
||||
columnType: "text",
|
||||
nullable: true,
|
||||
})
|
||||
@OrderClaimIdIndex.MikroORMIndex()
|
||||
claim_id: string | null = null
|
||||
|
||||
@ManyToOne(() => OrderClaim, {
|
||||
persist: false,
|
||||
})
|
||||
claim: OrderClaim
|
||||
|
||||
@ManyToOne({
|
||||
entity: () => OrderExchange,
|
||||
mapToPk: true,
|
||||
fieldName: "exchange_id",
|
||||
columnType: "text",
|
||||
nullable: true,
|
||||
})
|
||||
@OrderExchangeIdIndex.MikroORMIndex()
|
||||
exchange_id: string | null = null
|
||||
|
||||
@ManyToOne(() => OrderExchange, {
|
||||
persist: false,
|
||||
})
|
||||
exchange: OrderExchange
|
||||
|
||||
@Property({ columnType: "integer" })
|
||||
@VersionIndex.MikroORMIndex()
|
||||
version: number
|
||||
@@ -191,11 +235,17 @@ export default class OrderChange {
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "ordch")
|
||||
this.order_id ??= this.order?.id
|
||||
this.return_id ??= this.return?.id
|
||||
this.claim_id ??= this.claim?.id
|
||||
this.exchange_id ??= this.exchange?.id
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "ordch")
|
||||
this.order_id ??= this.order?.id
|
||||
this.return_id ??= this.return?.id
|
||||
this.claim_id ??= this.claim?.id
|
||||
this.exchange_id ??= this.exchange?.id
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,11 +14,8 @@ import {
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
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
|
||||
|
||||
@@ -28,24 +25,6 @@ const OrderIdIndex = createPsqlIndexStatementHelper({
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const ReturnIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_item",
|
||||
columns: "return_id",
|
||||
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"],
|
||||
@@ -85,51 +64,6 @@ export default class OrderItem {
|
||||
})
|
||||
order: Order
|
||||
|
||||
@ManyToOne({
|
||||
entity: () => Return,
|
||||
mapToPk: true,
|
||||
fieldName: "return_id",
|
||||
columnType: "text",
|
||||
nullable: true,
|
||||
})
|
||||
@ReturnIdIndex.MikroORMIndex()
|
||||
return_id: string | null = null
|
||||
|
||||
@ManyToOne(() => Return, {
|
||||
persist: false,
|
||||
})
|
||||
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
|
||||
@@ -216,9 +150,6 @@ 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
|
||||
}
|
||||
@@ -227,9 +158,6 @@ 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
|
||||
}
|
||||
|
||||
@@ -170,6 +170,7 @@ export default class OrderShippingMethod {
|
||||
this.id = generateEntityId(this.id, "ordspmv")
|
||||
this.order_id ??= this.order?.id
|
||||
this.return_id ??= this.return?.id
|
||||
this.claim_id ??= this.claim?.id
|
||||
this.exchange_id ??= this.exchange?.id
|
||||
this.shipping_method_id ??= this.shipping_method?.id
|
||||
this.version ??= this.order?.version
|
||||
@@ -180,6 +181,7 @@ export default class OrderShippingMethod {
|
||||
this.id = generateEntityId(this.id, "ordspmv")
|
||||
this.order_id ??= this.order?.id
|
||||
this.return_id ??= this.return?.id
|
||||
this.claim_id ??= this.claim?.id
|
||||
this.exchange_id ??= this.exchange?.id
|
||||
this.shipping_method_id ??= this.shipping_method?.id
|
||||
this.version ??= this.order?.version
|
||||
|
||||
143
packages/modules/order/src/models/return-item.ts
Normal file
143
packages/modules/order/src/models/return-item.ts
Normal file
@@ -0,0 +1,143 @@
|
||||
import { BigNumberRawValue, DAL } from "@medusajs/types"
|
||||
import {
|
||||
MikroOrmBigNumberProperty,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import LineItem from "./line-item"
|
||||
import Return from "./return"
|
||||
import ReturnReason from "./return-reason"
|
||||
|
||||
type OptionalLineItemProps = DAL.EntityDateColumns
|
||||
|
||||
const ReturnIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "return_item",
|
||||
columns: "return_id",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const ReturnReasonIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "return_item",
|
||||
columns: "reason_id",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const ItemIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "return_item",
|
||||
columns: "item_id",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const DeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "order_claim_item_image",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName: "return_item" })
|
||||
export default class ReturnItem {
|
||||
[OptionalProps]?: OptionalLineItemProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@ManyToOne(() => ReturnReason, {
|
||||
columnType: "text",
|
||||
fieldName: "reason_id",
|
||||
mapToPk: true,
|
||||
nullable: true,
|
||||
})
|
||||
@ReturnReasonIdIndex.MikroORMIndex()
|
||||
reason_id: string | null = null
|
||||
|
||||
@ManyToOne(() => ReturnReason, {
|
||||
persist: false,
|
||||
})
|
||||
reason: ReturnReason
|
||||
|
||||
@MikroOrmBigNumberProperty()
|
||||
quantity: Number | number
|
||||
|
||||
@Property({ columnType: "jsonb" })
|
||||
raw_quantity: BigNumberRawValue
|
||||
|
||||
@MikroOrmBigNumberProperty()
|
||||
received_quantity: Number | number = 0
|
||||
|
||||
@Property({ columnType: "jsonb" })
|
||||
raw_received_quantity: BigNumberRawValue
|
||||
|
||||
@ManyToOne(() => Return, {
|
||||
columnType: "text",
|
||||
fieldName: "return_id",
|
||||
mapToPk: true,
|
||||
onDelete: "cascade",
|
||||
})
|
||||
@ReturnIdIndex.MikroORMIndex()
|
||||
return_id: string
|
||||
|
||||
@ManyToOne(() => Return, {
|
||||
persist: false,
|
||||
})
|
||||
return: Return
|
||||
|
||||
@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
|
||||
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
@DeletedAtIndex.MikroORMIndex()
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "retitem")
|
||||
this.return_id = this.return?.id
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "retitem")
|
||||
this.return_id = this.return?.id
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { ReturnItem, Transaction } from "@models"
|
||||
import Claim from "./claim"
|
||||
import Exchange from "./exchange"
|
||||
import Order from "./order"
|
||||
@@ -126,7 +127,7 @@ export default class Return {
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
raw_refund_amount: BigNumberRawValue
|
||||
|
||||
@OneToMany(() => OrderItem, (itemDetail) => itemDetail.return, {
|
||||
@OneToMany(() => ReturnItem, (itemDetail) => itemDetail.return, {
|
||||
cascade: [Cascade.PERSIST],
|
||||
})
|
||||
items = new Collection<OrderItem>(this)
|
||||
@@ -140,6 +141,11 @@ export default class Return {
|
||||
)
|
||||
shipping_methods = new Collection<OrderShippingMethod>(this)
|
||||
|
||||
@OneToMany(() => Transaction, (transaction) => transaction.return, {
|
||||
cascade: [Cascade.PERSIST],
|
||||
})
|
||||
transactions = new Collection<Transaction>(this)
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null = null
|
||||
|
||||
|
||||
@@ -189,11 +189,17 @@ export default class Transaction {
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "ordtrx")
|
||||
this.order_id ??= this.order?.id
|
||||
this.return_id ??= this.return?.id
|
||||
this.claim_id ??= this.claim?.id
|
||||
this.exchange_id ??= this.exchange?.id
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "ordtrx")
|
||||
this.order_id ??= this.order?.id
|
||||
this.return_id ??= this.return?.id
|
||||
this.claim_id ??= this.claim?.id
|
||||
this.exchange_id ??= this.exchange?.id
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user