agrs-sequelize-sdk 1.2.13 → 1.2.14

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/Article.js CHANGED
@@ -1,156 +1,156 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const Article = sequelize.define(
3
- "Article",
4
- {
5
- providerId: {
6
- type: DataTypes.STRING,
7
- allowNull: true,
8
- unique: true,
9
- },
10
- category: {
11
- type: DataTypes.STRING,
12
- allowNull: true,
13
- },
14
- AGRSAID: {
15
- type: DataTypes.STRING,
16
- allowNull: false,
17
- unique: true,
18
- },
19
- articleUrl: {
20
- type: DataTypes.STRING(1024),
21
- allowNull: true,
22
- },
23
- feed: {
24
- type: DataTypes.STRING,
25
- allowNull: false,
26
- },
27
- feedName: {
28
- type: DataTypes.STRING,
29
- allowNull: false,
30
- },
31
- vertical: {
32
- type: DataTypes.STRING,
33
- allowNull: false,
34
- },
35
- language: {
36
- type: DataTypes.STRING,
37
- allowNull: false,
38
- defaultValue: "en",
39
- },
40
- headline: {
41
- type: DataTypes.STRING,
42
- allowNull: true,
43
- },
44
- topics: {
45
- type: DataTypes.ARRAY(DataTypes.STRING),
46
- allowNull: true,
47
- },
48
- mainKeyword: {
49
- type: DataTypes.STRING,
50
- allowNull: true,
51
- },
52
- keywords: {
53
- type: DataTypes.ARRAY(DataTypes.STRING),
54
- allowNull: true,
55
- },
56
- date: {
57
- type: DataTypes.DATE,
58
- allowNull: true,
59
- defaultValue: DataTypes.NOW,
60
- },
61
- nativeKeyword: {
62
- type: DataTypes.STRING,
63
- allowNull: false,
64
- },
65
- suggestedKeywords: {
66
- type: DataTypes.STRING,
67
- allowNull: true,
68
- },
69
- articleExcerpt: {
70
- type: DataTypes.TEXT,
71
- allowNull: true,
72
- },
73
- articleContent: {
74
- type: DataTypes.TEXT,
75
- allowNull: true,
76
- },
77
- fbPixelId: {
78
- type: DataTypes.STRING,
79
- allowNull: true,
80
- },
81
- status: {
82
- type: DataTypes.STRING,
83
- allowNull: false,
84
- defaultValue: "pending",
85
- validate: {
86
- isIn: [
87
- [
88
- "pending",
89
- "approved",
90
- "rejected",
91
- "disapproved",
92
- "duplicated",
93
- "keyword_already_exists",
94
- "invalid_vertical",
95
- "invalid_language",
96
- "in_review",
97
- "error",
98
- ],
99
- ],
100
- },
101
- },
102
- originalStatus: {
103
- type: DataTypes.STRING,
104
- allowNull: true,
105
- comment: "Original status from Predicto before any mapping",
106
- },
107
- creationType: {
108
- type: DataTypes.STRING,
109
- allowNull: false,
110
- defaultValue: "slug",
111
- validate: {
112
- isIn: [["search", "slug"]],
113
- },
114
- },
115
- createdAt: {
116
- type: DataTypes.DATE,
117
- defaultValue: DataTypes.NOW,
118
- },
119
- updatedAt: {
120
- type: DataTypes.DATE,
121
- defaultValue: DataTypes.NOW,
122
- },
123
- buyer: {
124
- type: DataTypes.STRING,
125
- allowNull: true,
126
- },
127
- country: {
128
- type: DataTypes.STRING,
129
- allowNull: true,
130
- },
131
- name: {
132
- type: DataTypes.STRING,
133
- allowNull: true,
134
- },
135
- },
136
- {
137
- tableName: "articles",
138
- timestamps: true,
139
- }
140
- );
141
-
142
- Article.associate = (models) => {
143
- Article.hasMany(models.RSOCFeedCampaign, {
144
- foreignKey: "AGRSAID",
145
- sourceKey: "AGRSAID",
146
- as: "RSOCFeedCampaigns",
147
- constraints: false,
148
- });
149
- };
150
-
151
- Article.prototype.isAvailableForCampaign = function () {
152
- return ["approved", "keyword_already_exists"].includes(this.status);
153
- };
154
-
155
- return Article;
156
- };
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const Article = sequelize.define(
3
+ "Article",
4
+ {
5
+ providerId: {
6
+ type: DataTypes.STRING,
7
+ allowNull: true,
8
+ unique: true,
9
+ },
10
+ category: {
11
+ type: DataTypes.STRING,
12
+ allowNull: true,
13
+ },
14
+ AGRSAID: {
15
+ type: DataTypes.STRING,
16
+ allowNull: false,
17
+ unique: true,
18
+ },
19
+ articleUrl: {
20
+ type: DataTypes.STRING(1024),
21
+ allowNull: true,
22
+ },
23
+ feed: {
24
+ type: DataTypes.STRING,
25
+ allowNull: false,
26
+ },
27
+ feedName: {
28
+ type: DataTypes.STRING,
29
+ allowNull: false,
30
+ },
31
+ vertical: {
32
+ type: DataTypes.STRING,
33
+ allowNull: false,
34
+ },
35
+ language: {
36
+ type: DataTypes.STRING,
37
+ allowNull: false,
38
+ defaultValue: "en",
39
+ },
40
+ headline: {
41
+ type: DataTypes.STRING,
42
+ allowNull: true,
43
+ },
44
+ topics: {
45
+ type: DataTypes.ARRAY(DataTypes.STRING),
46
+ allowNull: true,
47
+ },
48
+ mainKeyword: {
49
+ type: DataTypes.STRING,
50
+ allowNull: true,
51
+ },
52
+ keywords: {
53
+ type: DataTypes.ARRAY(DataTypes.STRING),
54
+ allowNull: true,
55
+ },
56
+ date: {
57
+ type: DataTypes.DATE,
58
+ allowNull: true,
59
+ defaultValue: DataTypes.NOW,
60
+ },
61
+ nativeKeyword: {
62
+ type: DataTypes.STRING,
63
+ allowNull: false,
64
+ },
65
+ suggestedKeywords: {
66
+ type: DataTypes.STRING,
67
+ allowNull: true,
68
+ },
69
+ articleExcerpt: {
70
+ type: DataTypes.TEXT,
71
+ allowNull: true,
72
+ },
73
+ articleContent: {
74
+ type: DataTypes.TEXT,
75
+ allowNull: true,
76
+ },
77
+ fbPixelId: {
78
+ type: DataTypes.STRING,
79
+ allowNull: true,
80
+ },
81
+ status: {
82
+ type: DataTypes.STRING,
83
+ allowNull: false,
84
+ defaultValue: "pending",
85
+ validate: {
86
+ isIn: [
87
+ [
88
+ "pending",
89
+ "approved",
90
+ "rejected",
91
+ "disapproved",
92
+ "duplicated",
93
+ "keyword_already_exists",
94
+ "invalid_vertical",
95
+ "invalid_language",
96
+ "in_review",
97
+ "error",
98
+ ],
99
+ ],
100
+ },
101
+ },
102
+ originalStatus: {
103
+ type: DataTypes.STRING,
104
+ allowNull: true,
105
+ comment: "Original status from Predicto before any mapping",
106
+ },
107
+ creationType: {
108
+ type: DataTypes.STRING,
109
+ allowNull: false,
110
+ defaultValue: "slug",
111
+ validate: {
112
+ isIn: [["search", "slug"]],
113
+ },
114
+ },
115
+ createdAt: {
116
+ type: DataTypes.DATE,
117
+ defaultValue: DataTypes.NOW,
118
+ },
119
+ updatedAt: {
120
+ type: DataTypes.DATE,
121
+ defaultValue: DataTypes.NOW,
122
+ },
123
+ buyer: {
124
+ type: DataTypes.STRING,
125
+ allowNull: true,
126
+ },
127
+ country: {
128
+ type: DataTypes.STRING,
129
+ allowNull: true,
130
+ },
131
+ name: {
132
+ type: DataTypes.STRING,
133
+ allowNull: true,
134
+ },
135
+ },
136
+ {
137
+ tableName: "articles",
138
+ timestamps: true,
139
+ }
140
+ );
141
+
142
+ Article.associate = (models) => {
143
+ Article.hasMany(models.RSOCFeedCampaign, {
144
+ foreignKey: "AGRSAID",
145
+ sourceKey: "AGRSAID",
146
+ as: "RSOCFeedCampaigns",
147
+ constraints: false,
148
+ });
149
+ };
150
+
151
+ Article.prototype.isAvailableForCampaign = function () {
152
+ return ["approved", "keyword_already_exists"].includes(this.status);
153
+ };
154
+
155
+ return Article;
156
+ };
package/models/Buyers.js CHANGED
@@ -1,26 +1,26 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const Buyers = sequelize.define(
3
- "Buyers",
4
- {
5
- id: {
6
- type: DataTypes.UUID,
7
- defaultValue: DataTypes.UUIDV4,
8
- primaryKey: true,
9
- },
10
- name: {
11
- type: DataTypes.STRING,
12
- allowNull: false,
13
- },
14
- code: {
15
- type: DataTypes.STRING,
16
- allowNull: false,
17
- unique: true,
18
- },
19
- },
20
- {
21
- tableName: "Buyers",
22
- }
23
- );
24
-
25
- return Buyers;
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const Buyers = sequelize.define(
3
+ "Buyers",
4
+ {
5
+ id: {
6
+ type: DataTypes.UUID,
7
+ defaultValue: DataTypes.UUIDV4,
8
+ primaryKey: true,
9
+ },
10
+ name: {
11
+ type: DataTypes.STRING,
12
+ allowNull: false,
13
+ },
14
+ code: {
15
+ type: DataTypes.STRING,
16
+ allowNull: false,
17
+ unique: true,
18
+ },
19
+ },
20
+ {
21
+ tableName: "Buyers",
22
+ }
23
+ );
24
+
25
+ return Buyers;
26
26
  };
