agrs-sequelize-sdk 1.1.64 → 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 +68 -15
  2. package/package.json +1 -1
package/models/Ad.js CHANGED
@@ -128,15 +128,38 @@ module.exports = (sequelize, DataTypes) => {
128
128
  }
129
129
  );
130
130
 
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
+
131
147
  Ad.associate = (models) => {
132
148
  Ad.belongsTo(models.AdSet, { foreignKey: "AdSetID" });
133
149
 
134
- // Association with CodefuelCampaign using AGRS_CID
150
+ // Add dynamic relations to either CodefuelCampaign or RSOCFeedCampaign
135
151
  Ad.belongsTo(models.CodefuelCampaign, {
136
152
  foreignKey: "AGRS_CID",
137
153
  targetKey: "AGRSCID",
138
154
  as: "CodefuelCampaign",
139
- constraints: false, // Disable FK constraint at the DB level
155
+ constraints: false, // Disable FK constraint
156
+ });
157
+
158
+ Ad.belongsTo(models.RSOCFeedCampaign, {
159
+ foreignKey: "AGRS_CID",
160
+ targetKey: "AGRS_CID",
161
+ as: "RSOCFeedCampaign",
162
+ constraints: false, // Disable FK constraint
140
163
  });
141
164
 
142
165
  Ad.hasMany(models.AdPerformance, {
@@ -144,10 +167,50 @@ module.exports = (sequelize, DataTypes) => {
144
167
  });
145
168
  };
146
169
 
147
- // 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
+
148
210
  Ad.prototype.getRelatedCampaign = async function () {
149
211
  if (!this.AGRS_CID) return null;
150
212
 
213
+ // Try fetching related CodefuelCampaign
151
214
  const codefuelCampaign = await sequelize.models.CodefuelCampaign.findOne({
152
215
  where: { AGRSCID: this.AGRS_CID },
153
216
  });
@@ -159,18 +222,7 @@ module.exports = (sequelize, DataTypes) => {
159
222
  };
160
223
  }
161
224
 
162
- const tonicCampaign = await sequelize.models.TonicCampaign.findOne({
163
- where: { AGRSCID: this.AGRS_CID },
164
- });
165
-
166
- if (tonicCampaign) {
167
- return {
168
- type: "TonicCampaign",
169
- data: tonicCampaign,
170
- };
171
- }
172
-
173
- // do the same with RSOCFeedCampaign
225
+ // Try fetching related RSOCFeedCampaign
174
226
  const rsocFeedCampaign = await sequelize.models.RSOCFeedCampaign.findOne({
175
227
  where: { AGRS_CID: this.AGRS_CID },
176
228
  });
@@ -181,6 +233,7 @@ module.exports = (sequelize, DataTypes) => {
181
233
  data: rsocFeedCampaign,
182
234
  };
183
235
  }
236
+
184
237
  return null;
185
238
  };
186
239
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agrs-sequelize-sdk",
3
- "version": "1.1.64",
3
+ "version": "1.1.66",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "start": "node index.js",