agrs-sequelize-sdk 1.2.12 → 1.2.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agrs-sequelize-sdk",
3
- "version": "1.2.12",
3
+ "version": "1.2.13",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "start": "node index.js",
@@ -1,264 +0,0 @@
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
- };
@@ -1,73 +0,0 @@
1
- "use strict";
2
-
3
- module.exports = {
4
- up: async (queryInterface, Sequelize) => {
5
- // Add indexes for AdPerformance table
6
- await queryInterface.addIndex("AdPerformance", ["Date", "AdID"], {
7
- name: "ad_performance_date_adid_idx",
8
- unique: true,
9
- });
10
-
11
- await queryInterface.addIndex("AdPerformance", ["Date"], {
12
- name: "ad_performance_date_idx",
13
- });
14
-
15
- // Add indexes for Ad table
16
- await queryInterface.addIndex("Ad", ["AdSetID"], {
17
- name: "ad_adsetid_idx",
18
- });
19
-
20
- await queryInterface.addIndex("Ad", ["AGRS_CID"], {
21
- name: "ad_agrs_cid_idx",
22
- });
23
-
24
- await queryInterface.addIndex("Ad", ["Status"], {
25
- name: "ad_status_idx",
26
- });
27
-
28
- // Add indexes for AdSet table
29
- await queryInterface.addIndex("AdSet", ["CampaignID"], {
30
- name: "adset_campaignid_idx",
31
- });
32
-
33
- await queryInterface.addIndex("AdSet", ["Status"], {
34
- name: "adset_status_idx",
35
- });
36
-
37
- // Add indexes for Campaign table
38
- await queryInterface.addIndex("Campaign", ["AdAccountID"], {
39
- name: "campaign_adaccountid_idx",
40
- });
41
-
42
- await queryInterface.addIndex("Campaign", ["Status"], {
43
- name: "campaign_status_idx",
44
- });
45
-
46
- await queryInterface.addIndex("Campaign", ["CreatedTime"], {
47
- name: "campaign_createdtime_idx",
48
- });
49
- },
50
-
51
- down: async (queryInterface, Sequelize) => {
52
- // Remove indexes in reverse order
53
- await queryInterface.removeIndex("Campaign", "campaign_createdtime_idx");
54
- await queryInterface.removeIndex("Campaign", "campaign_status_idx");
55
- await queryInterface.removeIndex("Campaign", "campaign_adaccountid_idx");
56
-
57
- await queryInterface.removeIndex("AdSet", "adset_status_idx");
58
- await queryInterface.removeIndex("AdSet", "adset_campaignid_idx");
59
-
60
- await queryInterface.removeIndex("Ad", "ad_status_idx");
61
- await queryInterface.removeIndex("Ad", "ad_agrs_cid_idx");
62
- await queryInterface.removeIndex("Ad", "ad_adsetid_idx");
63
-
64
- await queryInterface.removeIndex(
65
- "AdPerformance",
66
- "ad_performance_date_idx"
67
- );
68
- await queryInterface.removeIndex(
69
- "AdPerformance",
70
- "ad_performance_date_adid_idx"
71
- );
72
- },
73
- };
package/routes/api.js DELETED
@@ -1,18 +0,0 @@
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
- );