agrs-sequelize-sdk 1.0.86 → 1.0.88
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/Ad.js +8 -19
- package/models/AdSet.js +8 -22
- package/models/Campaign.js +8 -22
- package/package.json +1 -1
package/models/Ad.js
CHANGED
|
@@ -168,27 +168,16 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
168
168
|
return null;
|
|
169
169
|
};
|
|
170
170
|
|
|
171
|
-
Ad.addHook("
|
|
172
|
-
if (ad.
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
});
|
|
179
|
-
} else if (ad.previous("publish") === false && ad.publish === true) {
|
|
180
|
-
// Delete the latest history entry
|
|
181
|
-
const latestHistory = await sequelize.models.AdHistory.findOne({
|
|
182
|
-
where: { AdID: ad.AdID },
|
|
183
|
-
order: [["timestamp", "DESC"]], // Get the latest history entry
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
if (latestHistory) {
|
|
187
|
-
await latestHistory.destroy();
|
|
188
|
-
}
|
|
189
|
-
}
|
|
171
|
+
Ad.addHook("afterCreate", async (ad, options) => {
|
|
172
|
+
if (ad.publish === false) {
|
|
173
|
+
// If publish is false on creation, save a snapshot to AdHistory
|
|
174
|
+
await sequelize.models.AdHistory.create({
|
|
175
|
+
AdID: ad.AdID,
|
|
176
|
+
DataSnapshot: ad.toJSON(), // Save the full Ad data as JSON
|
|
177
|
+
});
|
|
190
178
|
}
|
|
191
179
|
});
|
|
180
|
+
|
|
192
181
|
Ad.addHook("beforeUpdate", async (ad, options) => {
|
|
193
182
|
if (ad.changed("publish")) {
|
|
194
183
|
if (ad.previous("publish") === true && ad.publish === false) {
|
package/models/AdSet.js
CHANGED
|
@@ -124,30 +124,16 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
});
|
|
127
|
-
|
|
128
|
-
AdSet.addHook("beforeCreate", async (adSet, options) => {
|
|
129
|
-
if (adSet.changed("publish")) {
|
|
130
|
-
if (adSet.previous("publish") === true && adSet.publish === false) {
|
|
131
|
-
// Save current state to AdSetHistory
|
|
132
|
-
await sequelize.models.AdSetHistory.create({
|
|
133
|
-
AdSetID: adSet.AdSetID,
|
|
134
|
-
DataSnapshot: adSet._previousDataValues, // Save the full AdSet data as JSON
|
|
135
|
-
});
|
|
136
|
-
} else if (
|
|
137
|
-
adSet.previous("publish") === false &&
|
|
138
|
-
adSet.publish === true
|
|
139
|
-
) {
|
|
140
|
-
// Delete the latest history entry
|
|
141
|
-
const latestHistory = await sequelize.models.AdSetHistory.findOne({
|
|
142
|
-
where: { AdSetID: adSet.AdSetID },
|
|
143
|
-
order: [["timestamp", "DESC"]], // Get the latest history entry
|
|
144
|
-
});
|
|
145
127
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
128
|
+
AdSet.addHook("afterCreate", async (adSet, options) => {
|
|
129
|
+
if (adSet.publish === false) {
|
|
130
|
+
// If publish is false on creation, save a snapshot to AdSetHistory
|
|
131
|
+
await sequelize.models.AdSetHistory.create({
|
|
132
|
+
AdSetID: adSet.AdSetID,
|
|
133
|
+
DataSnapshot: adSet.toJSON(), // Save the full AdSet data as JSON
|
|
134
|
+
});
|
|
150
135
|
}
|
|
151
136
|
});
|
|
137
|
+
|
|
152
138
|
return AdSet;
|
|
153
139
|
};
|
package/models/Campaign.js
CHANGED
|
@@ -117,30 +117,16 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
117
117
|
}
|
|
118
118
|
});
|
|
119
119
|
|
|
120
|
-
Campaign.addHook("
|
|
121
|
-
if (campaign.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
});
|
|
128
|
-
} else if (
|
|
129
|
-
campaign.previous("publish") === false &&
|
|
130
|
-
campaign.publish === true
|
|
131
|
-
) {
|
|
132
|
-
// Delete the latest history entry
|
|
133
|
-
const latestHistory = await sequelize.models.CampaignHistory.findOne({
|
|
134
|
-
where: { CampaignID: campaign.CampaignID },
|
|
135
|
-
order: [["timestamp", "DESC"]], // Get the latest history entry
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
if (latestHistory) {
|
|
139
|
-
await latestHistory.destroy(); // Delete the latest history entry
|
|
140
|
-
}
|
|
141
|
-
}
|
|
120
|
+
Campaign.addHook("afterCreate", async (campaign, options) => {
|
|
121
|
+
if (campaign.publish === false) {
|
|
122
|
+
// If publish is false on creation, save a snapshot to CampaignHistory
|
|
123
|
+
await sequelize.models.CampaignHistory.create({
|
|
124
|
+
CampaignID: campaign.CampaignID,
|
|
125
|
+
DataSnapshot: campaign.toJSON(), // Save current state
|
|
126
|
+
});
|
|
142
127
|
}
|
|
143
128
|
});
|
|
129
|
+
|
|
144
130
|
|
|
145
131
|
return Campaign;
|
|
146
132
|
};
|