1 import {
2 model,
3 PriceListStatus,
4 PriceListType,
5 } from "@medusajs/framework/utils"
6 import Price from "./price"
7 import PriceListRule from "./price-list-rule"
8
9 const PriceList = model
10 .define("PriceList", {
11 id: model.id({ prefix: "plist" }).primaryKey(),
12 title: model.text().searchable(),
13 description: model.text().searchable(),
14 status: model.enum(PriceListStatus).default(PriceListStatus.DRAFT),
15 type: model.enum(PriceListType).default(PriceListType.SALE),
16 starts_at: model.dateTime().nullable(),
17 ends_at: model.dateTime().nullable(),
18 rules_count: model.number().default(0).nullable(),
19 prices: model.hasMany(() => Price, {
20 mappedBy: "price_list",
21 }),
22 price_list_rules: model.hasMany(() => PriceListRule, {
23 mappedBy: "price_list",
24 }),
25 metadata: model.json().nullable(),
26 })
27 .cascades({
28 delete: ["price_list_rules", "prices"],
29 })
30 .indexes([
31 {
32 on: ["id", "status", "starts_at", "ends_at"],
33 where: "deleted_at IS NULL AND status = 'active'",
34 },
35 ])
36
37 export default PriceList