1 import { PromotionUtils, model } from "@medusajs/framework/utils"
2 import Promotion from "./promotion"
3 import PromotionRule from "./promotion-rule"
4
5 const ApplicationMethod = model
6 .define(
7 { name: "ApplicationMethod", tableName: "promotion_application_method" },
8 {
9 id: model.id({ prefix: "proappmet" }).primaryKey(),
10 value: model.bigNumber().nullable(),
11 currency_code: model.text().nullable(),
12 max_quantity: model.number().nullable(),
13 apply_to_quantity: model.number().nullable(),
14 buy_rules_min_quantity: model.number().nullable(),
15 type: model
16 .enum(PromotionUtils.ApplicationMethodType)
17 .index("IDX_application_method_type"),
18 target_type: model
19 .enum(PromotionUtils.ApplicationMethodTargetType)
20 .index("IDX_application_method_target_type"),
21 allocation: model
22 .enum(PromotionUtils.ApplicationMethodAllocation)
23 .index("IDX_application_method_allocation")
24 .nullable(),
25 promotion: model.belongsTo(() => Promotion, {
26 mappedBy: "application_method",
27 }),
28 target_rules: model.manyToMany(() => PromotionRule, {
29 pivotTable: "application_method_target_rules",
30 mappedBy: "method_target_rules",
31 }),
32 buy_rules: model.manyToMany(() => PromotionRule, {
33 pivotTable: "application_method_buy_rules",
34 mappedBy: "method_buy_rules",
35 }),
36 }
37 )
38 .indexes([
39 {
40 on: ["currency_code"],
41 where: "deleted_at IS NOT NULL",
42 },
43 ])
44
45 export default ApplicationMethod