Files
medusa-store/packages/modules/promotion/src/models/promotion.ts
juanzgc ef15868ca8 feat(promotion): Add metadata column to promotion (#13999)
* feat(promotion): Add metadata column to promotion

Add metadata column to the promotion model.

Closes CORE-1276

* Add changeset

---------

Co-authored-by: Frane Polić <16856471+fPolic@users.noreply.github.com>
2025-11-17 19:50:57 +01:00

52 lines
1.5 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(),
is_automatic: model.boolean().default(false),
is_tax_inclusive: model.boolean().default(false),
type: model.enum(PromotionUtils.PromotionType).index("IDX_promotion_type"),
status: model
.enum(PromotionUtils.PromotionStatus)
.index("IDX_promotion_status")
.default(PromotionUtils.PromotionStatus.DRAFT),
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",
}),
metadata: model.json().nullable(),
})
.cascades({
delete: ["application_method"],
})
.indexes([
{
name: "IDX_unique_promotion_code",
on: ["code"],
where: "deleted_at IS NULL",
unique: true,
},
{
name: "IDX_promotion_is_automatic",
on: ["is_automatic"],
unique: false,
where: "deleted_at IS NULL",
},
])
export default Promotion