agrs-sequelize-sdk 1.4.16 → 1.4.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/migrations/2026-05-17-PIXELS-FOLLOWUP.md +85 -0
  2. package/migrations/2026-05-17-add-platform-to-ad.js +19 -0
  3. package/migrations/2026-05-17-add-platform-to-adaccount.js +19 -0
  4. package/migrations/2026-05-17-add-platform-to-adperformance.js +19 -0
  5. package/migrations/2026-05-17-add-platform-to-adset.js +19 -0
  6. package/migrations/2026-05-17-add-platform-to-adsetperformance.js +19 -0
  7. package/migrations/2026-05-17-add-platform-to-aiarticleretryqueue.js +19 -0
  8. package/migrations/2026-05-17-add-platform-to-aicampaignqueue.js +19 -0
  9. package/migrations/2026-05-17-add-platform-to-article.js +19 -0
  10. package/migrations/2026-05-17-add-platform-to-campaign.js +19 -0
  11. package/migrations/2026-05-17-add-platform-to-codefuelcampaign.js +19 -0
  12. package/migrations/2026-05-17-add-platform-to-dynamicfeed.js +19 -0
  13. package/migrations/2026-05-17-add-platform-to-facebookretryqueue.js +19 -0
  14. package/migrations/2026-05-17-add-platform-to-pages.js +19 -0
  15. package/migrations/2026-05-17-add-platform-to-presets.js +19 -0
  16. package/migrations/RUN_ME_MANUALLY_2026-05-17.sql +99 -0
  17. package/migrations/add-requested-from-dashboard-to-articles.js +17 -17
  18. package/migrations/change-adset-name-to-text.js +79 -79
  19. package/models/AICampaignQueue.js +143 -136
  20. package/models/AIGenerationLog.js +85 -85
  21. package/models/AIGenerationRequest.js +212 -212
  22. package/models/Ad.js +6 -0
  23. package/models/AdAccount.js +6 -0
  24. package/models/AdAccountValues.js +25 -25
  25. package/models/AdHistory.js +30 -30
  26. package/models/AdPerformance.js +100 -94
  27. package/models/AdSet.js +295 -289
  28. package/models/AdSetHistory.js +30 -30
  29. package/models/AdsetPerformance.js +132 -126
  30. package/models/AiArticleRetryQueue.js +157 -150
  31. package/models/AiCreationRetryQueue.js +127 -127
  32. package/models/Article.js +212 -206
  33. package/models/AutomationRule.js +173 -173
  34. package/models/BannerTemplate.js +129 -129
  35. package/models/Buyers.js +25 -25
  36. package/models/Campaign.js +163 -157
  37. package/models/CampaignActionHistory.js +86 -86
  38. package/models/CampaignCreationLog.js +309 -309
  39. package/models/CampaignCreationLogV2.js +314 -314
  40. package/models/CampaignHistory.js +33 -33
  41. package/models/Channel.js +55 -55
  42. package/models/CodefuelCampaign.js +6 -0
  43. package/models/Domain.js +39 -47
  44. package/models/DynamicFeed.js +218 -212
  45. package/models/ExplorAdsChannel.js +61 -61
  46. package/models/FacebookRetryQueue.js +163 -156
  47. package/models/Feed.js +33 -33
  48. package/models/FeedArticleConfiguration.js +80 -80
  49. package/models/FrontStoryChannel.js +59 -59
  50. package/models/FrontStoryChannelV2.js +60 -60
  51. package/models/GenericFlowRequest.js +114 -114
  52. package/models/MidoWebChannel.js +47 -47
  53. package/models/MineChannel.js +42 -42
  54. package/models/Pages.js +105 -99
  55. package/models/PipelineExecution.js +59 -59
  56. package/models/PolicyDogsCreativeCache.js +50 -50
  57. package/models/PolicyDogsImageCache.js +30 -30
  58. package/models/Presets.js +40 -34
  59. package/models/RSOCFeedCampaign.js +375 -375
  60. package/models/RsocKeywordPerformance.js +110 -110
  61. package/models/RuleAction.js +90 -90
  62. package/models/RuleCondition.js +137 -137
  63. package/models/RuleExecution.js +107 -107
  64. package/models/RulesValues.js +56 -56
  65. package/models/SupportedLocale.js +23 -23
  66. package/models/SyncHistory.js +249 -249
  67. package/models/TTQChannel.js +42 -42
  68. package/models/TemplateMetadata.js +260 -260
  69. package/models/Tier2_AdAccounts.js +110 -110
  70. package/models/Tier2_Assets.js +70 -70
  71. package/models/Tier2_BusinessManagers.js +105 -105
  72. package/models/Tier2_CreditLines.js +99 -99
  73. package/models/Tier2_Pages.js +91 -91
  74. package/models/Tier2_Pixels.js +82 -82
  75. package/models/Tier2_Tokens.js +64 -64
  76. package/models/Tier2_UserAdAccounts.js +83 -83
  77. package/models/TokenRotationState.js +121 -121
  78. package/models/TonicRSOCKeywordPerformance.js +122 -122
  79. package/models/Users.js +148 -148
  80. package/models/Vertical.js +25 -25
  81. package/models/newFiles.js +137 -137
  82. package/package.json +19 -21
  83. package/run.sh +214 -214
  84. package/services/sequelizeService.js +110 -110
