|
1
|
import { model } from "@medusajs/framework/utils" |
|
2
|
import CampaignBudget from "./campaign-budget" |
|
3
|
import Promotion from "./promotion" |
|
4
|
|
|
5
|
const Campaign = model |
|
6
|
.define( |
|
7
|
{ name: "Campaign", tableName: "promotion_campaign" }, |
|
8
|
{ |
|
9
|
id: model.id({ prefix: "procamp" }).primaryKey(), |
|
10
|
name: model.text().searchable(), |
|
11
|
description: model.text().searchable().nullable(), |
|
12
|
campaign_identifier: model.text(), |
|
13
|
starts_at: model.dateTime().nullable(), |
|
14
|
ends_at: model.dateTime().nullable(), |
|
15
|
budget: model |
|
16
|
.hasOne<() => typeof CampaignBudget>(() => CampaignBudget, { |
|
17
|
mappedBy: "campaign", |
|
18
|
}) |
|
19
|
.nullable(), |
|
20
|
promotions: model.hasMany(() => Promotion, { |
|
21
|
mappedBy: "campaign", |
|
22
|
}), |
|
23
|
} |
|
24
|
) |
|
25
|
.cascades({ |
|
26
|
delete: ["budget"], |
|
27
|
}) |
|
28
|
.indexes([ |
|
29
|
{ |
|
30
|
on: ["campaign_identifier"], |
|
31
|
unique: true, |
|
32
|
where: "deleted_at IS NULL", |
|
33
|
}, |
|
34
|
]) |
|
35
|
|
|
36
|
export default Campaign |