agrs-sequelize-sdk 1.0.48 → 1.0.50

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 CHANGED
@@ -21,10 +21,10 @@ module.exports = (sequelize, DataTypes) => {
21
21
  creativeId: {
22
22
  type: DataTypes.STRING,
23
23
  allowNull: true,
24
- references: {
25
- model: "AdCreatives", // Assuming you have an AdCreative model
26
- key: "id",
27
- },
24
+ // references: {
25
+ // model: "AdCreatives", // Assuming you have an AdCreative model
26
+ // key: "id",
27
+ // },
28
28
  },
29
29
  pixelId: {
30
30
  type: DataTypes.STRING,
@@ -76,7 +76,7 @@ module.exports = (sequelize, DataTypes) => {
76
76
  type: DataTypes.STRING,
77
77
  allowNull: true,
78
78
  },
79
- publish:{
79
+ publish: {
80
80
  type: DataTypes.BOOLEAN,
81
81
  allowNull: true,
82
82
  defaultValue: true,
@@ -152,27 +152,27 @@ module.exports = (sequelize, DataTypes) => {
152
152
 
153
153
  return null;
154
154
  };
155
- Ad.addHook('beforeUpdate', async (ad, options) => {
156
- if (ad.changed('publish')) {
157
- if (ad.previous('publish') === true && ad.publish === false) {
155
+ Ad.addHook("beforeUpdate", async (ad, options) => {
156
+ if (ad.changed("publish")) {
157
+ if (ad.previous("publish") === true && ad.publish === false) {
158
158
  // Save current state to AdHistory
159
159
  await sequelize.models.AdHistory.create({
160
160
  AdID: ad.AdID,
161
161
  DataSnapshot: ad._previousDataValues, // Save the full Ad data as JSON
162
162
  });
163
- } else if (ad.previous('publish') === false && ad.publish === true) {
163
+ } else if (ad.previous("publish") === false && ad.publish === true) {
164
164
  // Delete the latest history entry
165
165
  const latestHistory = await sequelize.models.AdHistory.findOne({
166
166
  where: { AdID: ad.AdID },
167
- order: [['timestamp', 'DESC']], // Get the latest history entry
167
+ order: [["timestamp", "DESC"]], // Get the latest history entry
168
168
  });
169
-
169
+
170
170
  if (latestHistory) {
171
171
  await latestHistory.destroy();
172
172
  }
173
173
  }
174
174
  }
175
175
  });
176
-
176
+
177
177
  return Ad;
178
178
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agrs-sequelize-sdk",
3
- "version": "1.0.48",
3
+ "version": "1.0.50",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "start": "node index.js",
@@ -1,65 +0,0 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const AdCreative = sequelize.define("AdCreative", {
3
- id: {
4
- type: DataTypes.STRING,
5
- primaryKey: true,
6
- },
7
- name: DataTypes.STRING,
8
- adAccountId: {
9
- type: DataTypes.STRING,
10
- allowNull: false,
11
- },
12
- pageId: {
13
- type: DataTypes.STRING,
14
- allowNull: false,
15
- },
16
- imageHashes: {
17
- type: DataTypes.ARRAY(DataTypes.STRING), // Array of image hash IDs (Foreign key to Files table)
18
- allowNull: true,
19
- },
20
- videoIds: {
21
- type: DataTypes.ARRAY(DataTypes.STRING), // Array of video file IDs (Foreign key to Files table)
22
- allowNull: true,
23
- },
24
- messages: {
25
- type: DataTypes.ARRAY(DataTypes.STRING), // Array of messages (primary text)
26
- allowNull: true,
27
- },
28
- headlines: {
29
- type: DataTypes.ARRAY(DataTypes.STRING), // Array of headlines
30
- allowNull: true,
31
- },
32
- descriptions: {
33
- type: DataTypes.ARRAY(DataTypes.STRING), // Array of descriptions
34
- allowNull: true,
35
- },
36
- websiteUrl: {
37
- type: DataTypes.STRING(1000), // Increase limit for longer URLs
38
- allowNull: false,
39
- },
40
- format: {
41
- type: DataTypes.STRING,
42
- allowNull: false,
43
- defaultValue: "FLEXIBLE",
44
- },
45
- Draft: {
46
- type: DataTypes.BOOLEAN,
47
- allowNull: true,
48
- },
49
- UserCreated: {
50
- type: DataTypes.STRING,
51
- allowNull: true,
52
- },
53
- });
54
-
55
- // Define associations
56
- AdCreative.associate = function (models) {
57
- // Associate AdCreative with Ad (one-to-many)
58
- AdCreative.hasMany(models.Ad, { foreignKey: "creativeId" });
59
-
60
- // Associate AdCreative with Files (one-to-many)
61
- AdCreative.hasMany(models.Files, { foreignKey: "id", sourceKey: "id" });
62
- };
63
-
64
- return AdCreative;
65
- };