agrs-sequelize-sdk 1.1.65 → 1.1.66

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 (2) hide show
  1. package/models/Ad.js +46 -16
  2. package/package.json +1 -1
package/models/Ad.js CHANGED
@@ -147,19 +147,19 @@ module.exports = (sequelize, DataTypes) => {
147
147
  Ad.associate = (models) => {
148
148
  Ad.belongsTo(models.AdSet, { foreignKey: "AdSetID" });
149
149
 
150
- // Add a dynamic relationship that supports either CodefuelCampaign or RSOCFeedCampaign
150
+ // Add dynamic relations to either CodefuelCampaign or RSOCFeedCampaign
151
151
  Ad.belongsTo(models.CodefuelCampaign, {
152
152
  foreignKey: "AGRS_CID",
153
153
  targetKey: "AGRSCID",
154
154
  as: "CodefuelCampaign",
155
- constraints: false,
155
+ constraints: false, // Disable FK constraint
156
156
  });
157
157
 
158
158
  Ad.belongsTo(models.RSOCFeedCampaign, {
159
159
  foreignKey: "AGRS_CID",
160
160
  targetKey: "AGRS_CID",
161
161
  as: "RSOCFeedCampaign",
162
- constraints: false,
162
+ constraints: false, // Disable FK constraint
163
163
  });
164
164
 
165
165
  Ad.hasMany(models.AdPerformance, {
@@ -167,10 +167,50 @@ module.exports = (sequelize, DataTypes) => {
167
167
  });
168
168
  };
169
169
 
170
- // Method to dynamically fetch related campaign
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
+
171
210
  Ad.prototype.getRelatedCampaign = async function () {
172
211
  if (!this.AGRS_CID) return null;
173
212
 
213
+ // Try fetching related CodefuelCampaign
174
214
  const codefuelCampaign = await sequelize.models.CodefuelCampaign.findOne({
175
215
  where: { AGRSCID: this.AGRS_CID },
176
216
  });
@@ -182,18 +222,7 @@ module.exports = (sequelize, DataTypes) => {
182
222
  };
183
223
  }
184
224
 
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
225
+ // Try fetching related RSOCFeedCampaign
197
226
  const rsocFeedCampaign = await sequelize.models.RSOCFeedCampaign.findOne({
198
227
  where: { AGRS_CID: this.AGRS_CID },
199
228
  });
@@ -204,6 +233,7 @@ module.exports = (sequelize, DataTypes) => {
204
233
  data: rsocFeedCampaign,
205
234
  };
206
235
  }
236
+
207
237
  return null;
208
238
  };
209
239
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agrs-sequelize-sdk",
3
- "version": "1.1.65",
3
+ "version": "1.1.66",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "start": "node index.js",