powr-sdk-api 4.1.10 → 4.3.0
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/dist/index.js +7 -5
- package/dist/{services → managers}/functions.js +1 -1
- package/dist/managers/index.js +26 -0
- package/dist/{services/scheduledTasks.js → managers/tasks.js} +123 -143
- package/dist/{services → managers}/tools.js +1 -1
- package/dist/middleware/projectId.js +1 -1
- package/dist/routes/functions.js +3 -1
- package/dist/routes/index.js +3 -27
- package/dist/routes/tasks.js +304 -0
- package/dist/routes/tools.js +21 -8
- package/package.json +69 -71
- package/dist/admin/activities.js +0 -81
- package/dist/admin/auth.js +0 -234
- package/dist/admin/blogs.js +0 -94
- package/dist/admin/comments.js +0 -83
- package/dist/admin/files.js +0 -56
- package/dist/admin/forms.js +0 -242
- package/dist/admin/index.js +0 -53
- package/dist/admin/invoice.js +0 -163
- package/dist/admin/likes.js +0 -126
- package/dist/admin/notifications.js +0 -93
- package/dist/admin/plexx.js +0 -53
- package/dist/admin/ratings.js +0 -189
- package/dist/admin/routes.js +0 -132
- package/dist/admin/slides.js +0 -101
- package/dist/admin/users.js +0 -175
- package/dist/admin/waitlists.js +0 -94
- package/dist/logger/gcs.js +0 -78
- package/dist/logger/s3.js +0 -78
- package/dist/middleware/auth.js +0 -76
- package/dist/middleware/logger.js +0 -45
- package/dist/middleware/response.js +0 -53
- package/dist/routes/admin/index.js +0 -520
- package/dist/routes/blogs.js +0 -94
- package/dist/routes/invoice.js +0 -167
- package/dist/routes/plexx.js +0 -269
- package/dist/routes/routes.js +0 -143
- package/dist/routes/scheduledTasks.js +0 -240
- package/dist/scripts/update-tools-schema.js +0 -157
- package/dist/services/dbService.js +0 -42
- package/dist/services/logger.js +0 -35
- package/dist/services/plexx.js +0 -229
- package/dist/utils/auth.js +0 -19
- package/dist/utils/logger.js +0 -57
- package/dist/utils/s3-transport.js +0 -61
- package/dist/utils/s3.js +0 -78
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const express = require("express");
|
|
4
|
+
const router = express.Router();
|
|
5
|
+
const {
|
|
6
|
+
toolsManager,
|
|
7
|
+
scheduledTasksManager
|
|
8
|
+
} = require("../managers");
|
|
9
|
+
|
|
10
|
+
// GET /tasks - Get all tasks
|
|
11
|
+
router.get("/", async (req, res) => {
|
|
12
|
+
try {
|
|
13
|
+
const isAdmin = req.user.access === 100;
|
|
14
|
+
const result = await scheduledTasksManager.getUserTasks(req.user.powrId, req.projectId, isAdmin);
|
|
15
|
+
if (result.success) {
|
|
16
|
+
return res.status(200).json({
|
|
17
|
+
success: true,
|
|
18
|
+
tasks: result.tasks
|
|
19
|
+
});
|
|
20
|
+
} else {
|
|
21
|
+
return res.status(400).json({
|
|
22
|
+
success: false,
|
|
23
|
+
message: result.message
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
} catch (error) {
|
|
27
|
+
console.error("Error retrieving tasks:", error);
|
|
28
|
+
return res.status(500).json({
|
|
29
|
+
success: false,
|
|
30
|
+
message: "Failed to retrieve tasks."
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// GET /tasks/:taskId - Get specific task
|
|
36
|
+
router.get("/:taskId", async (req, res) => {
|
|
37
|
+
try {
|
|
38
|
+
const isAdmin = req.user.access === 100;
|
|
39
|
+
const result = await scheduledTasksManager.getTask(req.params.taskId, req.user.powrId, req.projectId, isAdmin);
|
|
40
|
+
if (result.success) {
|
|
41
|
+
return res.status(200).json({
|
|
42
|
+
success: true,
|
|
43
|
+
task: result.task
|
|
44
|
+
});
|
|
45
|
+
} else {
|
|
46
|
+
return res.status(404).json({
|
|
47
|
+
success: false,
|
|
48
|
+
message: result.message
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error("Error retrieving task:", error);
|
|
53
|
+
return res.status(500).json({
|
|
54
|
+
success: false,
|
|
55
|
+
message: "Failed to retrieve task."
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// POST /tasks - Create new task
|
|
61
|
+
router.post("/", async (req, res) => {
|
|
62
|
+
try {
|
|
63
|
+
var _tool$actions;
|
|
64
|
+
const {
|
|
65
|
+
name,
|
|
66
|
+
description,
|
|
67
|
+
scheduledFor,
|
|
68
|
+
toolId,
|
|
69
|
+
actionId,
|
|
70
|
+
params,
|
|
71
|
+
isActive
|
|
72
|
+
} = req.body;
|
|
73
|
+
|
|
74
|
+
// Validate required fields
|
|
75
|
+
if (!name || !toolId || !actionId) {
|
|
76
|
+
return res.status(400).json({
|
|
77
|
+
success: false,
|
|
78
|
+
message: "Missing required fields: name, toolId, actionId"
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Validate tool exists
|
|
83
|
+
const tool = toolsManager.getTool(toolId);
|
|
84
|
+
if (!tool) {
|
|
85
|
+
return res.status(400).json({
|
|
86
|
+
success: false,
|
|
87
|
+
message: `Tool not found: ${toolId}`
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Validate action exists
|
|
92
|
+
const action = (_tool$actions = tool.actions) === null || _tool$actions === void 0 ? void 0 : _tool$actions.find(a => a.id === actionId);
|
|
93
|
+
if (!action) {
|
|
94
|
+
return res.status(400).json({
|
|
95
|
+
success: false,
|
|
96
|
+
message: `Action not found: ${actionId} for tool ${toolId}`
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const taskData = {
|
|
100
|
+
name,
|
|
101
|
+
description,
|
|
102
|
+
scheduledFor,
|
|
103
|
+
// null, timestamp, or cron expression
|
|
104
|
+
toolId,
|
|
105
|
+
actionId,
|
|
106
|
+
params: params || {},
|
|
107
|
+
userId: req.user.powrId,
|
|
108
|
+
projectId: req.projectId,
|
|
109
|
+
isActive: isActive !== false // Default to true
|
|
110
|
+
};
|
|
111
|
+
const result = await scheduledTasksManager.createTask(taskData);
|
|
112
|
+
if (result.success) {
|
|
113
|
+
res.status(201).json({
|
|
114
|
+
success: true,
|
|
115
|
+
message: "Task created successfully",
|
|
116
|
+
task: result.task
|
|
117
|
+
});
|
|
118
|
+
} else {
|
|
119
|
+
res.status(400).json({
|
|
120
|
+
success: false,
|
|
121
|
+
message: result.message
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error("❌ Error creating scheduled task:", error);
|
|
126
|
+
res.status(500).json({
|
|
127
|
+
success: false,
|
|
128
|
+
message: "Failed to create scheduled task"
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// PUT /tasks/:taskId - Update task
|
|
134
|
+
router.put("/:taskId", async (req, res) => {
|
|
135
|
+
try {
|
|
136
|
+
const {
|
|
137
|
+
name,
|
|
138
|
+
description,
|
|
139
|
+
scheduledFor,
|
|
140
|
+
toolId,
|
|
141
|
+
actionId,
|
|
142
|
+
params,
|
|
143
|
+
isActive
|
|
144
|
+
} = req.body;
|
|
145
|
+
|
|
146
|
+
// Validate tool exists if toolId is being updated
|
|
147
|
+
if (toolId) {
|
|
148
|
+
const tool = toolsManager.getTool(toolId);
|
|
149
|
+
if (!tool) {
|
|
150
|
+
return res.status(400).json({
|
|
151
|
+
success: false,
|
|
152
|
+
message: `Tool not found: ${toolId}`
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Validate action exists if actionId is being updated
|
|
157
|
+
if (actionId) {
|
|
158
|
+
var _tool$actions2;
|
|
159
|
+
const action = (_tool$actions2 = tool.actions) === null || _tool$actions2 === void 0 ? void 0 : _tool$actions2.find(a => a.id === actionId);
|
|
160
|
+
if (!action) {
|
|
161
|
+
return res.status(400).json({
|
|
162
|
+
success: false,
|
|
163
|
+
message: `Action not found: ${actionId} for tool ${toolId}`
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const updateData = {};
|
|
169
|
+
if (name !== undefined) updateData.name = name;
|
|
170
|
+
if (description !== undefined) updateData.description = description;
|
|
171
|
+
if (scheduledFor !== undefined) updateData.scheduledFor = scheduledFor;
|
|
172
|
+
if (toolId !== undefined) updateData.toolId = toolId;
|
|
173
|
+
if (actionId !== undefined) updateData.actionId = actionId;
|
|
174
|
+
if (params !== undefined) updateData.params = params;
|
|
175
|
+
if (isActive !== undefined) updateData.isActive = isActive;
|
|
176
|
+
const isAdmin = req.user.access === 100;
|
|
177
|
+
const result = await scheduledTasksManager.updateTask(req.params.taskId, req.user.powrId, req.projectId, updateData, isAdmin);
|
|
178
|
+
if (result.success) {
|
|
179
|
+
res.status(200).json({
|
|
180
|
+
success: true,
|
|
181
|
+
message: "Task updated successfully"
|
|
182
|
+
});
|
|
183
|
+
} else {
|
|
184
|
+
res.status(400).json({
|
|
185
|
+
success: false,
|
|
186
|
+
message: result.message
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
} catch (error) {
|
|
190
|
+
console.error("❌ Error updating scheduled task:", error);
|
|
191
|
+
res.status(500).json({
|
|
192
|
+
success: false,
|
|
193
|
+
message: "Failed to update scheduled task"
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// POST /tasks/:taskId/execute - Execute task manually
|
|
199
|
+
router.post("/:taskId/execute", async (req, res) => {
|
|
200
|
+
try {
|
|
201
|
+
const taskId = req.params.taskId;
|
|
202
|
+
const isAdmin = req.user.access === 100;
|
|
203
|
+
const result = await scheduledTasksManager.executeTask(taskId, req.user.powrId, req.projectId, isAdmin);
|
|
204
|
+
if (result.success) {
|
|
205
|
+
res.json({
|
|
206
|
+
success: true,
|
|
207
|
+
message: "Task executed successfully",
|
|
208
|
+
result: result.result
|
|
209
|
+
});
|
|
210
|
+
} else {
|
|
211
|
+
res.status(400).json({
|
|
212
|
+
success: false,
|
|
213
|
+
message: result.message
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
} catch (error) {
|
|
217
|
+
console.error("❌ Error executing scheduled task:", error);
|
|
218
|
+
res.status(500).json({
|
|
219
|
+
success: false,
|
|
220
|
+
message: "Failed to execute scheduled task"
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// POST /tasks/:taskId/toggle - Toggle task active status
|
|
226
|
+
router.post("/:taskId/toggle", async (req, res) => {
|
|
227
|
+
try {
|
|
228
|
+
const taskId = req.params.taskId;
|
|
229
|
+
const {
|
|
230
|
+
isActive
|
|
231
|
+
} = req.body;
|
|
232
|
+
const isAdmin = req.user.access === 100;
|
|
233
|
+
const result = await scheduledTasksManager.toggleTask(taskId, req.user.powrId, req.projectId, isActive, isAdmin);
|
|
234
|
+
if (result.success) {
|
|
235
|
+
res.json({
|
|
236
|
+
success: true,
|
|
237
|
+
message: `Task ${isActive ? 'activated' : 'deactivated'} successfully`
|
|
238
|
+
});
|
|
239
|
+
} else {
|
|
240
|
+
res.status(400).json({
|
|
241
|
+
success: false,
|
|
242
|
+
message: result.message
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
} catch (error) {
|
|
246
|
+
console.error("❌ Error toggling scheduled task:", error);
|
|
247
|
+
res.status(500).json({
|
|
248
|
+
success: false,
|
|
249
|
+
message: "Failed to toggle scheduled task"
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
// DELETE /tasks/:taskId - Delete task
|
|
255
|
+
router.delete("/:taskId", async (req, res) => {
|
|
256
|
+
try {
|
|
257
|
+
const taskId = req.params.taskId;
|
|
258
|
+
const isAdmin = req.user.access === 100;
|
|
259
|
+
const result = await scheduledTasksManager.deleteTask(taskId, req.user.powrId, req.projectId, isAdmin);
|
|
260
|
+
if (result.success) {
|
|
261
|
+
res.json({
|
|
262
|
+
success: true,
|
|
263
|
+
message: "Task deleted successfully"
|
|
264
|
+
});
|
|
265
|
+
} else {
|
|
266
|
+
res.status(400).json({
|
|
267
|
+
success: false,
|
|
268
|
+
message: result.message
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
} catch (error) {
|
|
272
|
+
console.error("❌ Error deleting scheduled task:", error);
|
|
273
|
+
res.status(500).json({
|
|
274
|
+
success: false,
|
|
275
|
+
message: "Failed to delete scheduled task"
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
// POST /tasks/execute-scheduled - Execute all scheduled tasks (called by Atlas)
|
|
281
|
+
router.post("/execute-scheduled", async (req, res) => {
|
|
282
|
+
try {
|
|
283
|
+
const projectId = req.projectId;
|
|
284
|
+
console.log(`🔍 API: Executing scheduled tasks for project: ${projectId}`);
|
|
285
|
+
|
|
286
|
+
// Execute all scheduled tasks for this project
|
|
287
|
+
const result = await scheduledTasksManager.executeScheduledTasks(projectId);
|
|
288
|
+
console.log(`✅ API: Scheduled tasks execution completed for project: ${projectId}`);
|
|
289
|
+
res.json({
|
|
290
|
+
success: true,
|
|
291
|
+
message: "Scheduled tasks executed successfully",
|
|
292
|
+
projectId: projectId,
|
|
293
|
+
result: result
|
|
294
|
+
});
|
|
295
|
+
} catch (error) {
|
|
296
|
+
console.error("❌ API: Error executing scheduled tasks:", error);
|
|
297
|
+
res.status(500).json({
|
|
298
|
+
success: false,
|
|
299
|
+
message: "Failed to execute scheduled tasks",
|
|
300
|
+
error: error.message
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
module.exports = router;
|
package/dist/routes/tools.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
const express = require("express");
|
|
4
4
|
const router = express.Router();
|
|
5
|
-
const
|
|
5
|
+
const {
|
|
6
|
+
toolsManager
|
|
7
|
+
} = require("../managers");
|
|
6
8
|
const {
|
|
7
9
|
getDb
|
|
8
10
|
} = require("../services/mongo");
|
|
@@ -192,7 +194,7 @@ router.post('/:toolId/configure', async (req, res) => {
|
|
|
192
194
|
// Execute tool action
|
|
193
195
|
router.post('/:toolId/execute', async (req, res) => {
|
|
194
196
|
try {
|
|
195
|
-
var _req$
|
|
197
|
+
var _req$headers$authoriz;
|
|
196
198
|
const {
|
|
197
199
|
toolId
|
|
198
200
|
} = req.params;
|
|
@@ -200,13 +202,24 @@ router.post('/:toolId/execute', async (req, res) => {
|
|
|
200
202
|
actionId,
|
|
201
203
|
params
|
|
202
204
|
} = req.body;
|
|
203
|
-
const userId = (_req$user2 = req.user) === null || _req$user2 === void 0 ? void 0 : _req$user2.powrId; // From JWT token
|
|
204
205
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
206
|
+
// Check for service-to-service authentication
|
|
207
|
+
const apiKey = req.headers['x-api-key'] || ((_req$headers$authoriz = req.headers['authorization']) === null || _req$headers$authoriz === void 0 ? void 0 : _req$headers$authoriz.replace('Bearer ', ''));
|
|
208
|
+
const isServiceCall = apiKey === process.env.POWR_SERVICE_API_KEY;
|
|
209
|
+
let userId;
|
|
210
|
+
if (isServiceCall) {
|
|
211
|
+
// For service calls, use the userId from the task
|
|
212
|
+
userId = req.headers['x-user-id'] || 'system';
|
|
213
|
+
} else {
|
|
214
|
+
var _req$user2;
|
|
215
|
+
// For regular calls, use JWT token
|
|
216
|
+
userId = (_req$user2 = req.user) === null || _req$user2 === void 0 ? void 0 : _req$user2.powrId;
|
|
217
|
+
if (!userId) {
|
|
218
|
+
return res.status(401).json({
|
|
219
|
+
success: false,
|
|
220
|
+
message: "User not authenticated"
|
|
221
|
+
});
|
|
222
|
+
}
|
|
210
223
|
}
|
|
211
224
|
if (!actionId) {
|
|
212
225
|
return res.status(400).json({
|
package/package.json
CHANGED
|
@@ -1,71 +1,69 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "powr-sdk-api",
|
|
3
|
-
"version": "4.
|
|
4
|
-
"description": "Shared API core library for PowrStack projects",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"dist",
|
|
9
|
-
"README.md"
|
|
10
|
-
],
|
|
11
|
-
"scripts": {
|
|
12
|
-
"test": "jest --passWithNoTests",
|
|
13
|
-
"lint": "eslint .",
|
|
14
|
-
"build": "babel src -d dist",
|
|
15
|
-
"prepare": "npm run build",
|
|
16
|
-
"prepublishOnly": "npm run test"
|
|
17
|
-
},
|
|
18
|
-
"keywords": [
|
|
19
|
-
"api",
|
|
20
|
-
"express",
|
|
21
|
-
"middleware",
|
|
22
|
-
"error-handling",
|
|
23
|
-
"response-formatting",
|
|
24
|
-
"logging",
|
|
25
|
-
"swagger",
|
|
26
|
-
"documentation"
|
|
27
|
-
],
|
|
28
|
-
"author": "Lawazia Tech",
|
|
29
|
-
"license": "ISC",
|
|
30
|
-
"repository": {
|
|
31
|
-
"type": "git",
|
|
32
|
-
"url": "git+https://github.com/powrstack/powr-sdk-api.git"
|
|
33
|
-
},
|
|
34
|
-
"bugs": {
|
|
35
|
-
"url": "https://github.com/powrstack/powr-sdk-api/issues"
|
|
36
|
-
},
|
|
37
|
-
"homepage": "https://github.com/powrstack/powr-sdk-api#readme",
|
|
38
|
-
"dependencies": {
|
|
39
|
-
"@aws-sdk/client-s3": "^3.787.0",
|
|
40
|
-
"@google-cloud/storage": "^7.16.0",
|
|
41
|
-
"axios": "^1.6.0",
|
|
42
|
-
"bcrypt": "^5.1.1",
|
|
43
|
-
"cron-parser": "^4.9.0",
|
|
44
|
-
"express": "^4.18.2",
|
|
45
|
-
"jsonwebtoken": "^9.0.2",
|
|
46
|
-
"mongodb": "^6.3.0",
|
|
47
|
-
"multer": "^1.4.5-lts.1",
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"@babel/
|
|
56
|
-
"@
|
|
57
|
-
"@
|
|
58
|
-
"@types/express": "^4.
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "powr-sdk-api",
|
|
3
|
+
"version": "4.3.0",
|
|
4
|
+
"description": "Shared API core library for PowrStack projects",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"test": "jest --passWithNoTests",
|
|
13
|
+
"lint": "eslint .",
|
|
14
|
+
"build": "babel src -d dist",
|
|
15
|
+
"prepare": "npm run build",
|
|
16
|
+
"prepublishOnly": "npm run test"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"api",
|
|
20
|
+
"express",
|
|
21
|
+
"middleware",
|
|
22
|
+
"error-handling",
|
|
23
|
+
"response-formatting",
|
|
24
|
+
"logging",
|
|
25
|
+
"swagger",
|
|
26
|
+
"documentation"
|
|
27
|
+
],
|
|
28
|
+
"author": "Lawazia Tech",
|
|
29
|
+
"license": "ISC",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/powrstack/powr-sdk-api.git"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/powrstack/powr-sdk-api/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/powrstack/powr-sdk-api#readme",
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@aws-sdk/client-s3": "^3.787.0",
|
|
40
|
+
"@google-cloud/storage": "^7.16.0",
|
|
41
|
+
"axios": "^1.6.0",
|
|
42
|
+
"bcrypt": "^5.1.1",
|
|
43
|
+
"cron-parser": "^4.9.0",
|
|
44
|
+
"express": "^4.18.2",
|
|
45
|
+
"jsonwebtoken": "^9.0.2",
|
|
46
|
+
"mongodb": "^6.3.0",
|
|
47
|
+
"multer": "^1.4.5-lts.1",
|
|
48
|
+
"nodemailer": "^6.10.0",
|
|
49
|
+
"swagger-jsdoc": "^6.2.8",
|
|
50
|
+
"winston": "^3.17.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@babel/cli": "^7.23.9",
|
|
54
|
+
"@babel/core": "^7.24.0",
|
|
55
|
+
"@babel/preset-env": "^7.24.0",
|
|
56
|
+
"@types/express": "^4.17.21",
|
|
57
|
+
"@types/swagger-jsdoc": "^6.0.4",
|
|
58
|
+
"@types/swagger-ui-express": "^4.1.6",
|
|
59
|
+
"eslint": "^8.57.0",
|
|
60
|
+
"jest": "^29.7.0",
|
|
61
|
+
"typescript": "^5.3.3"
|
|
62
|
+
},
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"express": "^4.18.2"
|
|
65
|
+
},
|
|
66
|
+
"engines": {
|
|
67
|
+
"node": ">=14.0.0"
|
|
68
|
+
}
|
|
69
|
+
}
|
package/dist/admin/activities.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const router = express.Router();
|
|
5
|
-
const {
|
|
6
|
-
getDb
|
|
7
|
-
} = require("../services/mongo");
|
|
8
|
-
|
|
9
|
-
// Get activities
|
|
10
|
-
router.get("/", async (req, res) => {
|
|
11
|
-
const {
|
|
12
|
-
projectId,
|
|
13
|
-
contentId
|
|
14
|
-
} = req.query;
|
|
15
|
-
try {
|
|
16
|
-
const query = {
|
|
17
|
-
projectId
|
|
18
|
-
};
|
|
19
|
-
if (contentId) {
|
|
20
|
-
query.contentId = contentId;
|
|
21
|
-
}
|
|
22
|
-
console.log("Filter.....:", query);
|
|
23
|
-
const activities = await getDb().collection("activities").find(query).toArray();
|
|
24
|
-
if (!activities || activities.length === 0) {
|
|
25
|
-
console.log("Data not found.");
|
|
26
|
-
return res.status(200).json({
|
|
27
|
-
success: true,
|
|
28
|
-
activities: []
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
return res.status(200).json({
|
|
32
|
-
success: true,
|
|
33
|
-
activities: activities
|
|
34
|
-
});
|
|
35
|
-
} catch (error) {
|
|
36
|
-
console.error("Error retrieving activities:", error);
|
|
37
|
-
return res.status(500).json({
|
|
38
|
-
success: false,
|
|
39
|
-
message: "Failed to retrieve activities."
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// Add activity
|
|
45
|
-
router.post("/", async (req, res) => {
|
|
46
|
-
const {
|
|
47
|
-
projectId,
|
|
48
|
-
contentId,
|
|
49
|
-
activity
|
|
50
|
-
} = req.body;
|
|
51
|
-
const activityData = {
|
|
52
|
-
projectId,
|
|
53
|
-
contentId,
|
|
54
|
-
activity,
|
|
55
|
-
createdAt: new Date()
|
|
56
|
-
};
|
|
57
|
-
try {
|
|
58
|
-
const result = await getDb().collection("activities").insertOne(activityData);
|
|
59
|
-
if (result && result.insertedId) {
|
|
60
|
-
console.log("Activity added with ID:", result.insertedId);
|
|
61
|
-
return res.status(200).json({
|
|
62
|
-
success: true,
|
|
63
|
-
message: "Activity added successfully.",
|
|
64
|
-
activityId: result.insertedId
|
|
65
|
-
});
|
|
66
|
-
} else {
|
|
67
|
-
console.error("Insert operation failed. Result:", result);
|
|
68
|
-
return res.status(500).json({
|
|
69
|
-
success: false,
|
|
70
|
-
message: "Activity could not be added."
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
} catch (error) {
|
|
74
|
-
console.error("Error adding activity:", error);
|
|
75
|
-
return res.status(500).json({
|
|
76
|
-
success: false,
|
|
77
|
-
message: "Failed to add activity due to a server error."
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
module.exports = router;
|