agrs-sequelize-sdk 1.1.22 → 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.
- package/models/CodefuelCampaign.js +29 -7
- package/package.json +1 -1
|
@@ -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}}`;
|
|
@@ -146,19 +147,40 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
146
147
|
}
|
|
147
148
|
});
|
|
148
149
|
|
|
149
|
-
CodefuelCampaign.
|
|
150
|
-
console.log("
|
|
151
|
-
|
|
150
|
+
CodefuelCampaign.beforeUpdate(async (campaign, options) => {
|
|
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);
|
|
152
159
|
|
|
153
|
-
|
|
154
|
-
|
|
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
|
+
}
|
|
155
177
|
});
|
|
156
178
|
|
|
157
|
-
CodefuelCampaign.
|
|
179
|
+
CodefuelCampaign.afterUpdate(async (campaign, options) => {
|
|
158
180
|
console.log("afterUpdate", campaign);
|
|
159
181
|
});
|
|
160
182
|
|
|
161
|
-
CodefuelCampaign.
|
|
183
|
+
CodefuelCampaign.afterCreate(async (campaign, options) => {
|
|
162
184
|
console.log("afterCreate", campaign);
|
|
163
185
|
});
|
|
164
186
|
|