1 import { model } from "@medusajs/framework/utils"
2 import PriceList from "./price-list"
3 import PriceRule from "./price-rule"
4 import PriceSet from "./price-set"
5
6 const Price = model
7 .define("Price", {
8 id: model.id({ prefix: "price" }).primaryKey(),
9 title: model.text().nullable(),
10 currency_code: model.text(),
11 amount: model.bigNumber(),
12 min_quantity: model.bigNumber().nullable(),
13 max_quantity: model.bigNumber().nullable(),
14 rules_count: model.number().default(0).nullable(),
15 price_set: model.belongsTo(() => PriceSet, {
16 mappedBy: "prices",
17 }),
18 price_rules: model.hasMany(() => PriceRule, {
19 mappedBy: "price",
20 }),
21 price_list: model
22 .belongsTo(() => PriceList, {
23 mappedBy: "prices",
24 })
25 .nullable(),
26 })
27 .cascades({
28 delete: ["price_rules"],
29 })
30 .indexes([
31 {
32 on: ["price_set_id"],
33 where: "deleted_at IS NULL",
34 },
35 {
36 on: ["price_list_id"],
37 where: "deleted_at IS NULL",
38 },
39 {
40 on: ["currency_code"],
41 where: "deleted_at IS NULL",
42 },
43 ])
44
45 export default Price