feat(pricing, types): PriceSets as entry point to pricing module (#4978)

What:
- Adds PriceSet, PriceSetMoneyAmount, updates schema
- Adds service/repo for PriceSet
- Shifts entry point to use PriceSet
- Updates link/joiner config

RESOLVES CORE-1495
This commit is contained in:
Riqwan Thamir
2023-09-11 17:24:31 +00:00
committed by GitHub
parent adf4903003
commit 834da5c41a
29 changed files with 1853 additions and 113 deletions
+2
View File
@@ -1,2 +1,4 @@
export { default as Currency } from "./currency"
export { default as MoneyAmount } from "./money-amount"
export { default as PriceSet } from "./price-set"
export { default as PriceSetMoneyAmount } from "./price-set-money-amount"
@@ -1,13 +1,16 @@
import { generateEntityId } from "@medusajs/utils"
import {
BeforeCreate,
Collection,
Entity,
ManyToMany,
ManyToOne,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import Currency from "./currency"
import PriceSet from "./price-set"
@Entity()
class MoneyAmount {
@@ -17,6 +20,12 @@ class MoneyAmount {
@Property({ columnType: "text", nullable: true })
currency_code?: string
@ManyToMany({
entity: () => PriceSet,
mappedBy: (ps) => ps.money_amounts,
})
price_sets = new Collection<PriceSet>(this)
@ManyToOne(() => Currency, {
nullable: true,
index: "IDX_money_amount_currency_code",
@@ -0,0 +1,39 @@
import { generateEntityId } from "@medusajs/utils"
import {
BeforeCreate,
Entity,
ManyToOne,
PrimaryKey,
PrimaryKeyType,
Property,
} from "@mikro-orm/core"
import MoneyAmount from "./money-amount"
import PriceSet from "./price-set"
@Entity()
export default class PriceSetMoneyAmount {
@PrimaryKey({ columnType: "text" })
id!: string
@Property({ columnType: "text" })
title!: string
@ManyToOne(() => PriceSet, { onDelete: "cascade" })
price_set?: PriceSet
@ManyToOne(() => MoneyAmount, {})
money_amount?: MoneyAmount
@BeforeCreate()
onCreate() {
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
}
}
+28
View File
@@ -0,0 +1,28 @@
import { generateEntityId } from "@medusajs/utils"
import {
BeforeCreate,
Collection,
Entity,
ManyToMany,
PrimaryKey,
} from "@mikro-orm/core"
import MoneyAmount from "./money-amount"
import PriceSetMoneyAmount from "./price-set-money-amount"
@Entity()
export default class PriceSet {
@PrimaryKey({ columnType: "text" })
id!: string
@ManyToMany({
entity: () => MoneyAmount,
pivotEntity: () => PriceSetMoneyAmount,
})
money_amounts = new Collection<MoneyAmount>(this)
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "pset")
}
}