Files
medusa-store/packages/modules/promotion/src/models/promotion.ts
2024-12-11 13:12:39 +05:30

36 lines
1.1 KiB
TypeScript

import { PromotionUtils, model } from "@medusajs/framework/utils"
import ApplicationMethod from "./application-method"
import Campaign from "./campaign"
import PromotionRule from "./promotion-rule"
const Promotion = model
.define("Promotion", {
id: model.id({ prefix: "promo" }).primaryKey(),
code: model
.text()
.searchable()
.unique("IDX_promotion_code_unique")
.index("IDX_promotion_code"),
is_automatic: model.boolean().default(false),
type: model.enum(PromotionUtils.PromotionType).index("IDX_promotion_type"),
campaign: model
.belongsTo(() => Campaign, {
mappedBy: "promotions",
})
.nullable(),
application_method: model
.hasOne<() => typeof ApplicationMethod>(() => ApplicationMethod, {
mappedBy: "promotion",
})
.nullable(),
rules: model.manyToMany<() => typeof PromotionRule>(() => PromotionRule, {
pivotTable: "promotion_promotion_rule",
mappedBy: "promotions",
}),
})
.cascades({
delete: ["application_method"],
})
export default Promotion