@@ -1,111 +1,111 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const RsocKeywordPerformance = sequelize.define('RsocKeywordPerformance', {
3
- id: {
4
- type: DataTypes.INTEGER,
5
- primaryKey: true,
6
- autoIncrement: true,
7
- allowNull: false
8
- },
9
- ts: {
10
- type: DataTypes.DATE,
11
- allowNull: false,
12
- comment: 'Timestamp of the record'
13
- },
14
- channel_id: {
15
- type: DataTypes.STRING,
16
- allowNull: false,
17
- comment: 'Channel identifier'
18
- },
19
- style_id: {
20
- type: DataTypes.STRING,
21
- allowNull: true,
22
- comment: 'Style identifier'
23
- },
24
- country_code: {
25
- type: DataTypes.STRING(2),
26
- allowNull: true,
27
- comment: 'Country code (ISO 2-letter)'
28
- },
29
- custom_query: {
30
- type: DataTypes.TEXT,
31
- allowNull: true,
32
- comment: 'Custom search query'
33
- },
34
- query: {
35
- type: DataTypes.TEXT,
36
- allowNull: true,
37
- comment: 'Standard search query'
38
- },
39
- funnel_page_views: {
40
- type: DataTypes.INTEGER,
41
- allowNull: true,
42
- defaultValue: 0,
43
- comment: 'Number of funnel page views'
44
- },
45
- funnel_impressions: {
46
- type: DataTypes.INTEGER,
47
- allowNull: true,
48
- defaultValue: 0,
49
- comment: 'Number of funnel impressions'
50
- },
51
- funnel_clicks: {
52
- type: DataTypes.INTEGER,
53
- allowNull: true,
54
- defaultValue: 0,
55
- comment: 'Number of funnel clicks'
56
- },
57
- page_views: {
58
- type: DataTypes.INTEGER,
59
- allowNull: true,
60
- defaultValue: 0,
61
- comment: 'Number of page views'
62
- },
63
- impressions: {
64
- type: DataTypes.INTEGER,
65
- allowNull: true,
66
- defaultValue: 0,
67
- comment: 'Number of impressions'
68
- },
69
- clicks: {
70
- type: DataTypes.INTEGER,
71
- allowNull: true,
72
- defaultValue: 0,
73
- comment: 'Number of clicks'
74
- },
75
- agrs_cid: {
76
- type: DataTypes.STRING,
77
- allowNull: true,
78
- comment: 'AGRS campaign identifier linking to campaign data'
79
- }
80
- }, {
81
- tableName: 'rsoc_keyword_performance',
82
- timestamps: true, // Adds createdAt and updatedAt columns
83
- indexes: [
84
- {
85
- fields: ['channel_id', 'ts'],
86
- name: 'idx_rsoc_keyword_channel_time'
87
- },
88
- {
89
- fields: ['style_id'],
90
- name: 'idx_rsoc_keyword_style'
91
- },
92
- {
93
- fields: ['country_code'],
94
- name: 'idx_rsoc_keyword_country'
95
- },
96
- {
97
- fields: ['agrs_cid'],
98
- name: 'idx_rsoc_keyword_agrs_cid'
99
- }
100
- ]
101
- });
102
-
103
- // Define associations if needed
104
- RsocKeywordPerformance.associate = (models) => {
105
- // Add associations here if your table needs to reference other tables
106
- // For example:
107
- // RsocKeywordPerformance.belongsTo(models.Channel, { foreignKey: 'channel_id' });
108
- };
109
-
110
- return RsocKeywordPerformance;
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const RsocKeywordPerformance = sequelize.define('RsocKeywordPerformance', {
3
+ id: {
4
+ type: DataTypes.INTEGER,
5
+ primaryKey: true,
6
+ autoIncrement: true,
7
+ allowNull: false
8
+ },
9
+ ts: {
10
+ type: DataTypes.DATE,
11
+ allowNull: false,
12
+ comment: 'Timestamp of the record'
13
+ },
14
+ channel_id: {
15
+ type: DataTypes.STRING,
16
+ allowNull: false,
17
+ comment: 'Channel identifier'
18
+ },
19
+ style_id: {
20
+ type: DataTypes.STRING,
21
+ allowNull: true,
22
+ comment: 'Style identifier'
23
+ },
24
+ country_code: {
25
+ type: DataTypes.STRING(2),
26
+ allowNull: true,
27
+ comment: 'Country code (ISO 2-letter)'
28
+ },
29
+ custom_query: {
30
+ type: DataTypes.TEXT,
31
+ allowNull: true,
32
+ comment: 'Custom search query'
33
+ },
34
+ query: {
35
+ type: DataTypes.TEXT,
36
+ allowNull: true,
37
+ comment: 'Standard search query'
38
+ },
39
+ funnel_page_views: {
40
+ type: DataTypes.INTEGER,
41
+ allowNull: true,
42
+ defaultValue: 0,
43
+ comment: 'Number of funnel page views'
44
+ },
45
+ funnel_impressions: {
46
+ type: DataTypes.INTEGER,
47
+ allowNull: true,
48
+ defaultValue: 0,
49
+ comment: 'Number of funnel impressions'
50
+ },
51
+ funnel_clicks: {
52
+ type: DataTypes.INTEGER,
53
+ allowNull: true,
54
+ defaultValue: 0,
55
+ comment: 'Number of funnel clicks'
56
+ },
57
+ page_views: {
58
+ type: DataTypes.INTEGER,
59
+ allowNull: true,
60
+ defaultValue: 0,
61
+ comment: 'Number of page views'
62
+ },
63
+ impressions: {
64
+ type: DataTypes.INTEGER,
65
+ allowNull: true,
66
+ defaultValue: 0,
67
+ comment: 'Number of impressions'
68
+ },
69
+ clicks: {
70
+ type: DataTypes.INTEGER,
71
+ allowNull: true,
72
+ defaultValue: 0,
73
+ comment: 'Number of clicks'
74
+ },
75
+ agrs_cid: {
76
+ type: DataTypes.STRING,
77
+ allowNull: true,
78
+ comment: 'AGRS campaign identifier linking to campaign data'
79
+ }
80
+ }, {
81
+ tableName: 'rsoc_keyword_performance',
82
+ timestamps: true, // Adds createdAt and updatedAt columns
83
+ indexes: [
84
+ {
85
+ fields: ['channel_id', 'ts'],
86
+ name: 'idx_rsoc_keyword_channel_time'
87
+ },
88
+ {
89
+ fields: ['style_id'],
90
+ name: 'idx_rsoc_keyword_style'
91
+ },
92
+ {
93
+ fields: ['country_code'],
94
+ name: 'idx_rsoc_keyword_country'
95
+ },
96
+ {
97
+ fields: ['agrs_cid'],
98
+ name: 'idx_rsoc_keyword_agrs_cid'
99
+ }
100
+ ]
101
+ });
102
+
103
+ // Define associations if needed
104
+ RsocKeywordPerformance.associate = (models) => {
105
+ // Add associations here if your table needs to reference other tables
106
+ // For example:
107
+ // RsocKeywordPerformance.belongsTo(models.Channel, { foreignKey: 'channel_id' });
108
+ };
109
+
110
+ return RsocKeywordPerformance;
111
111
  };
