agrs-sequelize-sdk 1.1.23 → 1.1.24

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.
@@ -139,6 +139,7 @@ module.exports = (sequelize, DataTypes) => {
139
139
 
140
140
  CodefuelCampaign.beforeSave(async (campaign, options) => {
141
141
  // Catch-all logic to set RedirectLink if AGRSCID is set during save
142
+ console.log("beforeSave", campaign);
142
143
  const AGRSCID = campaign.getDataValue("AGRSCID");
143
144
  if (AGRSCID && !campaign.getDataValue("RedirectLink")) {
144
145
  const redirectLink = `https://ktwrjqdfv.com/${AGRSCID}?campaign_name={{campaign.name}}&adset_name={{adset.name}}&ad_name={{ad.name}}&campaign_id={{campaign.id}}&adset_id={{adset.id}}&ad_id={{ad.id}}_${AGRSCID}&placement={{placement}}&site_source_name={{site_source}}&fbclid={{fbclid}}`;
@@ -147,7 +148,32 @@ module.exports = (sequelize, DataTypes) => {
147
148
  });
148
149
 
149
150
  CodefuelCampaign.beforeUpdate(async (campaign, options) => {
150
- console.log("beforeUpdate", campaign);
151
+ console.log("I got to the beforeUpdate hook");
152
+ const { updateAdData, publishAdFacebook } = require("../Facebook/Ad");
153
+ console.log("CodefuelCampaign changed", campaign.changed("FinalLink"));
154
+
155
+ const { getAdsByAgrscid } = require("../Facebook/db/ad");
156
+ if (campaign.changed("FinalLink")) {
157
+ try {
158
+ const ads = await getAdsByAgrscid(campaign.AGRSCID);
159
+
160
+ await Promise.all(
161
+ ads.map(async (ad) => {
162
+ if (ad.Draft === "true" || ad.Draft === true) {
163
+ console.log("Updating ad data and publishing ad");
164
+ // Update ad data and publish ad
165
+ await updateAdData({
166
+ adId: ad.AdID,
167
+ websiteUrl: campaign.FinalLink, // Assuming `campaign.FinalLink` is correct
168
+ });
169
+ await publishAdFacebook(ad.AdID, null, null, campaign.FinalLink);
170
+ }
171
+ })
172
+ );
173
+ } catch (error) {
174
+ console.error("Error processing ads:", error);
175
+ }
176
+ }
151
177
  });
152
178
 
153
179
  CodefuelCampaign.afterUpdate(async (campaign, options) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agrs-sequelize-sdk",
3
- "version": "1.1.23",
3
+ "version": "1.1.24",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "start": "node index.js",