feat(pricing): pricing models are made soft deletable (#6732)
what: - pricing models are made soft deletable - adds missing timestamp attributes - removes unwanted relationships + cascade cleanup
This commit is contained in:
@@ -5,6 +5,5 @@ export { default as PriceListRuleValue } from "./price-list-rule-value"
|
||||
export { default as PriceRule } from "./price-rule"
|
||||
export { default as PriceSet } from "./price-set"
|
||||
export { default as PriceSetMoneyAmount } from "./price-set-money-amount"
|
||||
export { default as PriceSetMoneyAmountRules } from "./price-set-money-amount-rules"
|
||||
export { default as PriceSetRuleType } from "./price-set-rule-type"
|
||||
export { default as RuleType } from "./rule-type"
|
||||
|
||||
@@ -1,60 +1,53 @@
|
||||
import { DALUtils, generateEntityId } from "@medusajs/utils"
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
DALUtils,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
Index,
|
||||
ManyToMany,
|
||||
OnInit,
|
||||
OneToOne,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
|
||||
import { PriceSetMoneyAmount } from "./index"
|
||||
import PriceSet from "./price-set"
|
||||
|
||||
@Entity()
|
||||
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]?:
|
||||
| "created_at"
|
||||
| "updated_at"
|
||||
| "deleted_at"
|
||||
| "price_set_money_amount"
|
||||
| "amount"
|
||||
[OptionalProps]?: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@Property({
|
||||
columnType: "text",
|
||||
nullable: true,
|
||||
index: "IDX_money_amount_currency_code",
|
||||
})
|
||||
currency_code: string | null
|
||||
|
||||
@ManyToMany({
|
||||
entity: () => PriceSet,
|
||||
mappedBy: (ps) => ps.money_amounts,
|
||||
})
|
||||
price_sets = new Collection<PriceSet>(this)
|
||||
|
||||
@OneToOne({
|
||||
entity: () => PriceSetMoneyAmount,
|
||||
mappedBy: (psma) => psma.money_amount,
|
||||
cascade: ["soft-remove"] as any,
|
||||
})
|
||||
price_set_money_amount: PriceSetMoneyAmount
|
||||
@MoneyAmountCurrencyCodeIndex.MikroORMIndex()
|
||||
@Property({ columnType: "text" })
|
||||
currency_code: string
|
||||
|
||||
@Property({
|
||||
columnType: "numeric",
|
||||
nullable: true,
|
||||
serializer: Number,
|
||||
})
|
||||
amount: number | null
|
||||
amount: number
|
||||
|
||||
@Property({ columnType: "numeric", nullable: true })
|
||||
min_quantity: number | null
|
||||
@@ -62,6 +55,13 @@ class MoneyAmount {
|
||||
@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",
|
||||
@@ -77,9 +77,9 @@ class MoneyAmount {
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@Index({ name: "IDX_money_amount_deleted_at" })
|
||||
@MoneyAmountDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
|
||||
@@ -1,30 +1,73 @@
|
||||
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 PriceListRule from "./price-list-rule"
|
||||
import { generateEntityId } from "@medusajs/utils"
|
||||
|
||||
@Entity()
|
||||
type OptionalFields = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const tableName = "price_list_rule_value"
|
||||
const PriceListRuleValueDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const PriceListPriceListRuleIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "price_list_rule_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PriceListRuleValue {
|
||||
[OptionalProps]?: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@PriceListPriceListRuleIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => PriceListRule, {
|
||||
onDelete: "cascade",
|
||||
fieldName: "price_list_rule_id",
|
||||
index: "IDX_price_list_rule_price_list_rule_value_id",
|
||||
})
|
||||
price_list_rule: PriceListRule
|
||||
|
||||
@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
|
||||
|
||||
@PriceListRuleValueDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "plrv")
|
||||
|
||||
@@ -1,56 +1,92 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
DALUtils,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
OnInit,
|
||||
OneToMany,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Unique,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
|
||||
import { generateEntityId } from "@medusajs/utils"
|
||||
import PriceList from "./price-list"
|
||||
import PriceListRuleValue from "./price-list-rule-value"
|
||||
import RuleType from "./rule-type"
|
||||
|
||||
type OptionalFields = "id"
|
||||
type OptionalRelations = "rule_type" | "price_list"
|
||||
type OptionalFields = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
@Entity()
|
||||
@Unique({
|
||||
name: "IDX_price_list_rule_rule_type_id_price_list_id_unique",
|
||||
properties: ["price_list", "rule_type"],
|
||||
const tableName = "price_list_rule"
|
||||
const PriceListRuleDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const PriceListRuleRuleTypeIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "rule_type_id",
|
||||
where: "deleted_at IS NULL",
|
||||
unique: true,
|
||||
})
|
||||
|
||||
const PriceListRulePriceListIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "price_list_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PriceListRule {
|
||||
[OptionalProps]: OptionalFields | OptionalRelations
|
||||
[OptionalProps]: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@ManyToOne({
|
||||
entity: () => RuleType,
|
||||
fieldName: "rule_type_id",
|
||||
name: "price_rule_rule_type_id_unique",
|
||||
index: "IDX_price_list_rule_rule_type_id",
|
||||
})
|
||||
@PriceListRuleRuleTypeIdIndex.MikroORMIndex()
|
||||
@ManyToOne({ entity: () => RuleType, fieldName: "rule_type_id" })
|
||||
rule_type: RuleType
|
||||
|
||||
@OneToMany(() => PriceListRuleValue, (plrv) => plrv.price_list_rule, {
|
||||
cascade: [Cascade.REMOVE],
|
||||
cascade: ["soft-remove" as Cascade],
|
||||
})
|
||||
price_list_rule_values = new Collection<PriceListRuleValue>(this)
|
||||
|
||||
@PriceListRulePriceListIdIndex.MikroORMIndex()
|
||||
@ManyToOne({
|
||||
entity: () => PriceList,
|
||||
fieldName: "price_list_id",
|
||||
name: "price_rule_price_list_id",
|
||||
index: "IDX_price_list_rule_price_list_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
price_list: PriceList
|
||||
|
||||
@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
|
||||
|
||||
@PriceListRuleDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
beforeCreate() {
|
||||
this.id = generateEntityId(this.id, "plrule")
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
generateEntityId,
|
||||
DALUtils,
|
||||
PriceListStatus,
|
||||
PriceListType,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
@@ -9,10 +12,10 @@ import {
|
||||
Collection,
|
||||
Entity,
|
||||
Enum,
|
||||
Index,
|
||||
Filter,
|
||||
ManyToMany,
|
||||
OneToMany,
|
||||
OnInit,
|
||||
OneToMany,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
@@ -22,23 +25,21 @@ import PriceSetMoneyAmount from "./price-set-money-amount"
|
||||
import RuleType from "./rule-type"
|
||||
|
||||
type OptionalFields =
|
||||
| "status"
|
||||
| "type"
|
||||
| "rules_count"
|
||||
| "starts_at"
|
||||
| "ends_at"
|
||||
| "created_at"
|
||||
| "updated_at"
|
||||
| "deleted_at"
|
||||
| DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
type OptionalRelations =
|
||||
| "price_set_money_amounts"
|
||||
| "rule_types"
|
||||
| "price_list_rules"
|
||||
const tableName = "price_list"
|
||||
const PriceListDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PriceList {
|
||||
[OptionalProps]: OptionalFields | OptionalRelations
|
||||
[OptionalProps]: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
@@ -59,33 +60,32 @@ export default class PriceList {
|
||||
columnType: "timestamptz",
|
||||
nullable: true,
|
||||
})
|
||||
starts_at: Date | null
|
||||
starts_at: Date | null = null
|
||||
|
||||
@Property({
|
||||
columnType: "timestamptz",
|
||||
nullable: true,
|
||||
})
|
||||
ends_at: Date | null
|
||||
ends_at: Date | null = null
|
||||
|
||||
@OneToMany(() => PriceSetMoneyAmount, (psma) => psma.price_list, {
|
||||
cascade: [Cascade.REMOVE],
|
||||
cascade: ["soft-remove" as Cascade],
|
||||
})
|
||||
price_set_money_amounts = new Collection<PriceSetMoneyAmount>(this)
|
||||
|
||||
@OneToMany(() => PriceListRule, (pr) => pr.price_list, {
|
||||
cascade: [Cascade.REMOVE],
|
||||
cascade: ["soft-remove" as Cascade],
|
||||
})
|
||||
price_list_rules = new Collection<PriceListRule>(this)
|
||||
|
||||
@ManyToMany({
|
||||
entity: () => RuleType,
|
||||
pivotEntity: () => PriceListRule,
|
||||
cascade: [Cascade.REMOVE],
|
||||
})
|
||||
rule_types = new Collection<RuleType>(this)
|
||||
|
||||
@Property({ columnType: "integer", default: 0 })
|
||||
rules_count?: number
|
||||
rules_count: number = 0
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
@@ -102,9 +102,9 @@ export default class PriceList {
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@Index({ name: "IDX_price_list_deleted_at" })
|
||||
@PriceListDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
|
||||
@@ -1,66 +1,81 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
DALUtils,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Filter,
|
||||
Index,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { DALUtils, generateEntityId } from "@medusajs/utils"
|
||||
|
||||
import PriceSet from "./price-set"
|
||||
import PriceSetMoneyAmount from "./price-set-money-amount"
|
||||
import RuleType from "./rule-type"
|
||||
|
||||
type OptionalFields =
|
||||
| "id"
|
||||
| "is_dynamic"
|
||||
| "priority"
|
||||
| "created_at"
|
||||
| "updated_at"
|
||||
| "deleted_at"
|
||||
type OptionalRelations = "price_set" | "rule_type" | "price_set_money_amount"
|
||||
type OptionalFields = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
@Entity()
|
||||
const tableName = "price_rule"
|
||||
const PriceRuleDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const PriceRulePriceSetIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "price_set_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const PriceRuleRuleTypeIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "rule_type_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const PriceRulePriceSetMoneyAmountIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "price_set_money_amount_id",
|
||||
where: "deleted_at IS NULL",
|
||||
unique: true,
|
||||
})
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PriceRule {
|
||||
[OptionalProps]: OptionalFields | OptionalRelations
|
||||
[OptionalProps]?: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@PriceRulePriceSetIdIndex.MikroORMIndex()
|
||||
@ManyToOne({
|
||||
entity: () => PriceSet,
|
||||
fieldName: "price_set_id",
|
||||
name: "price_rule_price_set_id_unique",
|
||||
onDelete: "cascade",
|
||||
index: "IDX_price_rule_price_set_id",
|
||||
})
|
||||
price_set: PriceSet
|
||||
|
||||
@ManyToOne({
|
||||
entity: () => RuleType,
|
||||
fieldName: "rule_type_id",
|
||||
name: "price_rule_rule_type_id_unique",
|
||||
index: "IDX_price_rule_rule_type_id",
|
||||
})
|
||||
@PriceRuleRuleTypeIdIndex.MikroORMIndex()
|
||||
@ManyToOne({ entity: () => RuleType })
|
||||
rule_type: RuleType
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
value: string
|
||||
|
||||
@Property({ columnType: "integer", default: 0 })
|
||||
priority: number
|
||||
priority: number = 0
|
||||
|
||||
@PriceRulePriceSetMoneyAmountIdIndex.MikroORMIndex()
|
||||
@ManyToOne({
|
||||
onDelete: "cascade",
|
||||
entity: () => PriceSetMoneyAmount,
|
||||
fieldName: "price_set_money_amount_id",
|
||||
name: "price_set_money_amount_id_unique",
|
||||
index: "IDX_price_rule_price_set_money_amount_id",
|
||||
})
|
||||
price_set_money_amount: PriceSetMoneyAmount
|
||||
|
||||
@@ -79,9 +94,9 @@ export default class PriceRule {
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@Index({ name: "IDX_price_rule_deleted_at" })
|
||||
@PriceRuleDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
beforeCreate() {
|
||||
|
||||
@@ -1,35 +1,82 @@
|
||||
import { generateEntityId } from "@medusajs/utils"
|
||||
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"
|
||||
|
||||
@Entity()
|
||||
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
|
||||
|
||||
@ManyToOne(() => PriceSetMoneyAmount, {
|
||||
onDelete: "cascade",
|
||||
index: "IDX_price_set_money_amount_rules_price_set_money_amount_id",
|
||||
})
|
||||
@PriceSetMoneyAmountRulesPriceSetMoneyAmountIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => PriceSetMoneyAmount, { onDelete: "cascade" })
|
||||
price_set_money_amount: PriceSetMoneyAmount
|
||||
|
||||
@ManyToOne(() => RuleType, {
|
||||
index: "IDX_price_set_money_amount_rules_rule_type_id",
|
||||
})
|
||||
@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")
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
DALUtils,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
@@ -5,67 +11,76 @@ import {
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OneToMany,
|
||||
OneToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
PrimaryKeyType,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { DALUtils, generateEntityId } from "@medusajs/utils"
|
||||
|
||||
import MoneyAmount from "./money-amount"
|
||||
import PriceList from "./price-list"
|
||||
import PriceRule from "./price-rule"
|
||||
import PriceSet from "./price-set"
|
||||
import PriceSetMoneyAmountRules from "./price-set-money-amount-rules"
|
||||
|
||||
@Entity()
|
||||
type OptionalFields = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const tableName = "price_set_money_amount"
|
||||
const PriceSetMoneyAmountDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const PriceSetMoneyAmountPriceSetIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "price_set_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const PriceSetMoneyAmountMoneyAmountIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "money_amount_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const PriceSetMoneyAmountPriceListIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "price_list_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PriceSetMoneyAmount {
|
||||
[OptionalProps]?: "created_at" | "updated_at" | "deleted_at"
|
||||
[OptionalProps]?: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
title!: string
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
title: string | null = null
|
||||
|
||||
@ManyToOne(() => PriceSet, {
|
||||
onDelete: "cascade",
|
||||
index: "IDX_price_set_money_amount_price_set_id",
|
||||
})
|
||||
@PriceSetMoneyAmountPriceSetIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => PriceSet, { onDelete: "cascade" })
|
||||
price_set: PriceSet
|
||||
|
||||
@OneToOne(() => MoneyAmount, {
|
||||
onDelete: "cascade",
|
||||
index: "IDX_price_set_money_amount_money_amount_id",
|
||||
})
|
||||
@PriceSetMoneyAmountMoneyAmountIdIndex.MikroORMIndex()
|
||||
@OneToOne(() => MoneyAmount, { onDelete: "cascade" })
|
||||
money_amount: MoneyAmount
|
||||
|
||||
@Property({ columnType: "integer", default: 0 })
|
||||
rules_count: number
|
||||
rules_count: number = 0
|
||||
|
||||
@OneToMany({
|
||||
entity: () => PriceRule,
|
||||
mappedBy: (pr) => pr.price_set_money_amount,
|
||||
cascade: ["soft-remove"] as any,
|
||||
cascade: ["soft-remove" as Cascade],
|
||||
})
|
||||
price_rules = new Collection<PriceRule>(this)
|
||||
|
||||
@OneToMany({
|
||||
entity: () => PriceSetMoneyAmountRules,
|
||||
mappedBy: (psmar) => psmar.price_set_money_amount,
|
||||
})
|
||||
price_set_money_amount_rules = new Collection<PriceSetMoneyAmountRules>(this)
|
||||
|
||||
@ManyToOne(() => PriceList, {
|
||||
index: "IDX_price_rule_price_list_id",
|
||||
onDelete: "cascade",
|
||||
cascade: [Cascade.REMOVE, "soft-remove"] as any,
|
||||
nullable: true,
|
||||
})
|
||||
@PriceSetMoneyAmountPriceListIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => PriceList, { onDelete: "cascade", nullable: true })
|
||||
price_list: PriceList | null
|
||||
|
||||
@Property({
|
||||
@@ -83,12 +98,9 @@ export default class PriceSetMoneyAmount {
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@Property({
|
||||
columnType: "timestamptz",
|
||||
nullable: true,
|
||||
index: "IDX_price_set_money_amount_deleted_at",
|
||||
})
|
||||
deleted_at: Date | null
|
||||
@PriceSetMoneyAmountDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
@@ -99,11 +111,4 @@ export default class PriceSetMoneyAmount {
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "psma")
|
||||
}
|
||||
|
||||
[PrimaryKeyType]?: [string, string]
|
||||
|
||||
constructor(money_amount: MoneyAmount, price_set: PriceSet) {
|
||||
this.money_amount = money_amount
|
||||
this.price_set = price_set
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,72 @@
|
||||
import {
|
||||
DALUtils,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
|
||||
import PriceSet from "./price-set"
|
||||
import RuleType from "./rule-type"
|
||||
import { generateEntityId } from "@medusajs/utils"
|
||||
|
||||
@Entity()
|
||||
const tableName = "price_set_rule_type"
|
||||
const PriceSetRuleTypeDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const PriceSetRuleTypePriceSetIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "price_set_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const PriceSetRuleTypeRuleTypeIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "rule_type_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PriceSetRuleType {
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@ManyToOne(() => PriceSet, {
|
||||
onDelete: "cascade",
|
||||
index: "IDX_price_set_rule_type_price_set_id",
|
||||
})
|
||||
@PriceSetRuleTypePriceSetIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => PriceSet, { onDelete: "cascade" })
|
||||
price_set: PriceSet
|
||||
|
||||
@ManyToOne(() => RuleType, {
|
||||
index: "IDX_price_set_rule_type_rule_type_id",
|
||||
})
|
||||
@PriceSetRuleTypeRuleTypeIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => RuleType, { onDelete: "cascade" })
|
||||
rule_type: RuleType
|
||||
|
||||
@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
|
||||
|
||||
@PriceSetRuleTypeDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "psrt")
|
||||
|
||||
@@ -1,52 +1,74 @@
|
||||
import { generateEntityId } from "@medusajs/utils"
|
||||
import {
|
||||
DALUtils,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToMany,
|
||||
OneToMany,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
OneToMany,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
|
||||
import MoneyAmount from "./money-amount"
|
||||
import PriceRule from "./price-rule"
|
||||
import PriceSetMoneyAmount from "./price-set-money-amount"
|
||||
import PriceSetRuleType from "./price-set-rule-type"
|
||||
import RuleType from "./rule-type"
|
||||
|
||||
@Entity()
|
||||
export default class PriceSet {
|
||||
[OptionalProps]?: "price_set_money_amounts" | "rule_types" | "money_amounts"
|
||||
const tableName = "price_set"
|
||||
const PriceSetDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PriceSet {
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@OneToMany(() => PriceSetMoneyAmount, (psma) => psma.price_set, {
|
||||
cascade: [Cascade.REMOVE],
|
||||
cascade: ["soft-remove" as Cascade],
|
||||
})
|
||||
price_set_money_amounts = new Collection<PriceSetMoneyAmount>(this)
|
||||
|
||||
@OneToMany(() => PriceRule, (pr) => pr.price_set, {
|
||||
cascade: [Cascade.REMOVE],
|
||||
cascade: ["soft-remove" as Cascade],
|
||||
})
|
||||
price_rules = new Collection<PriceRule>(this)
|
||||
|
||||
@ManyToMany({
|
||||
entity: () => MoneyAmount,
|
||||
pivotEntity: () => PriceSetMoneyAmount,
|
||||
})
|
||||
money_amounts = new Collection<MoneyAmount>(this)
|
||||
|
||||
@ManyToMany({
|
||||
entity: () => RuleType,
|
||||
pivotEntity: () => PriceSetRuleType,
|
||||
cascade: [Cascade.REMOVE],
|
||||
cascade: ["soft-remove" as Cascade],
|
||||
})
|
||||
rule_types = new Collection<RuleType>(this)
|
||||
|
||||
@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
|
||||
|
||||
@PriceSetDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "pset")
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import { generateEntityId } from "@medusajs/utils"
|
||||
import {
|
||||
DALUtils,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToMany,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
@@ -13,7 +18,21 @@ import PriceSet from "./price-set"
|
||||
|
||||
type OptionalFields = "default_priority"
|
||||
|
||||
@Entity()
|
||||
const tableName = "rule_type"
|
||||
const RuleTypeDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const RuleTypeRuleAttributeIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "rule_attribute",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
class RuleType {
|
||||
[OptionalProps]?: OptionalFields
|
||||
|
||||
@@ -23,7 +42,8 @@ class RuleType {
|
||||
@Property({ columnType: "text" })
|
||||
name: string
|
||||
|
||||
@Property({ columnType: "text", index: "IDX_rule_type_rule_attribute" })
|
||||
@RuleTypeRuleAttributeIndex.MikroORMIndex()
|
||||
@Property({ columnType: "text" })
|
||||
rule_attribute: string
|
||||
|
||||
@Property({ columnType: "integer", default: 0 })
|
||||
@@ -47,6 +67,10 @@ class RuleType {
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@RuleTypeDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "rul-typ")
|
||||
|
||||
Reference in New Issue
Block a user