@@ -1,90 +1,90 @@
1
- const { DataTypes } = require("sequelize");
2
-
3
- module.exports = (sequelize) => {
4
- const RuleAction = sequelize.define(
5
- "RuleAction",
6
- {
7
- id: {
8
- type: DataTypes.UUID,
9
- defaultValue: DataTypes.UUIDV4,
10
- primaryKey: true,
11
- },
12
- ruleId: {
13
- type: DataTypes.UUID,
14
- allowNull: false,
15
- references: {
16
- model: "AutomationRule",
17
- key: "id",
18
- },
19
- comment: "Reference to the parent rule",
20
- },
21
- actionType: {
22
- type: DataTypes.ENUM(
23
- "PAUSE",
24
- "ACTIVATE",
25
- "CHANGE_BUDGET",
26
- "CHANGE_BID",
27
- "CHANGE_BID_STRATEGY",
28
- "CUSTOM_ACTION"
29
- ),
30
- allowNull: false,
31
- comment: "Type of action to perform",
32
- },
33
- targetLevel: {
34
- type: DataTypes.ENUM("CAMPAIGN", "ADSET", "AD"),
35
- allowNull: false,
36
- comment: "Level at which the action operates",
37
- },
38
- value: {
39
- type: DataTypes.STRING(255),
40
- allowNull: true,
41
- comment: "Value for the action (budget amount, bid amount, etc.)",
42
- },
43
- valueType: {
44
- type: DataTypes.ENUM("STRING", "NUMBER", "ARRAY"),
45
- allowNull: true,
46
- defaultValue: "STRING",
47
- comment: "Type of the value field",
48
- },
49
- actionConfig: {
50
- type: DataTypes.JSONB,
51
- allowNull: true,
52
- comment:
53
- "Configuration for the action (budget amount, bid strategy, etc.)",
54
- },
55
- order: {
56
- type: DataTypes.INTEGER,
57
- allowNull: false,
58
- defaultValue: 0,
59
- comment: "Order of this action within the rule",
60
- },
61
- isActive: {
62
- type: DataTypes.BOOLEAN,
63
- defaultValue: true,
64
- allowNull: false,
65
- comment: "Whether this action is active",
66
- },
67
- delayMinutes: {
68
- type: DataTypes.INTEGER,
69
- allowNull: true,
70
- defaultValue: 0,
71
- comment: "Delay in minutes before executing this action",
72
- },
73
- },
74
- {
75
- tableName: "RuleActions",
76
- timestamps: true,
77
- // Remove indexes from model definition - they will be created by migration
78
- }
79
- );
80
-
81
- RuleAction.associate = (models) => {
82
- // An action belongs to a rule
83
- RuleAction.belongsTo(models.AutomationRule, {
84
- foreignKey: "ruleId",
85
- as: "rule",
86
- });
87
- };
88
-
89
- return RuleAction;
90
- };
1
+ const { DataTypes } = require("sequelize");
2
+
3
+ module.exports = (sequelize) => {
4
+ const RuleAction = sequelize.define(
5
+ "RuleAction",
6
+ {
7
+ id: {
8
+ type: DataTypes.UUID,
9
+ defaultValue: DataTypes.UUIDV4,
10
+ primaryKey: true,
11
+ },
12
+ ruleId: {
13
+ type: DataTypes.UUID,
14
+ allowNull: false,
15
+ references: {
16
+ model: "AutomationRule",
17
+ key: "id",
18
+ },
19
+ comment: "Reference to the parent rule",
20
+ },
21
+ actionType: {
22
+ type: DataTypes.ENUM(
23
+ "PAUSE",
24
+ "ACTIVATE",
25
+ "CHANGE_BUDGET",
26
+ "CHANGE_BID",
27
+ "CHANGE_BID_STRATEGY",
28
+ "CUSTOM_ACTION"
29
+ ),
30
+ allowNull: false,
31
+ comment: "Type of action to perform",
32
+ },
33
+ targetLevel: {
34
+ type: DataTypes.ENUM("CAMPAIGN", "ADSET", "AD"),
35
+ allowNull: false,
36
+ comment: "Level at which the action operates",
37
+ },
38
+ value: {
39
+ type: DataTypes.STRING(255),
40
+ allowNull: true,
41
+ comment: "Value for the action (budget amount, bid amount, etc.)",
42
+ },
43
+ valueType: {
44
+ type: DataTypes.ENUM("STRING", "NUMBER", "ARRAY"),
45
+ allowNull: true,
46
+ defaultValue: "STRING",
47
+ comment: "Type of the value field",
48
+ },
49
+ actionConfig: {
50
+ type: DataTypes.JSONB,
51
+ allowNull: true,
52
+ comment:
53
+ "Configuration for the action (budget amount, bid strategy, etc.)",
54
+ },
55
+ order: {
56
+ type: DataTypes.INTEGER,
57
+ allowNull: false,
58
+ defaultValue: 0,
59
+ comment: "Order of this action within the rule",
60
+ },
61
+ isActive: {
62
+ type: DataTypes.BOOLEAN,
63
+ defaultValue: true,
64
+ allowNull: false,
65
+ comment: "Whether this action is active",
66
+ },
67
+ delayMinutes: {
68
+ type: DataTypes.INTEGER,
69
+ allowNull: true,
70
+ defaultValue: 0,
71
+ comment: "Delay in minutes before executing this action",
72
+ },
73
+ },
74
+ {
75
+ tableName: "RuleActions",
76
+ timestamps: true,
77
+ // Remove indexes from model definition - they will be created by migration
78
+ }
79
+ );
80
+
81
+ RuleAction.associate = (models) => {
82
+ // An action belongs to a rule
83
+ RuleAction.belongsTo(models.AutomationRule, {
84
+ foreignKey: "ruleId",
85
+ as: "rule",
86
+ });
87
+ };
88
+
89
+ return RuleAction;
90
+ };
@@ -1,137 +1,137 @@
1
- const { DataTypes } = require("sequelize");
2
-
3
- module.exports = (sequelize) => {
4
- const RuleCondition = sequelize.define(
5
- "RuleCondition",
6
- {
7
- id: {
8
- type: DataTypes.UUID,
9
- defaultValue: DataTypes.UUIDV4,
10
- primaryKey: true,
11
- },
12
- ruleId: {
13
- type: DataTypes.UUID,
14
- allowNull: false,
15
- references: {
16
- model: "AutomationRule",
17
- key: "id",
18
- },
19
- comment: "Reference to the parent rule",
20
- },
21
- field: {
22
- type: DataTypes.STRING(100),
23
- allowNull: false,
24
- comment: "Field to evaluate (e.g., roi, ctr, campaign_name)",
25
- },
26
- type: {
27
- type: DataTypes.ENUM("DIMENSION", "METRIC"),
28
- allowNull: false,
29
- defaultValue: "DIMENSION",
30
- comment:
31
- "Type of field - DIMENSION for filtering, METRIC for calculations",
32
- },
33
- operator: {
34
- type: DataTypes.ENUM(
35
- "EQUALS",
36
- "NOT_EQUALS",
37
- "GREATER_THAN",
38
- "LESS_THAN",
39
- "GREATER_THAN_OR_EQUAL",
40
- "LESS_THAN_OR_EQUAL",
41
- "BETWEEN",
42
- "IN",
43
- "NOT_IN",
44
- "CONTAINS",
45
- "NOT_CONTAINS",
46
- "IS_NULL",
47
- "IS_NOT_NULL"
48
- ),
49
- allowNull: false,
50
- comment: "Comparison operator",
51
- },
52
- value: {
53
- type: DataTypes.JSONB,
54
- allowNull: true,
55
- comment:
56
- "Value(s) to compare against (can be array for BETWEEN, IN, etc.)",
57
- },
58
- valueType: {
59
- type: DataTypes.ENUM("STRING", "NUMBER", "ARRAY"),
60
- allowNull: true,
61
- defaultValue: "STRING",
62
- comment: "Type of the value field",
63
- },
64
- logicalOperator: {
65
- type: DataTypes.ENUM("AND", "OR"),
66
- allowNull: false,
67
- defaultValue: "AND",
68
- comment: "How this condition connects to the next one",
69
- },
70
- order: {
71
- type: DataTypes.INTEGER,
72
- allowNull: false,
73
- defaultValue: 0,
74
- comment: "Order of this condition within the rule",
75
- },
76
- isActive: {
77
- type: DataTypes.BOOLEAN,
78
- defaultValue: true,
79
- allowNull: false,
80
- comment: "Whether this condition is active",
81
- },
82
- groupId: {
83
- type: DataTypes.STRING(50),
84
- allowNull: true,
85
- comment: "ID to group conditions together (e.g., group1, group2)",
86
- },
87
- groupOperator: {
88
- type: DataTypes.ENUM("AND", "OR"),
89
- allowNull: false,
90
- defaultValue: "AND",
91
- comment: "Operator within the group (AND/OR)",
92
- },
93
- betweenGroupsOperator: {
94
- type: DataTypes.ENUM("AND", "OR"),
95
- allowNull: true,
96
- comment:
97
- "Operator between different groups (AND/OR) - only for first condition in group",
98
- },
99
- dateRangeType: {
100
- type: DataTypes.STRING(50),
101
- allowNull: true,
102
- comment:
103
- "Type of date range (last_7_days, yesterday, today, custom, etc.)",
104
- },
105
- dateRangeValue: {
106
- type: DataTypes.INTEGER,
107
- allowNull: true,
108
- comment: "Number of days for relative date ranges",
109
- },
110
- customStartDate: {
111
- type: DataTypes.DATE,
112
- allowNull: true,
113
- comment: "Custom start date if dateRangeType is custom",
114
- },
115
- customEndDate: {
116
- type: DataTypes.DATE,
117
- allowNull: true,
118
- comment: "Custom end date if dateRangeType is custom",
119
- },
120
- },
121
- {
122
- tableName: "RuleConditions",
123
- timestamps: true,
124
- // Remove indexes from model definition - they will be created by migration
125
- }
126
- );
127
-
128
- RuleCondition.associate = (models) => {
129
- // A condition belongs to a rule
130
- RuleCondition.belongsTo(models.AutomationRule, {
131
- foreignKey: "ruleId",
132
- as: "rule",
133
- });
134
- };
135
-
136
- return RuleCondition;
137
- };
1
+ const { DataTypes } = require("sequelize");
2
+
3
+ module.exports = (sequelize) => {
4
+ const RuleCondition = sequelize.define(
5
+ "RuleCondition",
6
+ {
7
+ id: {
8
+ type: DataTypes.UUID,
9
+ defaultValue: DataTypes.UUIDV4,
10
+ primaryKey: true,
11
+ },
12
+ ruleId: {
13
+ type: DataTypes.UUID,
14
+ allowNull: false,
15
+ references: {
16
+ model: "AutomationRule",
17
+ key: "id",
18
+ },
19
+ comment: "Reference to the parent rule",
20
+ },
21
+ field: {
22
+ type: DataTypes.STRING(100),
23
+ allowNull: false,
24
+ comment: "Field to evaluate (e.g., roi, ctr, campaign_name)",
25
+ },
26
+ type: {
27
+ type: DataTypes.ENUM("DIMENSION", "METRIC"),
28
+ allowNull: false,
29
+ defaultValue: "DIMENSION",
30
+ comment:
31
+ "Type of field - DIMENSION for filtering, METRIC for calculations",
32
+ },
33
+ operator: {
34
+ type: DataTypes.ENUM(
35
+ "EQUALS",
36
+ "NOT_EQUALS",
37
+ "GREATER_THAN",
38
+ "LESS_THAN",
39
+ "GREATER_THAN_OR_EQUAL",
40
+ "LESS_THAN_OR_EQUAL",
41
+ "BETWEEN",
42
+ "IN",
43
+ "NOT_IN",
44
+ "CONTAINS",
45
+ "NOT_CONTAINS",
46
+ "IS_NULL",
47
+ "IS_NOT_NULL"
48
+ ),
49
+ allowNull: false,
50
+ comment: "Comparison operator",
51
+ },
52
+ value: {
53
+ type: DataTypes.JSONB,
54
+ allowNull: true,
55
+ comment:
56
+ "Value(s) to compare against (can be array for BETWEEN, IN, etc.)",
57
+ },
58
+ valueType: {
59
+ type: DataTypes.ENUM("STRING", "NUMBER", "ARRAY"),
60
+ allowNull: true,
61
+ defaultValue: "STRING",
62
+ comment: "Type of the value field",
63
+ },
64
+ logicalOperator: {
65
+ type: DataTypes.ENUM("AND", "OR"),
66
+ allowNull: false,
67
+ defaultValue: "AND",
68
+ comment: "How this condition connects to the next one",
69
+ },
70
+ order: {
71
+ type: DataTypes.INTEGER,
72
+ allowNull: false,
73
+ defaultValue: 0,
74
+ comment: "Order of this condition within the rule",
75
+ },
76
+ isActive: {
77
+ type: DataTypes.BOOLEAN,
78
+ defaultValue: true,
79
+ allowNull: false,
80
+ comment: "Whether this condition is active",
81
+ },
82
+ groupId: {
83
+ type: DataTypes.STRING(50),
84
+ allowNull: true,
85
+ comment: "ID to group conditions together (e.g., group1, group2)",
86
+ },
87
+ groupOperator: {
88
+ type: DataTypes.ENUM("AND", "OR"),
89
+ allowNull: false,
90
+ defaultValue: "AND",
91
+ comment: "Operator within the group (AND/OR)",
92
+ },
93
+ betweenGroupsOperator: {
94
+ type: DataTypes.ENUM("AND", "OR"),
95
+ allowNull: true,
96
+ comment:
97
+ "Operator between different groups (AND/OR) - only for first condition in group",
98
+ },
99
+ dateRangeType: {
100
+ type: DataTypes.STRING(50),
101
+ allowNull: true,
102
+ comment:
103
+ "Type of date range (last_7_days, yesterday, today, custom, etc.)",
104
+ },
105
+ dateRangeValue: {
106
+ type: DataTypes.INTEGER,
107
+ allowNull: true,
108
+ comment: "Number of days for relative date ranges",
109
+ },
110
+ customStartDate: {
111
+ type: DataTypes.DATE,
112
+ allowNull: true,
113
+ comment: "Custom start date if dateRangeType is custom",
114
+ },
115
+ customEndDate: {
116
+ type: DataTypes.DATE,
117
+ allowNull: true,
118
+ comment: "Custom end date if dateRangeType is custom",
119
+ },
120
+ },
121
+ {
122
+ tableName: "RuleConditions",
123
+ timestamps: true,
124
+ // Remove indexes from model definition - they will be created by migration
125
+ }
126
+ );
127
+
128
+ RuleCondition.associate = (models) => {
129
+ // A condition belongs to a rule
130
+ RuleCondition.belongsTo(models.AutomationRule, {
131
+ foreignKey: "ruleId",
132
+ as: "rule",
133
+ });
134
+ };
135
+
136
+ return RuleCondition;
137
+ };