chore: merge money amounts and price set money amounts (#6768)
what: - merges price set money amounts and money amount
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
export { default as MoneyAmount } from "./money-amount"
|
||||
export { default as PriceList } from "./price-list"
|
||||
export { default as PriceListRule } from "./price-list-rule"
|
||||
export { default as PriceListRuleValue } from "./price-list-rule-value"
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
DALUtils,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Filter,
|
||||
OnInit,
|
||||
OneToOne,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { PriceSetMoneyAmount } from "./index"
|
||||
|
||||
type OptionalFields = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const tableName = "money_amount"
|
||||
const MoneyAmountDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const MoneyAmountCurrencyCodeIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "currency_code",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
class MoneyAmount {
|
||||
[OptionalProps]?: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@MoneyAmountCurrencyCodeIndex.MikroORMIndex()
|
||||
@Property({ columnType: "text" })
|
||||
currency_code: string
|
||||
|
||||
@Property({
|
||||
columnType: "numeric",
|
||||
serializer: Number,
|
||||
})
|
||||
amount: number
|
||||
|
||||
@Property({ columnType: "numeric", nullable: true })
|
||||
min_quantity: number | null
|
||||
|
||||
@Property({ columnType: "numeric", nullable: true })
|
||||
max_quantity: number | null
|
||||
|
||||
@OneToOne({
|
||||
entity: () => PriceSetMoneyAmount,
|
||||
mappedBy: (psma) => psma.money_amount,
|
||||
onDelete: "cascade",
|
||||
})
|
||||
price_set_money_amount: PriceSetMoneyAmount
|
||||
|
||||
@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
|
||||
|
||||
@MoneyAmountDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "ma")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "ma")
|
||||
}
|
||||
}
|
||||
|
||||
export default MoneyAmount
|
||||
@@ -13,12 +13,10 @@ import {
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OneToMany,
|
||||
OneToOne,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import MoneyAmount from "./money-amount"
|
||||
import PriceList from "./price-list"
|
||||
import PriceRule from "./price-rule"
|
||||
import PriceSet from "./price-set"
|
||||
@@ -50,6 +48,12 @@ const PriceSetMoneyAmountPriceListIdIndex = createPsqlIndexStatementHelper({
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const PriceSetMoneyAmountCurrencyCodeIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "currency_code",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PriceSetMoneyAmount {
|
||||
@@ -61,6 +65,19 @@ export default class PriceSetMoneyAmount {
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
title: string | null = null
|
||||
|
||||
@PriceSetMoneyAmountCurrencyCodeIndex.MikroORMIndex()
|
||||
@Property({ columnType: "text" })
|
||||
currency_code: string
|
||||
|
||||
@Property({ columnType: "numeric", serializer: Number })
|
||||
amount: number
|
||||
|
||||
@Property({ columnType: "numeric", nullable: true })
|
||||
min_quantity: number | null = null
|
||||
|
||||
@Property({ columnType: "numeric", nullable: true })
|
||||
max_quantity: number | null = null
|
||||
|
||||
@PriceSetMoneyAmountPriceSetIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => PriceSet, {
|
||||
columnType: "text",
|
||||
@@ -73,18 +90,6 @@ export default class PriceSetMoneyAmount {
|
||||
@ManyToOne(() => PriceSet, { persist: false })
|
||||
price_set?: PriceSet
|
||||
|
||||
@PriceSetMoneyAmountMoneyAmountIdIndex.MikroORMIndex()
|
||||
@OneToOne(() => MoneyAmount, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "money_amount_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
money_amount_id: string
|
||||
|
||||
@OneToOne(() => MoneyAmount, { persist: false })
|
||||
money_amount?: MoneyAmount
|
||||
|
||||
@Property({ columnType: "integer", default: 0 })
|
||||
rules_count: number = 0
|
||||
|
||||
@@ -103,10 +108,10 @@ export default class PriceSetMoneyAmount {
|
||||
fieldName: "price_list_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
price_list_id: string
|
||||
price_list_id: string | null = null
|
||||
|
||||
@ManyToOne(() => PriceList, { persist: false, nullable: true })
|
||||
price_list?: PriceList
|
||||
price_list: PriceList | null = null
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
|
||||
Reference in New Issue
Block a user