agrs-sequelize-sdk 1.2.10 → 1.2.12
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/controllers/campaignCreationLogsController.js +264 -0
- package/models/CampaignCreationLogNew.js +141 -0
- package/models/RSOCFeedCampaign.js +1 -1
- package/package.json +1 -1
- package/routes/api.js +18 -0
- package/utils/loggerUtils.js +497 -0
- package/agrs-sequelize/LICENSE +0 -21
- package/agrs-sequelize/README.md +0 -179
- package/agrs-sequelize/index.js +0 -169
- package/agrs-sequelize/jq.exe +0 -0
- package/agrs-sequelize/models/ActivityHistory.js +0 -73
- package/agrs-sequelize/models/Ad.js +0 -209
- package/agrs-sequelize/models/AdAccount.js +0 -91
- package/agrs-sequelize/models/AdAccountValues.js +0 -26
- package/agrs-sequelize/models/AdHistory.js +0 -30
- package/agrs-sequelize/models/AdPerformance.js +0 -84
- package/agrs-sequelize/models/AdPerformanceHourly.js +0 -66
- package/agrs-sequelize/models/AdSet.js +0 -140
- package/agrs-sequelize/models/AdSetHistory.js +0 -30
- package/agrs-sequelize/models/AdsetPerformance.js +0 -116
- package/agrs-sequelize/models/Article.js +0 -156
- package/agrs-sequelize/models/Buyers.js +0 -26
- package/agrs-sequelize/models/Campaign.js +0 -136
- package/agrs-sequelize/models/CampaignCreationLog.js +0 -86
- package/agrs-sequelize/models/CampaignHistory.js +0 -33
- package/agrs-sequelize/models/Channel.js +0 -55
- package/agrs-sequelize/models/CodefuelCampaign.js +0 -159
- package/agrs-sequelize/models/CodefuelCampaignKWHistory.js +0 -41
- package/agrs-sequelize/models/CodefuelKeywords.js +0 -35
- package/agrs-sequelize/models/CurrencyRate.js +0 -27
- package/agrs-sequelize/models/Domain.js +0 -26
- package/agrs-sequelize/models/ExplorAdsChannel.js +0 -62
- package/agrs-sequelize/models/Feed.js +0 -34
- package/agrs-sequelize/models/Files.js +0 -73
- package/agrs-sequelize/models/Folders.js +0 -133
- package/agrs-sequelize/models/KeywordPerformance.js +0 -99
- package/agrs-sequelize/models/KeywordRotationState.js +0 -51
- package/agrs-sequelize/models/Pages.js +0 -74
- package/agrs-sequelize/models/PipelineExecution.js +0 -46
- package/agrs-sequelize/models/RSOCFeedCampaign.js +0 -307
- package/agrs-sequelize/models/RsocKeywordPerformance.js +0 -111
- package/agrs-sequelize/models/Rule.js +0 -39
- package/agrs-sequelize/models/RulesValues.js +0 -56
- package/agrs-sequelize/models/SupportedLocale.js +0 -24
- package/agrs-sequelize/models/TonicCampaign.js +0 -97
- package/agrs-sequelize/models/Users.js +0 -111
- package/agrs-sequelize/models/Vertical.js +0 -26
- package/agrs-sequelize/models/newFiles.js +0 -68
- package/agrs-sequelize/models/pixels.js +0 -33
- package/agrs-sequelize/package-lock.json +0 -405
- package/agrs-sequelize/package.json +0 -19
- package/agrs-sequelize/run.ps1 +0 -98
- package/agrs-sequelize/run.sh +0 -214
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
const { CampaignCreationLogNew } = require("../db");
|
|
2
|
+
const {
|
|
3
|
+
getProcessHierarchy,
|
|
4
|
+
getProcessStats,
|
|
5
|
+
} = require("../utils/loggerUtils");
|
|
6
|
+
const { Op } = require("sequelize");
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Get detailed logs for campaign creation processes
|
|
10
|
+
* @param {Object} req - Express request object
|
|
11
|
+
* @param {Object} res - Express response object
|
|
12
|
+
*/
|
|
13
|
+
async function getCampaignCreationLogs(req, res) {
|
|
14
|
+
try {
|
|
15
|
+
const {
|
|
16
|
+
process_id,
|
|
17
|
+
country,
|
|
18
|
+
status,
|
|
19
|
+
stage,
|
|
20
|
+
entity_name,
|
|
21
|
+
facebook_campaign_id,
|
|
22
|
+
facebook_adset_id,
|
|
23
|
+
facebook_ad_id,
|
|
24
|
+
from_date,
|
|
25
|
+
to_date,
|
|
26
|
+
page = 0,
|
|
27
|
+
limit = 20,
|
|
28
|
+
} = req.query;
|
|
29
|
+
|
|
30
|
+
// Build where clause
|
|
31
|
+
const whereClause = {};
|
|
32
|
+
if (process_id) whereClause.process_id = process_id;
|
|
33
|
+
if (country) whereClause.country = country;
|
|
34
|
+
if (status) whereClause.status = status;
|
|
35
|
+
if (stage) whereClause.stage = stage;
|
|
36
|
+
if (entity_name)
|
|
37
|
+
whereClause.entity_name = { [Op.iLike]: `%${entity_name}%` };
|
|
38
|
+
if (facebook_campaign_id)
|
|
39
|
+
whereClause.facebook_campaign_id = facebook_campaign_id;
|
|
40
|
+
if (facebook_adset_id) whereClause.facebook_adset_id = facebook_adset_id;
|
|
41
|
+
if (facebook_ad_id) whereClause.facebook_ad_id = facebook_ad_id;
|
|
42
|
+
|
|
43
|
+
// Date range filtering
|
|
44
|
+
if (from_date || to_date) {
|
|
45
|
+
whereClause.createdAt = {};
|
|
46
|
+
if (from_date) whereClause.createdAt[Op.gte] = new Date(from_date);
|
|
47
|
+
if (to_date) whereClause.createdAt[Op.lte] = new Date(to_date);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Pagination params
|
|
51
|
+
const pageInt = parseInt(page, 10);
|
|
52
|
+
const limitInt = parseInt(limit, 10);
|
|
53
|
+
|
|
54
|
+
// Execute query
|
|
55
|
+
const { count, rows } = await CampaignCreationLogNew.findAndCountAll({
|
|
56
|
+
where: whereClause,
|
|
57
|
+
limit: limitInt,
|
|
58
|
+
offset: pageInt * limitInt,
|
|
59
|
+
order: [["createdAt", "DESC"]],
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return res.json({
|
|
63
|
+
success: true,
|
|
64
|
+
logs: rows,
|
|
65
|
+
pagination: {
|
|
66
|
+
total: count,
|
|
67
|
+
page: pageInt,
|
|
68
|
+
limit: limitInt,
|
|
69
|
+
pages: Math.ceil(count / limitInt),
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error("Error in getCampaignCreationLogs:", error);
|
|
74
|
+
return res.status(500).json({
|
|
75
|
+
success: false,
|
|
76
|
+
error: error.message,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Get all processes with summary information
|
|
83
|
+
* @param {Object} req - Express request object
|
|
84
|
+
* @param {Object} res - Express response object
|
|
85
|
+
*/
|
|
86
|
+
async function getCampaignCreationProcesses(req, res) {
|
|
87
|
+
try {
|
|
88
|
+
const {
|
|
89
|
+
status,
|
|
90
|
+
country,
|
|
91
|
+
from_date,
|
|
92
|
+
to_date,
|
|
93
|
+
page = 0,
|
|
94
|
+
limit = 10,
|
|
95
|
+
} = req.query;
|
|
96
|
+
|
|
97
|
+
// Get distinct process IDs with filter conditions
|
|
98
|
+
const whereClause = {};
|
|
99
|
+
if (status) whereClause.status = status;
|
|
100
|
+
if (country) whereClause.country = country;
|
|
101
|
+
|
|
102
|
+
// Date range filtering
|
|
103
|
+
if (from_date || to_date) {
|
|
104
|
+
whereClause.createdAt = {};
|
|
105
|
+
if (from_date) whereClause.createdAt[Op.gte] = new Date(from_date);
|
|
106
|
+
if (to_date) whereClause.createdAt[Op.lte] = new Date(to_date);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Get distinct process IDs
|
|
110
|
+
const distinctProcessIds = await CampaignCreationLogNew.findAll({
|
|
111
|
+
attributes: [
|
|
112
|
+
"process_id",
|
|
113
|
+
[
|
|
114
|
+
CampaignCreationLogNew.sequelize.fn(
|
|
115
|
+
"MAX",
|
|
116
|
+
CampaignCreationLogNew.sequelize.col("createdAt")
|
|
117
|
+
),
|
|
118
|
+
"latest_timestamp",
|
|
119
|
+
],
|
|
120
|
+
],
|
|
121
|
+
where: whereClause,
|
|
122
|
+
group: ["process_id"],
|
|
123
|
+
order: [
|
|
124
|
+
[CampaignCreationLogNew.sequelize.literal("latest_timestamp"), "DESC"],
|
|
125
|
+
],
|
|
126
|
+
limit: parseInt(limit, 10),
|
|
127
|
+
offset: parseInt(page, 10) * parseInt(limit, 10),
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Get process IDs from result
|
|
131
|
+
const processIds = distinctProcessIds.map((item) => item.process_id);
|
|
132
|
+
|
|
133
|
+
// Get summary information for each process
|
|
134
|
+
const processes = [];
|
|
135
|
+
for (const processId of processIds) {
|
|
136
|
+
// Get the initial log for this process
|
|
137
|
+
const initialLog = await CampaignCreationLogNew.findOne({
|
|
138
|
+
where: {
|
|
139
|
+
process_id: processId,
|
|
140
|
+
stage: "PROCESS_STARTED",
|
|
141
|
+
},
|
|
142
|
+
order: [["createdAt", "ASC"]],
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
if (initialLog) {
|
|
146
|
+
// Get stats for this process
|
|
147
|
+
const stats = await getProcessStats(processId);
|
|
148
|
+
|
|
149
|
+
// Get the latest log to determine current status
|
|
150
|
+
const latestLog = await CampaignCreationLogNew.findOne({
|
|
151
|
+
where: { process_id: processId },
|
|
152
|
+
order: [["createdAt", "DESC"]],
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
processes.push({
|
|
156
|
+
process_id: processId,
|
|
157
|
+
created_at: initialLog.createdAt,
|
|
158
|
+
updated_at: latestLog.createdAt,
|
|
159
|
+
status: latestLog.status,
|
|
160
|
+
statistics: stats,
|
|
161
|
+
countries: await getCountriesByProcess(processId),
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Count total number of distinct processes
|
|
167
|
+
const totalProcessesCount = await CampaignCreationLogNew.count({
|
|
168
|
+
distinct: true,
|
|
169
|
+
col: "process_id",
|
|
170
|
+
where: whereClause,
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
return res.json({
|
|
174
|
+
success: true,
|
|
175
|
+
processes,
|
|
176
|
+
pagination: {
|
|
177
|
+
total: totalProcessesCount,
|
|
178
|
+
page: parseInt(page, 10),
|
|
179
|
+
limit: parseInt(limit, 10),
|
|
180
|
+
pages: Math.ceil(totalProcessesCount / parseInt(limit, 10)),
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
} catch (error) {
|
|
184
|
+
console.error("Error in getCampaignCreationProcesses:", error);
|
|
185
|
+
return res.status(500).json({
|
|
186
|
+
success: false,
|
|
187
|
+
error: error.message,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Get detailed hierarchical view of a specific process
|
|
194
|
+
* @param {Object} req - Express request object
|
|
195
|
+
* @param {Object} res - Express response object
|
|
196
|
+
*/
|
|
197
|
+
async function getCampaignCreationProcessDetails(req, res) {
|
|
198
|
+
try {
|
|
199
|
+
const { process_id } = req.params;
|
|
200
|
+
|
|
201
|
+
if (!process_id) {
|
|
202
|
+
return res.status(400).json({
|
|
203
|
+
success: false,
|
|
204
|
+
error: "Process ID is required",
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Get hierarchical view
|
|
209
|
+
const processDetails = await getProcessHierarchy(process_id);
|
|
210
|
+
|
|
211
|
+
if (!processDetails) {
|
|
212
|
+
return res.status(404).json({
|
|
213
|
+
success: false,
|
|
214
|
+
error: "Process not found",
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return res.json({
|
|
219
|
+
success: true,
|
|
220
|
+
process: processDetails,
|
|
221
|
+
});
|
|
222
|
+
} catch (error) {
|
|
223
|
+
console.error("Error in getCampaignCreationProcessDetails:", error);
|
|
224
|
+
return res.status(500).json({
|
|
225
|
+
success: false,
|
|
226
|
+
error: error.message,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Helper function to get countries involved in a process
|
|
233
|
+
* @param {String} processId - Process ID
|
|
234
|
+
* @returns {Promise<Array>} Array of country information
|
|
235
|
+
*/
|
|
236
|
+
async function getCountriesByProcess(processId) {
|
|
237
|
+
const countries = await CampaignCreationLogNew.findAll({
|
|
238
|
+
attributes: [
|
|
239
|
+
"country",
|
|
240
|
+
[
|
|
241
|
+
CampaignCreationLogNew.sequelize.fn(
|
|
242
|
+
"MAX",
|
|
243
|
+
CampaignCreationLogNew.sequelize.col("status")
|
|
244
|
+
),
|
|
245
|
+
"status",
|
|
246
|
+
],
|
|
247
|
+
],
|
|
248
|
+
where: {
|
|
249
|
+
process_id: processId,
|
|
250
|
+
country: { [Op.ne]: null },
|
|
251
|
+
stage: "CAMPAIGN_CREATION",
|
|
252
|
+
},
|
|
253
|
+
group: ["country"],
|
|
254
|
+
raw: true,
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
return countries;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
module.exports = {
|
|
261
|
+
getCampaignCreationLogs,
|
|
262
|
+
getCampaignCreationProcesses,
|
|
263
|
+
getCampaignCreationProcessDetails,
|
|
264
|
+
};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
module.exports = (sequelize, DataTypes) => {
|
|
2
|
+
const CampaignCreationLogNew = sequelize.define(
|
|
3
|
+
"CampaignCreationLogNew",
|
|
4
|
+
{
|
|
5
|
+
id: {
|
|
6
|
+
type: DataTypes.INTEGER,
|
|
7
|
+
primaryKey: true,
|
|
8
|
+
autoIncrement: true,
|
|
9
|
+
},
|
|
10
|
+
process_id: {
|
|
11
|
+
type: DataTypes.UUID,
|
|
12
|
+
allowNull: false,
|
|
13
|
+
comment: "Unique ID for the creation batch process",
|
|
14
|
+
},
|
|
15
|
+
stage: {
|
|
16
|
+
type: DataTypes.ENUM(
|
|
17
|
+
"PROCESS_STARTED",
|
|
18
|
+
"CAMPAIGN_CREATION",
|
|
19
|
+
"ADSET_CREATION",
|
|
20
|
+
"AD_CREATION"
|
|
21
|
+
),
|
|
22
|
+
allowNull: false,
|
|
23
|
+
comment: "Current stage of the campaign creation process",
|
|
24
|
+
},
|
|
25
|
+
status: {
|
|
26
|
+
type: DataTypes.ENUM("STARTED", "IN_PROGRESS", "COMPLETED", "FAILED"),
|
|
27
|
+
allowNull: false,
|
|
28
|
+
defaultValue: "STARTED",
|
|
29
|
+
comment: "Status of the current stage",
|
|
30
|
+
},
|
|
31
|
+
country: {
|
|
32
|
+
type: DataTypes.STRING,
|
|
33
|
+
allowNull: true,
|
|
34
|
+
comment: "Country being processed",
|
|
35
|
+
},
|
|
36
|
+
feed_campaign_id: {
|
|
37
|
+
type: DataTypes.STRING,
|
|
38
|
+
allowNull: true,
|
|
39
|
+
comment: "AGRS_CID of the created feed campaign",
|
|
40
|
+
},
|
|
41
|
+
facebook_campaign_id: {
|
|
42
|
+
type: DataTypes.STRING,
|
|
43
|
+
allowNull: true,
|
|
44
|
+
comment: "Facebook campaign ID if created",
|
|
45
|
+
},
|
|
46
|
+
facebook_adset_id: {
|
|
47
|
+
type: DataTypes.STRING,
|
|
48
|
+
allowNull: true,
|
|
49
|
+
comment: "Facebook adset ID if created",
|
|
50
|
+
},
|
|
51
|
+
facebook_ad_id: {
|
|
52
|
+
type: DataTypes.STRING,
|
|
53
|
+
allowNull: true,
|
|
54
|
+
comment: "Facebook ad ID if created",
|
|
55
|
+
},
|
|
56
|
+
parent_id: {
|
|
57
|
+
type: DataTypes.STRING,
|
|
58
|
+
allowNull: true,
|
|
59
|
+
comment: "Parent entity ID (campaign ID for adsets, adset ID for ads)",
|
|
60
|
+
},
|
|
61
|
+
entity_name: {
|
|
62
|
+
type: DataTypes.STRING,
|
|
63
|
+
allowNull: true,
|
|
64
|
+
comment: "Name of the created entity (campaign, adset, or ad name)",
|
|
65
|
+
},
|
|
66
|
+
entity_index: {
|
|
67
|
+
type: DataTypes.INTEGER,
|
|
68
|
+
allowNull: true,
|
|
69
|
+
comment:
|
|
70
|
+
"Index of this entity in a collection (for multiple adsets/ads)",
|
|
71
|
+
},
|
|
72
|
+
details: {
|
|
73
|
+
type: DataTypes.JSONB,
|
|
74
|
+
allowNull: true,
|
|
75
|
+
comment:
|
|
76
|
+
"Structured details about the stage, including original request, campaign, adset, or ad data",
|
|
77
|
+
},
|
|
78
|
+
error_message: {
|
|
79
|
+
type: DataTypes.TEXT,
|
|
80
|
+
allowNull: true,
|
|
81
|
+
comment: "Error message if process failed",
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
tableName: "CampaignCreationLogsNew",
|
|
86
|
+
timestamps: true,
|
|
87
|
+
indexes: [
|
|
88
|
+
{
|
|
89
|
+
fields: ["process_id"],
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
fields: ["stage"],
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
fields: ["status"],
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
fields: ["country"],
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
fields: ["feed_campaign_id"],
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
fields: ["facebook_campaign_id"],
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
fields: ["facebook_adset_id"],
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
fields: ["facebook_ad_id"],
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
fields: ["parent_id"],
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
fields: ["entity_name"],
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
fields: ["entity_index"],
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
fields: ["createdAt"],
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
CampaignCreationLogNew.associate = (models) => {
|
|
129
|
+
// Add associations if needed
|
|
130
|
+
if (models.CodefuelCampaign) {
|
|
131
|
+
CampaignCreationLogNew.belongsTo(models.CodefuelCampaign, {
|
|
132
|
+
foreignKey: "feed_campaign_id",
|
|
133
|
+
targetKey: "AGRSCID",
|
|
134
|
+
as: "FeedCampaign",
|
|
135
|
+
constraints: false,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
return CampaignCreationLogNew;
|
|
141
|
+
};
|
package/package.json
CHANGED
package/routes/api.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Add these new routes to the API router
|
|
2
|
+
|
|
3
|
+
// Import the controller
|
|
4
|
+
const campaignCreationLogsController = require("../controllers/campaignCreationLogsController");
|
|
5
|
+
|
|
6
|
+
// Add routes for campaign creation logs
|
|
7
|
+
router.get(
|
|
8
|
+
"/campaign-creation-logs",
|
|
9
|
+
campaignCreationLogsController.getCampaignCreationLogs
|
|
10
|
+
);
|
|
11
|
+
router.get(
|
|
12
|
+
"/campaign-creation-processes",
|
|
13
|
+
campaignCreationLogsController.getCampaignCreationProcesses
|
|
14
|
+
);
|
|
15
|
+
router.get(
|
|
16
|
+
"/campaign-creation-processes/:process_id",
|
|
17
|
+
campaignCreationLogsController.getCampaignCreationProcessDetails
|
|
18
|
+
);
|