feat(pricing): add price rule entity (#5050)

**What**
- add price-rule entity to pricing module

blocked by #4977 

Fixes CORE-1497

Co-authored-by: Riqwan Thamir <5105988+riqwan@users.noreply.github.com>
Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
This commit is contained in:
Philip Korsholm
2023-09-26 12:59:55 +00:00
committed by GitHub
co-authored by Riqwan Thamir Adrien de Peretti
parent b3f1135fba
commit bc42b201ea
20 changed files with 1444 additions and 18 deletions
+1
View File
@@ -3,3 +3,4 @@ export { default as MoneyAmount } from "./money-amount"
export { default as PriceSet } from "./price-set"
export { default as PriceSetMoneyAmount } from "./price-set-money-amount"
export { default as RuleType } from "./rule-type"
export { default as PriceRule } from "./price-rule"
+69
View File
@@ -0,0 +1,69 @@
import {
BeforeCreate,
Collection,
Entity,
ManyToMany,
ManyToOne,
OneToMany,
OneToOne,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import MoneyAmount from "./money-amount"
import PriceSet from "./price-set"
import PriceSetMoneyAmount from "./price-set-money-amount"
import RuleType from "./rule-type"
import { generateEntityId } from "@medusajs/utils"
type OptionalFields = "id" | "is_dynamic" | "priority"
type OptionalRelations = "price_set" | "rule_type" | "price_set_money_amount"
@Entity()
export default class PriceRule {
[OptionalProps]: OptionalFields | OptionalRelations
@PrimaryKey({ columnType: "text" })
id!: string
@ManyToOne({
entity: () => PriceSet,
fieldName: "price_set_id",
name: "price_rule_price_set_id_unique",
})
price_set: PriceSet
@ManyToOne({
entity: () => RuleType,
fieldName: "rule_type_id",
name: "price_rule_rule_type_id_unique",
})
rule_type: RuleType
@Property({ columnType: "boolean", default: false })
is_dynamic: boolean
@Property({ columnType: "text" })
value: string
@Property({ columnType: "integer", default: 0 })
priority: number
@ManyToOne({
entity: () => PriceSetMoneyAmount,
fieldName: "price_set_money_amount_id",
name: "price_set_money_amount_id_unique",
})
price_set_money_amount: PriceSetMoneyAmount
@Property({ columnType: "text" })
price_list_id!: string
// TODO: Add price list
@BeforeCreate()
beforeCreate() {
this.id = generateEntityId(this.id, "pset")
}
}