@@ -1,135 +1,135 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const Campaign = sequelize.define(
3
- "Campaign",
4
- {
5
- CampaignID: {
6
- type: DataTypes.STRING,
7
- primaryKey: true,
8
- },
9
- CampaignName: {
10
- type: DataTypes.STRING,
11
- allowNull: true,
12
- },
13
- pixelId: {
14
- type: DataTypes.STRING,
15
- allowNull: true,
16
- },
17
- customEventType: {
18
- type: DataTypes.STRING,
19
- allowNull: false,
20
- defaultValue: "PURCHASE",
21
- },
22
- objective: {
23
- type: DataTypes.STRING,
24
- allowNull: false,
25
- defaultValue: "OUTCOME_SALES",
26
- },
27
- status: {
28
- type: DataTypes.STRING,
29
- allowNull: true,
30
- },
31
- AdAccountID: {
32
- type: DataTypes.STRING,
33
- allowNull: false,
34
- references: {
35
- model: "AdAccount",
36
- key: "AdAccountID",
37
- },
38
- },
39
- CreatedTime: {
40
- type: DataTypes.DATE,
41
- allowNull: false,
42
- },
43
- CampaignDelivery: {
44
- type: DataTypes.STRING,
45
- allowNull: true,
46
- },
47
- DailyBudget: {
48
- type: DataTypes.INTEGER,
49
- allowNull: true,
50
- },
51
- Draft: {
52
- type: DataTypes.BOOLEAN,
53
- allowNull: true,
54
- defaultValue: false,
55
- },
56
- publish: {
57
- type: DataTypes.BOOLEAN,
58
- allowNull: true,
59
- defaultValue: true,
60
- },
61
- UserCreated: {
62
- type: DataTypes.STRING,
63
- allowNull: true,
64
- },
65
- special_ad_categories: {
66
- type: DataTypes.ARRAY(DataTypes.STRING),
67
- allowNull: true,
68
- },
69
- effectiveStatus: {
70
- type: DataTypes.STRING,
71
- allowNull: true,
72
- },
73
- issuesInfo: {
74
- type: DataTypes.JSONB,
75
- allowNull: true,
76
- },
77
- waiting: {
78
- type: DataTypes.BOOLEAN,
79
- defaultValue: false,
80
- },
81
- },
82
- {
83
- tableName: "Campaign",
84
- indexes: [
85
- {
86
- fields: ["AdAccountID"], // Index on AdAccountID for faster joins
87
- },
88
- ],
89
- }
90
- );
91
-
92
- // Define associations
93
- Campaign.associate = (models) => {
94
- Campaign.belongsTo(models.AdAccount, { foreignKey: "AdAccountID" });
95
- Campaign.hasMany(models.AdSet, { foreignKey: "CampaignID" });
96
- };
97
-
98
- // Combined beforeUpdate hook
99
- Campaign.addHook("beforeUpdate", async (campaign, options) => {
100
- if (campaign.changed("publish")) {
101
- if (campaign.previous("publish") === true && campaign.publish === false) {
102
- // Save current state to CampaignHistory
103
- await sequelize.models.CampaignHistory.create({
104
- CampaignID: campaign.CampaignID,
105
- DataSnapshot: campaign._previousDataValues, // Store current state as JSON
106
- });
107
- } else if (
108
- campaign.previous("publish") === false &&
109
- campaign.publish === true
110
- ) {
111
- // Delete the latest history entry
112
- const latestHistory = await sequelize.models.CampaignHistory.findOne({
113
- where: { CampaignID: campaign.CampaignID },
114
- order: [["timestamp", "DESC"]], // Get the latest history entry
115
- });
116
-
117
- if (latestHistory) {
118
- await latestHistory.destroy(); // Delete the latest history entry
119
- }
120
- }
121
- }
122
- });
123
-
124
- Campaign.addHook("afterCreate", async (campaign, options) => {
125
- if (campaign.publish === false) {
126
- // If publish is false on creation, save a snapshot to CampaignHistory
127
- await sequelize.models.CampaignHistory.create({
128
- CampaignID: campaign.CampaignID,
129
- DataSnapshot: campaign.toJSON(), // Save current state
130
- });
131
- }
132
- });
133
-
134
- return Campaign;
135
- };
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const Campaign = sequelize.define(
3
+ "Campaign",
4
+ {
5
+ CampaignID: {
6
+ type: DataTypes.STRING,
7
+ primaryKey: true,
8
+ },
9
+ CampaignName: {
10
+ type: DataTypes.STRING,
11
+ allowNull: true,
12
+ },
13
+ pixelId: {
14
+ type: DataTypes.STRING,
15
+ allowNull: true,
16
+ },
17
+ customEventType: {
18
+ type: DataTypes.STRING,
19
+ allowNull: false,
20
+ defaultValue: "PURCHASE",
21
+ },
22
+ objective: {
23
+ type: DataTypes.STRING,
24
+ allowNull: false,
25
+ defaultValue: "OUTCOME_SALES",
26
+ },
27
+ status: {
28
+ type: DataTypes.STRING,
29
+ allowNull: true,
30
+ },
31
+ AdAccountID: {
32
+ type: DataTypes.STRING,
33
+ allowNull: false,
34
+ references: {
35
+ model: "AdAccount",
36
+ key: "AdAccountID",
37
+ },
38
+ },
39
+ CreatedTime: {
40
+ type: DataTypes.DATE,
41
+ allowNull: false,
42
+ },
43
+ CampaignDelivery: {
44
+ type: DataTypes.STRING,
45
+ allowNull: true,
46
+ },
47
+ DailyBudget: {
48
+ type: DataTypes.INTEGER,
49
+ allowNull: true,
50
+ },
51
+ Draft: {
52
+ type: DataTypes.BOOLEAN,
53
+ allowNull: true,
54
+ defaultValue: false,
55
+ },
56
+ publish: {
57
+ type: DataTypes.BOOLEAN,
58
+ allowNull: true,
59
+ defaultValue: true,
60
+ },
61
+ UserCreated: {
62
+ type: DataTypes.STRING,
63
+ allowNull: true,
64
+ },
65
+ special_ad_categories: {
66
+ type: DataTypes.ARRAY(DataTypes.STRING),
67
+ allowNull: true,
68
+ },
69
+ effectiveStatus: {
70
+ type: DataTypes.STRING,
71
+ allowNull: true,
72
+ },
73
+ issuesInfo: {
74
+ type: DataTypes.JSONB,
75
+ allowNull: true,
76
+ },
77
+ waiting: {
78
+ type: DataTypes.BOOLEAN,
79
+ defaultValue: false,
80
+ },
81
+ },
82
+ {
83
+ tableName: "Campaign",
84
+ indexes: [
85
+ {
86
+ fields: ["AdAccountID"], // Index on AdAccountID for faster joins
87
+ },
88
+ ],
89
+ }
90
+ );
91
+
92
+ // Define associations
93
+ Campaign.associate = (models) => {
94
+ Campaign.belongsTo(models.AdAccount, { foreignKey: "AdAccountID" });
95
+ Campaign.hasMany(models.AdSet, { foreignKey: "CampaignID" });
96
+ };
97
+
98
+ // Combined beforeUpdate hook
99
+ Campaign.addHook("beforeUpdate", async (campaign, options) => {
100
+ if (campaign.changed("publish")) {
101
+ if (campaign.previous("publish") === true && campaign.publish === false) {
102
+ // Save current state to CampaignHistory
103
+ await sequelize.models.CampaignHistory.create({
104
+ CampaignID: campaign.CampaignID,
105
+ DataSnapshot: campaign._previousDataValues, // Store current state as JSON
106
+ });
107
+ } else if (
108
+ campaign.previous("publish") === false &&
109
+ campaign.publish === true
110
+ ) {
111
+ // Delete the latest history entry
112
+ const latestHistory = await sequelize.models.CampaignHistory.findOne({
113
+ where: { CampaignID: campaign.CampaignID },
114
+ order: [["timestamp", "DESC"]], // Get the latest history entry
115
+ });
116
+
117
+ if (latestHistory) {
118
+ await latestHistory.destroy(); // Delete the latest history entry
119
+ }
120
+ }
121
+ }
122
+ });
123
+
124
+ Campaign.addHook("afterCreate", async (campaign, options) => {
125
+ if (campaign.publish === false) {
126
+ // If publish is false on creation, save a snapshot to CampaignHistory
127
+ await sequelize.models.CampaignHistory.create({
128
+ CampaignID: campaign.CampaignID,
129
+ DataSnapshot: campaign.toJSON(), // Save current state
130
+ });
131
+ }
132
+ });
133
+
134
+ return Campaign;
135
+ };