agrs-sequelize-sdk 1.0.93 → 1.0.94
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/AdSet.js +2 -12
- package/models/Campaign.js +2 -14
- package/package.json +1 -1
package/models/AdSet.js
CHANGED
|
@@ -103,24 +103,14 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
103
103
|
AdSet.addHook("beforeUpdate", async (adSet, options) => {
|
|
104
104
|
if (adSet.changed("AdSetID")) {
|
|
105
105
|
const oldAdSetID = adSet.previous("AdSetID");
|
|
106
|
-
const newAdSetID = adSet.AdSetID;
|
|
107
|
-
|
|
108
|
-
const transaction = options.transaction || await sequelize.transaction(); // Use or create transaction
|
|
109
|
-
|
|
106
|
+
const newAdSetID = adSet.AdSetID;
|
|
110
107
|
try {
|
|
111
108
|
// Update associated Ads to the new AdSetID
|
|
112
109
|
await sequelize.models.Ad.update(
|
|
113
110
|
{ AdSetID: newAdSetID }, // Set new AdSetID
|
|
114
|
-
{ where: { AdSetID: oldAdSetID }
|
|
111
|
+
{ where: { AdSetID: oldAdSetID } }
|
|
115
112
|
);
|
|
116
|
-
|
|
117
|
-
if (!options.transaction) {
|
|
118
|
-
await transaction.commit();
|
|
119
|
-
}
|
|
120
113
|
} catch (error) {
|
|
121
|
-
if (!options.transaction) {
|
|
122
|
-
await transaction.rollback();
|
|
123
|
-
}
|
|
124
114
|
throw error; // Propagate the error
|
|
125
115
|
}
|
|
126
116
|
}
|
package/models/Campaign.js
CHANGED
|
@@ -96,26 +96,14 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
96
96
|
if (campaign.changed("CampaignID")) {
|
|
97
97
|
const oldCampaignID = campaign.previous("CampaignID");
|
|
98
98
|
const newCampaignID = campaign.CampaignID;
|
|
99
|
-
|
|
100
|
-
// Use existing transaction or create a new one
|
|
101
|
-
const transaction = options.transaction || await sequelize.transaction();
|
|
102
|
-
|
|
99
|
+
|
|
103
100
|
try {
|
|
104
101
|
// Update all associated AdSets to the new CampaignID
|
|
105
102
|
await sequelize.models.AdSet.update(
|
|
106
103
|
{ CampaignID: newCampaignID }, // Set new CampaignID
|
|
107
|
-
{ where: { CampaignID: oldCampaignID }
|
|
104
|
+
{ where: { CampaignID: oldCampaignID } }
|
|
108
105
|
);
|
|
109
|
-
|
|
110
|
-
// Commit transaction if this is a new transaction
|
|
111
|
-
if (!options.transaction) {
|
|
112
|
-
await transaction.commit();
|
|
113
|
-
}
|
|
114
106
|
} catch (error) {
|
|
115
|
-
// Rollback on failure
|
|
116
|
-
if (!options.transaction) {
|
|
117
|
-
await transaction.rollback();
|
|
118
|
-
}
|
|
119
107
|
throw error; // Propagate the error
|
|
120
108
|
}
|
|
121
109
|
}
|