agrs-sequelize-sdk 1.2.48 → 1.2.49

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.
@@ -0,0 +1,113 @@
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const TonicRSOCKeywordPerformance = sequelize.define(
3
+ "TonicRSOCKeywordPerformance",
4
+ {
5
+ Date: {
6
+ type: DataTypes.DATEONLY,
7
+ primaryKey: true,
8
+ },
9
+ adID: {
10
+ type: DataTypes.STRING,
11
+ references: {
12
+ model: "Ad",
13
+ key: "AdID",
14
+ },
15
+ foreignKey: true,
16
+ primaryKey: true,
17
+ },
18
+ Keyword: {
19
+ type: DataTypes.STRING,
20
+ allowNull: false,
21
+ primaryKey: true,
22
+ },
23
+ Country: {
24
+ type: DataTypes.STRING,
25
+ allowNull: false,
26
+ primaryKey: true, // ✅ Country is now part of primary key
27
+ },
28
+ Revenue: {
29
+ type: DataTypes.FLOAT,
30
+ allowNull: false,
31
+ },
32
+ Clicks: {
33
+ type: DataTypes.INTEGER,
34
+ allowNull: false,
35
+ },
36
+ TemplatedKeyword: {
37
+ type: DataTypes.STRING,
38
+ allowNull: true,
39
+ },
40
+ FirstAppearanceDate: {
41
+ type: DataTypes.DATEONLY,
42
+ allowNull: true,
43
+ },
44
+ },
45
+ {
46
+ tableName: "TonicRSOCKeywordPerformance",
47
+ indexes: [
48
+ {
49
+ unique: true,
50
+ fields: ["Date", "adID", "Keyword", "Country"],
51
+ },
52
+ {
53
+ fields: ["Date"],
54
+ },
55
+ {
56
+ fields: ["adID"],
57
+ },
58
+ {
59
+ fields: ["Keyword"],
60
+ },
61
+ {
62
+ fields: ["Country"],
63
+ },
64
+ {
65
+ fields: ["Revenue"],
66
+ },
67
+ {
68
+ fields: ["Clicks"],
69
+ },
70
+ {
71
+ fields: ["Country", "Date"],
72
+ },
73
+ {
74
+ fields: ["Keyword", "Country"],
75
+ },
76
+ {
77
+ fields: ["Date", "Revenue"],
78
+ },
79
+ ],
80
+ hooks: {
81
+ beforeCreate: async (record, options) => {
82
+ try {
83
+ const existingKeyword = await sequelize.models.TonicRSOCKeywordPerformance.findOne({
84
+ where: {
85
+ Keyword: sequelize.where(
86
+ sequelize.fn("LOWER", sequelize.col("Keyword")),
87
+ sequelize.fn("LOWER", record.Keyword)
88
+ ),
89
+ Country: record.Country,
90
+ },
91
+ attributes: ["FirstAppearanceDate"],
92
+ transaction: options.transaction,
93
+ });
94
+
95
+ record.FirstAppearanceDate =
96
+ existingKeyword?.FirstAppearanceDate || record.Date;
97
+ } catch (error) {
98
+ console.error("Error in TonicRSOCKeywordPerformance FirstAppearanceDate hook:", error);
99
+ throw error;
100
+ }
101
+ },
102
+ },
103
+ }
104
+ );
105
+
106
+ TonicRSOCKeywordPerformance.associate = (models) => {
107
+ TonicRSOCKeywordPerformance.belongsTo(models.Ad, {
108
+ foreignKey: "adID",
109
+ });
110
+ };
111
+
112
+ return TonicRSOCKeywordPerformance;
113
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agrs-sequelize-sdk",
3
- "version": "1.2.48",
3
+ "version": "1.2.49",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "start": "node index.js",