agrs-sequelize-sdk 1.1.87 → 1.1.90

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.
package/models/Ad.js CHANGED
@@ -21,10 +21,6 @@ module.exports = (sequelize, DataTypes) => {
21
21
  creativeId: {
22
22
  type: DataTypes.STRING,
23
23
  allowNull: true,
24
- // references: {
25
- // model: "AdCreatives", // Assuming you have an AdCreative model
26
- // key: "id",
27
- // },
28
24
  },
29
25
  pixelId: {
30
26
  type: DataTypes.STRING,
@@ -44,27 +40,27 @@ module.exports = (sequelize, DataTypes) => {
44
40
  defaultValue: "SINGLE",
45
41
  },
46
42
  imageHashes: {
47
- type: DataTypes.ARRAY(DataTypes.STRING), // Array of image hashes
43
+ type: DataTypes.ARRAY(DataTypes.STRING),
48
44
  allowNull: true,
49
45
  },
50
46
  videoIds: {
51
- type: DataTypes.ARRAY(DataTypes.STRING), // Array of video IDs
47
+ type: DataTypes.ARRAY(DataTypes.STRING),
52
48
  allowNull: true,
53
49
  },
54
50
  messages: {
55
- type: DataTypes.ARRAY(DataTypes.TEXT), // Array of primary text messages
51
+ type: DataTypes.ARRAY(DataTypes.TEXT),
56
52
  allowNull: true,
57
53
  },
58
54
  headlines: {
59
- type: DataTypes.ARRAY(DataTypes.TEXT), // Array of headlines
55
+ type: DataTypes.ARRAY(DataTypes.TEXT),
60
56
  allowNull: true,
61
57
  },
62
58
  websiteUrl: {
63
- type: DataTypes.TEXT, // Increase limit for longer URLs
59
+ type: DataTypes.TEXT,
64
60
  allowNull: true,
65
61
  },
66
62
  pageId: {
67
- type: DataTypes.STRING(256), // Increase limit for longer URLs
63
+ type: DataTypes.STRING(256),
68
64
  allowNull: true,
69
65
  },
70
66
  actionTypes: {
@@ -98,17 +94,14 @@ module.exports = (sequelize, DataTypes) => {
98
94
  type: DataTypes.STRING,
99
95
  allowNull: true,
100
96
  },
101
- // add effective_status field
102
97
  effectiveStatus: {
103
98
  type: DataTypes.STRING,
104
99
  allowNull: true,
105
100
  },
106
- // add issues_info field
107
101
  issuesInfo: {
108
102
  type: DataTypes.JSONB,
109
103
  allowNull: true,
110
104
  },
111
- // add ad_review_feedback
112
105
  adReviewFeedback: {
113
106
  type: DataTypes.JSONB,
114
107
  allowNull: true,
@@ -122,44 +115,27 @@ module.exports = (sequelize, DataTypes) => {
122
115
  tableName: "Ad",
123
116
  indexes: [
124
117
  {
125
- fields: ["AdSetID"], // Index on AdSetID for faster join
118
+ fields: ["AdSetID"],
126
119
  },
127
120
  ],
128
121
  }
129
122
  );
130
123
 
131
- // Ad.associate = (models) => {
132
- // Ad.belongsTo(models.AdSet, { foreignKey: "AdSetID" });
133
-
134
- // // Association with CodefuelCampaign using AGRS_CID
135
- // Ad.belongsTo(models.CodefuelCampaign, {
136
- // foreignKey: "AGRS_CID",
137
- // targetKey: "AGRSCID",
138
- // as: "CodefuelCampaign",
139
- // constraints: false, // Disable FK constraint at the DB level
140
- // });
141
-
142
- // Ad.hasMany(models.AdPerformance, {
143
- // foreignKey: "AdID",
144
- // });
145
- // };
146
-
147
124
  Ad.associate = (models) => {
148
125
  Ad.belongsTo(models.AdSet, { foreignKey: "AdSetID" });
149
126
 
150
- // Add dynamic relations to either CodefuelCampaign or RSOCFeedCampaign
151
127
  Ad.belongsTo(models.CodefuelCampaign, {
152
128
  foreignKey: "AGRS_CID",
153
129
  targetKey: "AGRSCID",
154
130
  as: "CodefuelCampaign",
155
- constraints: false, // Disable FK constraint
131
+ constraints: false,
156
132
  });
157
133
 
158
134
  Ad.belongsTo(models.RSOCFeedCampaign, {
159
135
  foreignKey: "AGRS_CID",
160
136
  targetKey: "AGRS_CID",
161
137
  as: "RSOCFeedCampaign",
162
- constraints: false, // Disable FK constraint
138
+ constraints: false,
163
139
  });
164
140
 
165
141
  Ad.hasMany(models.AdPerformance, {
@@ -167,46 +143,6 @@ module.exports = (sequelize, DataTypes) => {
167
143
  });
168
144
  };
169
145
 
170
- // // Method to dynamically fetch related campaign
171
- // Ad.prototype.getRelatedCampaign = async function () {
172
- // if (!this.AGRS_CID) return null;
173
-
174
- // const codefuelCampaign = await sequelize.models.CodefuelCampaign.findOne({
175
- // where: { AGRSCID: this.AGRS_CID },
176
- // });
177
-
178
- // if (codefuelCampaign) {
179
- // return {
180
- // type: "CodefuelCampaign",
181
- // data: codefuelCampaign,
182
- // };
183
- // }
184
-
185
- // const tonicCampaign = await sequelize.models.TonicCampaign.findOne({
186
- // where: { AGRSCID: this.AGRS_CID },
187
- // });
188
-
189
- // if (tonicCampaign) {
190
- // return {
191
- // type: "TonicCampaign",
192
- // data: tonicCampaign,
193
- // };
194
- // }
195
-
196
- // // do the same with RSOCFeedCampaign
197
- // const rsocFeedCampaign = await sequelize.models.RSOCFeedCampaign.findOne({
198
- // where: { AGRS_CID: this.AGRS_CID },
199
- // });
200
-
201
- // if (rsocFeedCampaign) {
202
- // return {
203
- // type: "RSOCFeedCampaign",
204
- // data: rsocFeedCampaign,
205
- // };
206
- // }
207
- // return null;
208
- // };
209
-
210
146
  Ad.prototype.getRelatedCampaign = async function () {
211
147
  if (!this.AGRS_CID) return null;
212
148
 
@@ -1,26 +1,26 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const AdAccountValues = sequelize.define(
3
- "AdAccountValues",
4
- {
5
- id: {
6
- type: DataTypes.UUID,
7
- defaultValue: DataTypes.UUIDV4,
8
- primaryKey: true,
9
- },
10
- name: {
11
- type: DataTypes.STRING,
12
- allowNull: false,
13
- },
14
- code: {
15
- type: DataTypes.STRING,
16
- allowNull: false,
17
- unique: true,
18
- },
19
- },
20
- {
21
- tableName: "AdAccountValues",
22
- }
23
- );
24
-
25
- return AdAccountValues;
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const AdAccountValues = sequelize.define(
3
+ "AdAccountValues",
4
+ {
5
+ id: {
6
+ type: DataTypes.UUID,
7
+ defaultValue: DataTypes.UUIDV4,
8
+ primaryKey: true,
9
+ },
10
+ name: {
11
+ type: DataTypes.STRING,
12
+ allowNull: false,
13
+ },
14
+ code: {
15
+ type: DataTypes.STRING,
16
+ allowNull: false,
17
+ unique: true,
18
+ },
19
+ },
20
+ {
21
+ tableName: "AdAccountValues",
22
+ }
23
+ );
24
+
25
+ return AdAccountValues;
26
26
  };
@@ -1,30 +1,30 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const AdHistory = sequelize.define(
3
- "AdHistory",
4
- {
5
- HistoryID: {
6
- type: DataTypes.UUID,
7
- defaultValue: DataTypes.UUIDV4,
8
- primaryKey: true,
9
- },
10
- AdID: {
11
- type: DataTypes.STRING,
12
- allowNull: false,
13
- },
14
- DataSnapshot: {
15
- type: DataTypes.JSONB, // Store the full Ad row as a JSON object
16
- allowNull: false,
17
- },
18
- timestamp: {
19
- type: DataTypes.DATE,
20
- defaultValue: DataTypes.NOW,
21
- },
22
- },
23
- {
24
- tableName: "AdHistory",
25
- timestamps: false, // Disable Sequelize timestamps
26
- }
27
- );
28
-
29
- return AdHistory;
30
- };
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const AdHistory = sequelize.define(
3
+ "AdHistory",
4
+ {
5
+ HistoryID: {
6
+ type: DataTypes.UUID,
7
+ defaultValue: DataTypes.UUIDV4,
8
+ primaryKey: true,
9
+ },
10
+ AdID: {
11
+ type: DataTypes.STRING,
12
+ allowNull: false,
13
+ },
14
+ DataSnapshot: {
15
+ type: DataTypes.JSONB, // Store the full Ad row as a JSON object
16
+ allowNull: false,
17
+ },
18
+ timestamp: {
19
+ type: DataTypes.DATE,
20
+ defaultValue: DataTypes.NOW,
21
+ },
22
+ },
23
+ {
24
+ tableName: "AdHistory",
25
+ timestamps: false, // Disable Sequelize timestamps
26
+ }
27
+ );
28
+
29
+ return AdHistory;
30
+ };
package/models/AdSet.js CHANGED
@@ -1,147 +1,3 @@
1
- // module.exports = (sequelize, DataTypes) => {
2
- // const AdSet = sequelize.define(
3
- // "AdSet",
4
- // {
5
- // AdSetID: {
6
- // type: DataTypes.STRING,
7
- // primaryKey: true,
8
- // },
9
- // AdSetName: {
10
- // type: DataTypes.STRING,
11
- // allowNull: true,
12
- // },
13
- // Status: {
14
- // type: DataTypes.STRING,
15
- // allowNull: true,
16
- // },
17
- // daily_budget: {
18
- // type: DataTypes.INTEGER,
19
- // allowNull: true,
20
- // },
21
- // start_time: {
22
- // type: DataTypes.DATE,
23
- // allowNull: true,
24
- // },
25
- // end_time: {
26
- // type: DataTypes.DATE,
27
- // allowNull: true,
28
- // },
29
- // targeting: {
30
- // type: DataTypes.JSONB,
31
- // allowNull: true,
32
- // },
33
- // promotedObject: {
34
- // type: DataTypes.JSONB, // Storing promoted object as a JSON object
35
- // allowNull: true,
36
- // },
37
- // BillingEvent: {
38
- // type: DataTypes.STRING,
39
- // allowNull: false,
40
- // defaultValue: "impressions", // Default value for BillingEvent
41
- // },
42
- // OptimizationGoal: {
43
- // type: DataTypes.STRING,
44
- // allowNull: false,
45
- // defaultValue: "offsite_conversions", // Default value for OptimizationGoal
46
- // },
47
- // Draft: {
48
- // type: DataTypes.BOOLEAN,
49
- // allowNull: true,
50
- // defaultValue: false,
51
- // },
52
- // UserCreated: {
53
- // type: DataTypes.STRING,
54
- // allowNull: true,
55
- // },
56
- // publish: {
57
- // type: DataTypes.BOOLEAN,
58
- // allowNull: true,
59
- // defaultValue: true,
60
- // },
61
- // CampaignID: {
62
- // type: DataTypes.STRING,
63
- // allowNull: false,
64
- // references: {
65
- // model: "Campaign",
66
- // key: "CampaignID",
67
- // },
68
- // },
69
- // effectiveStatus: {
70
- // type: DataTypes.STRING,
71
- // allowNull: true,
72
- // },
73
- // // add issues_info field
74
- // issuesInfo: {
75
- // type: DataTypes.JSONB,
76
- // allowNull: true,
77
- // },
78
- // bid_strategy: {
79
- // type: DataTypes.STRING,
80
- // allowNull: true,
81
- // },
82
- // // bid amount
83
- // bid_amount: {
84
- // type: DataTypes.INTEGER,
85
- // allowNull: true,
86
- // },
87
- // waiting: {
88
- // type: DataTypes.BOOLEAN,
89
- // defaultValue: false,
90
- // },
91
- // },
92
- // {
93
- // tableName: "AdSet",
94
- // indexes: [
95
- // {
96
- // fields: ["CampaignID"], // Index on CampaignID for faster join
97
- // },
98
- // ],
99
- // }
100
- // );
101
-
102
- // AdSet.associate = (models) => {
103
- // AdSet.belongsTo(models.Campaign, { foreignKey: "CampaignID" });
104
- // AdSet.hasMany(models.Ad, { foreignKey: "AdSetID" });
105
- // };
106
-
107
- // AdSet.addHook("beforeUpdate", async (adSet, options) => {
108
- // if (adSet.changed("publish")) {
109
- // if (adSet.previous("publish") === true && adSet.publish === false) {
110
- // // Save current state to AdSetHistory
111
- // await sequelize.models.AdSetHistory.create({
112
- // AdSetID: adSet.AdSetID,
113
- // DataSnapshot: adSet._previousDataValues, // Save the full AdSet data as JSON
114
- // });
115
- // } else if (
116
- // adSet.previous("publish") === false &&
117
- // adSet.publish === true
118
- // ) {
119
- // // Delete the latest history entry
120
- // const latestHistory = await sequelize.models.AdSetHistory.findOne({
121
- // where: { AdSetID: adSet.AdSetID },
122
- // order: [["timestamp", "DESC"]], // Get the latest history entry
123
- // });
124
-
125
- // if (latestHistory) {
126
- // await latestHistory.destroy();
127
- // }
128
- // }
129
- // }
130
- // });
131
-
132
- // AdSet.addHook("afterCreate", async (adSet, options) => {
133
- // if (adSet.publish === false) {
134
- // // If publish is false on creation, save a snapshot to AdSetHistory
135
- // await sequelize.models.AdSetHistory.create({
136
- // AdSetID: adSet.AdSetID,
137
- // DataSnapshot: adSet.toJSON(), // Save the full AdSet data as JSON
138
- // });
139
- // }
140
- // });
141
-
142
- // return AdSet;
143
- // };
144
-
145
1
  module.exports = (sequelize, DataTypes) => {
146
2
  const AdSet = sequelize.define(
147
3
  "AdSet",
@@ -1,30 +1,30 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const AdSetHistory = sequelize.define(
3
- "AdSetHistory",
4
- {
5
- HistoryID: {
6
- type: DataTypes.UUID,
7
- defaultValue: DataTypes.UUIDV4,
8
- primaryKey: true,
9
- },
10
- AdSetID: {
11
- type: DataTypes.STRING,
12
- allowNull: false,
13
- },
14
- DataSnapshot: {
15
- type: DataTypes.JSONB, // Store the full AdSet row as a JSON object
16
- allowNull: false,
17
- },
18
- timestamp: {
19
- type: DataTypes.DATE,
20
- defaultValue: DataTypes.NOW,
21
- },
22
- },
23
- {
24
- tableName: "AdSetHistory",
25
- timestamps: false,
26
- }
27
- );
28
-
29
- return AdSetHistory;
30
- };
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const AdSetHistory = sequelize.define(
3
+ "AdSetHistory",
4
+ {
5
+ HistoryID: {
6
+ type: DataTypes.UUID,
7
+ defaultValue: DataTypes.UUIDV4,
8
+ primaryKey: true,
9
+ },
10
+ AdSetID: {
11
+ type: DataTypes.STRING,
12
+ allowNull: false,
13
+ },
14
+ DataSnapshot: {
15
+ type: DataTypes.JSONB, // Store the full AdSet row as a JSON object
16
+ allowNull: false,
17
+ },
18
+ timestamp: {
19
+ type: DataTypes.DATE,
20
+ defaultValue: DataTypes.NOW,
21
+ },
22
+ },
23
+ {
24
+ tableName: "AdSetHistory",
25
+ timestamps: false,
26
+ }
27
+ );
28
+
29
+ return AdSetHistory;
30
+ };