chore: pricing models uses standardized relationships attributes (#6767)

what:

- all relationships under all models are standardized
This commit is contained in:
Riqwan Thamir
2024-03-21 11:01:52 +01:00
committed by GitHub
parent d930ebc1ed
commit cf8b5ce85b
16 changed files with 157 additions and 402 deletions

View File

@@ -41,9 +41,14 @@ export default class PriceListRuleValue {
@PriceListPriceListRuleIdIndex.MikroORMIndex()
@ManyToOne(() => PriceListRule, {
onDelete: "cascade",
columnType: "text",
mapToPk: true,
fieldName: "price_list_rule_id",
onDelete: "cascade",
})
price_list_rule_id: string
@ManyToOne(() => PriceListRule, { persist: false })
price_list_rule: PriceListRule
@Property({ columnType: "text" })

View File

@@ -52,7 +52,14 @@ export default class PriceListRule {
id!: string
@PriceListRuleRuleTypeIdIndex.MikroORMIndex()
@ManyToOne({ entity: () => RuleType, fieldName: "rule_type_id" })
@ManyToOne(() => RuleType, {
columnType: "text",
mapToPk: true,
fieldName: "rule_type_id",
})
rule_type_id: string
@ManyToOne(() => RuleType, { persist: false })
rule_type: RuleType
@OneToMany(() => PriceListRuleValue, (plrv) => plrv.price_list_rule, {
@@ -61,11 +68,15 @@ export default class PriceListRule {
price_list_rule_values = new Collection<PriceListRuleValue>(this)
@PriceListRulePriceListIdIndex.MikroORMIndex()
@ManyToOne({
entity: () => PriceList,
@ManyToOne(() => PriceList, {
columnType: "text",
mapToPk: true,
fieldName: "price_list_id",
onDelete: "cascade",
})
price_list_id: string
@ManyToOne(() => PriceList, { persist: false })
price_list: PriceList
@Property({

View File

@@ -55,15 +55,26 @@ export default class PriceRule {
id!: string
@PriceRulePriceSetIdIndex.MikroORMIndex()
@ManyToOne({
entity: () => PriceSet,
@ManyToOne(() => PriceSet, {
columnType: "text",
mapToPk: true,
fieldName: "price_set_id",
onDelete: "cascade",
})
price_set_id: string
@ManyToOne(() => PriceSet, { persist: false })
price_set: PriceSet
@PriceRuleRuleTypeIdIndex.MikroORMIndex()
@ManyToOne({ entity: () => RuleType })
@ManyToOne(() => RuleType, {
columnType: "text",
mapToPk: true,
fieldName: "rule_type_id",
})
rule_type_id: string
@ManyToOne(() => RuleType, { persist: false })
rule_type: RuleType
@Property({ columnType: "text" })
@@ -73,10 +84,15 @@ export default class PriceRule {
priority: number = 0
@PriceRulePriceSetMoneyAmountIdIndex.MikroORMIndex()
@ManyToOne({
@ManyToOne(() => PriceSetMoneyAmount, {
columnType: "text",
mapToPk: true,
fieldName: "price_set_money_amount_id",
onDelete: "cascade",
entity: () => PriceSetMoneyAmount,
})
price_set_money_amount_id: string
@ManyToOne(() => PriceSetMoneyAmount, { persist: false })
price_set_money_amount: PriceSetMoneyAmount
@Property({

View File

@@ -1,89 +0,0 @@
import { DAL } from "@medusajs/types"
import {
DALUtils,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Entity,
Filter,
ManyToOne,
OnInit,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import PriceSetMoneyAmount from "./price-set-money-amount"
import RuleType from "./rule-type"
type OptionalFields = DAL.SoftDeletableEntityDateColumns
const tableName = "price_set_money_amount_rules"
const PriceSetMoneyAmountRulesDeletedAtIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "deleted_at",
where: "deleted_at IS NOT NULL",
})
const PriceSetMoneyAmountRulesPriceSetMoneyAmountIdIndex =
createPsqlIndexStatementHelper({
tableName: tableName,
columns: "price_set_money_amount_id",
where: "deleted_at IS NULL",
})
const PriceSetMoneyAmountRulesRuleTypeIdIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: "rule_type_id",
where: "deleted_at IS NULL",
})
@Entity({ tableName })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class PriceSetMoneyAmountRules {
[OptionalProps]?: OptionalFields
@PrimaryKey({ columnType: "text" })
id!: string
@PriceSetMoneyAmountRulesPriceSetMoneyAmountIdIndex.MikroORMIndex()
@ManyToOne(() => PriceSetMoneyAmount, { onDelete: "cascade" })
price_set_money_amount: PriceSetMoneyAmount
@PriceSetMoneyAmountRulesRuleTypeIdIndex.MikroORMIndex()
@ManyToOne(() => RuleType, { onDelete: "cascade" })
rule_type: RuleType
@Property({ columnType: "text" })
value: string
@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
@PriceSetMoneyAmountRulesDeletedAtIndex.MikroORMIndex()
@Property({ columnType: "timestamptz", nullable: true })
deleted_at: Date | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "psmar")
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "psmar")
}
}

View File

@@ -62,12 +62,28 @@ export default class PriceSetMoneyAmount {
title: string | null = null
@PriceSetMoneyAmountPriceSetIdIndex.MikroORMIndex()
@ManyToOne(() => PriceSet, { onDelete: "cascade" })
price_set: PriceSet
@ManyToOne(() => PriceSet, {
columnType: "text",
mapToPk: true,
fieldName: "price_set_id",
onDelete: "cascade",
})
price_set_id: string
@ManyToOne(() => PriceSet, { persist: false })
price_set?: PriceSet
@PriceSetMoneyAmountMoneyAmountIdIndex.MikroORMIndex()
@OneToOne(() => MoneyAmount, { onDelete: "cascade" })
money_amount: MoneyAmount
@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
@@ -80,8 +96,17 @@ export default class PriceSetMoneyAmount {
price_rules = new Collection<PriceRule>(this)
@PriceSetMoneyAmountPriceListIdIndex.MikroORMIndex()
@ManyToOne(() => PriceList, { onDelete: "cascade", nullable: true })
price_list: PriceList | null
@ManyToOne(() => PriceList, {
columnType: "text",
mapToPk: true,
nullable: true,
fieldName: "price_list_id",
onDelete: "cascade",
})
price_list_id: string
@ManyToOne(() => PriceList, { persist: false, nullable: true })
price_list?: PriceList
@Property({
onCreate: () => new Date(),