agrs-sequelize-sdk 1.0.64 → 1.0.65
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 +5 -0
- package/models/AdSet.js +15 -8
- package/models/Campaign.js +4 -0
- package/package.json +1 -1
package/models/Ad.js
CHANGED
package/models/AdSet.js
CHANGED
|
@@ -53,7 +53,7 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
53
53
|
type: DataTypes.STRING,
|
|
54
54
|
allowNull: true,
|
|
55
55
|
},
|
|
56
|
-
publish:{
|
|
56
|
+
publish: {
|
|
57
57
|
type: DataTypes.BOOLEAN,
|
|
58
58
|
allowNull: true,
|
|
59
59
|
defaultValue: true,
|
|
@@ -66,6 +66,10 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
66
66
|
key: "CampaignID",
|
|
67
67
|
},
|
|
68
68
|
},
|
|
69
|
+
effectiveStatus: {
|
|
70
|
+
type: DataTypes.STRING,
|
|
71
|
+
allowNull: true,
|
|
72
|
+
},
|
|
69
73
|
},
|
|
70
74
|
{
|
|
71
75
|
tableName: "AdSet",
|
|
@@ -82,27 +86,30 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
82
86
|
AdSet.hasMany(models.Ad, { foreignKey: "AdSetID" });
|
|
83
87
|
};
|
|
84
88
|
|
|
85
|
-
AdSet.addHook(
|
|
86
|
-
if (adSet.changed(
|
|
87
|
-
if (adSet.previous(
|
|
89
|
+
AdSet.addHook("beforeUpdate", async (adSet, options) => {
|
|
90
|
+
if (adSet.changed("publish")) {
|
|
91
|
+
if (adSet.previous("publish") === true && adSet.publish === false) {
|
|
88
92
|
// Save current state to AdSetHistory
|
|
89
93
|
await sequelize.models.AdSetHistory.create({
|
|
90
94
|
AdSetID: adSet.AdSetID,
|
|
91
95
|
DataSnapshot: adSet._previousDataValues, // Save the full AdSet data as JSON
|
|
92
96
|
});
|
|
93
|
-
} else if (
|
|
97
|
+
} else if (
|
|
98
|
+
adSet.previous("publish") === false &&
|
|
99
|
+
adSet.publish === true
|
|
100
|
+
) {
|
|
94
101
|
// Delete the latest history entry
|
|
95
102
|
const latestHistory = await sequelize.models.AdSetHistory.findOne({
|
|
96
103
|
where: { AdSetID: adSet.AdSetID },
|
|
97
|
-
order: [[
|
|
104
|
+
order: [["timestamp", "DESC"]], // Get the latest history entry
|
|
98
105
|
});
|
|
99
|
-
|
|
106
|
+
|
|
100
107
|
if (latestHistory) {
|
|
101
108
|
await latestHistory.destroy();
|
|
102
109
|
}
|
|
103
110
|
}
|
|
104
111
|
}
|
|
105
112
|
});
|
|
106
|
-
|
|
113
|
+
|
|
107
114
|
return AdSet;
|
|
108
115
|
};
|
package/models/Campaign.js
CHANGED