powr-sdk-api 2.4.3 → 2.4.5
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/routes/activities.js +35 -42
- package/dist/routes/auth.js +14 -9
- package/dist/routes/comments.js +40 -44
- package/dist/routes/slides.js +45 -65
- package/package.json +1 -1
|
@@ -6,31 +6,25 @@ const {
|
|
|
6
6
|
getDb
|
|
7
7
|
} = require("../services/mongo");
|
|
8
8
|
|
|
9
|
-
// Get activities
|
|
9
|
+
// Get all activities
|
|
10
10
|
router.get("/", async (req, res) => {
|
|
11
|
-
const {
|
|
12
|
-
projectId,
|
|
13
|
-
contentId
|
|
14
|
-
} = req.query;
|
|
15
11
|
try {
|
|
12
|
+
const {
|
|
13
|
+
contentId
|
|
14
|
+
} = req.query;
|
|
15
|
+
const projectId = req.projectId; // Use middleware-injected projectId
|
|
16
|
+
|
|
16
17
|
const query = {
|
|
17
18
|
projectId
|
|
18
19
|
};
|
|
19
20
|
if (contentId) {
|
|
20
21
|
query.contentId = contentId;
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
-
const activities = await
|
|
24
|
-
|
|
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({
|
|
23
|
+
const db = await getDb();
|
|
24
|
+
const activities = await db.collection("activities").find(query).toArray();
|
|
25
|
+
return res.json({
|
|
32
26
|
success: true,
|
|
33
|
-
|
|
27
|
+
data: activities
|
|
34
28
|
});
|
|
35
29
|
} catch (error) {
|
|
36
30
|
console.error("Error retrieving activities:", error);
|
|
@@ -41,40 +35,39 @@ router.get("/", async (req, res) => {
|
|
|
41
35
|
}
|
|
42
36
|
});
|
|
43
37
|
|
|
44
|
-
//
|
|
38
|
+
// Create new activity
|
|
45
39
|
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
40
|
try {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
} else {
|
|
67
|
-
console.error("Insert operation failed. Result:", result);
|
|
68
|
-
return res.status(500).json({
|
|
41
|
+
const {
|
|
42
|
+
contentId,
|
|
43
|
+
activity
|
|
44
|
+
} = req.body;
|
|
45
|
+
const projectId = req.projectId; // Use middleware-injected projectId
|
|
46
|
+
|
|
47
|
+
if (!contentId || !activity) {
|
|
48
|
+
return res.status(400).json({
|
|
69
49
|
success: false,
|
|
70
|
-
message: "
|
|
50
|
+
message: "Content ID and activity are required"
|
|
71
51
|
});
|
|
72
52
|
}
|
|
53
|
+
const activityData = {
|
|
54
|
+
projectId,
|
|
55
|
+
contentId,
|
|
56
|
+
activity,
|
|
57
|
+
createdAt: new Date()
|
|
58
|
+
};
|
|
59
|
+
const db = await getDb();
|
|
60
|
+
const result = await db.collection("activities").insertOne(activityData);
|
|
61
|
+
return res.status(201).json({
|
|
62
|
+
success: true,
|
|
63
|
+
message: "Activity created successfully",
|
|
64
|
+
id: result.insertedId
|
|
65
|
+
});
|
|
73
66
|
} catch (error) {
|
|
74
|
-
console.error("Error
|
|
67
|
+
console.error("Error creating activity:", error);
|
|
75
68
|
return res.status(500).json({
|
|
76
69
|
success: false,
|
|
77
|
-
message: "Failed to
|
|
70
|
+
message: "Failed to create activity."
|
|
78
71
|
});
|
|
79
72
|
}
|
|
80
73
|
});
|
package/dist/routes/auth.js
CHANGED
|
@@ -128,7 +128,8 @@ router.post("/login", async (req, res) => {
|
|
|
128
128
|
}]
|
|
129
129
|
};
|
|
130
130
|
console.log(q);
|
|
131
|
-
const
|
|
131
|
+
const db = await getDb();
|
|
132
|
+
const user = await db.collection("users").findOne(q);
|
|
132
133
|
console.log(user);
|
|
133
134
|
if (!user) {
|
|
134
135
|
return res.status(401).json({
|
|
@@ -147,13 +148,13 @@ router.post("/login", async (req, res) => {
|
|
|
147
148
|
// Fetch profile data if projectId is provided
|
|
148
149
|
let profile = null;
|
|
149
150
|
if (projectId) {
|
|
150
|
-
profile = await
|
|
151
|
+
profile = await db.collection("profiles").findOne({
|
|
151
152
|
userId: user._id,
|
|
152
153
|
projectId: projectId
|
|
153
154
|
});
|
|
154
155
|
if (profile) {
|
|
155
156
|
// Update lastActiveAt
|
|
156
|
-
await
|
|
157
|
+
await db.collection("profiles").updateOne({
|
|
157
158
|
_id: profile._id
|
|
158
159
|
}, {
|
|
159
160
|
$set: {
|
|
@@ -168,7 +169,7 @@ router.post("/login", async (req, res) => {
|
|
|
168
169
|
createdAt: new Date(),
|
|
169
170
|
updatedAt: new Date()
|
|
170
171
|
};
|
|
171
|
-
const profileResult = await
|
|
172
|
+
const profileResult = await db.collection("profiles").insertOne(newProfile);
|
|
172
173
|
profile = {
|
|
173
174
|
_id: profileResult.insertedId,
|
|
174
175
|
...newProfile
|
|
@@ -226,7 +227,8 @@ router.post("/forgot-password", async (req, res) => {
|
|
|
226
227
|
message: "Username is required"
|
|
227
228
|
});
|
|
228
229
|
}
|
|
229
|
-
const
|
|
230
|
+
const db = await getDb();
|
|
231
|
+
const user = await db.collection("users").findOne({
|
|
230
232
|
username: username
|
|
231
233
|
});
|
|
232
234
|
if (!user) {
|
|
@@ -243,7 +245,7 @@ router.post("/forgot-password", async (req, res) => {
|
|
|
243
245
|
exp: Math.floor(Date.now() / 1000) + 60 * 60
|
|
244
246
|
};
|
|
245
247
|
const resetToken = jwt.sign(resetPayload, config.jwtToken);
|
|
246
|
-
await
|
|
248
|
+
await db.collection("users").updateOne({
|
|
247
249
|
_id: user._id
|
|
248
250
|
}, {
|
|
249
251
|
$set: {
|
|
@@ -294,7 +296,8 @@ router.post("/reset-password", async (req, res) => {
|
|
|
294
296
|
message: "Invalid reset token type or missing user ID"
|
|
295
297
|
});
|
|
296
298
|
}
|
|
297
|
-
const
|
|
299
|
+
const db = await getDb();
|
|
300
|
+
const user = await db.collection("users").findOne({
|
|
298
301
|
_id: new ObjectId(decoded.userId),
|
|
299
302
|
resetToken: resetToken,
|
|
300
303
|
resetTokenExpiry: {
|
|
@@ -311,7 +314,9 @@ router.post("/reset-password", async (req, res) => {
|
|
|
311
314
|
// Hash the new password
|
|
312
315
|
const saltRounds = 10;
|
|
313
316
|
const hashedPassword = await bcrypt.hash(newPassword, saltRounds);
|
|
314
|
-
|
|
317
|
+
|
|
318
|
+
// Update user with new password and clear reset token
|
|
319
|
+
await db.collection("users").updateOne({
|
|
315
320
|
_id: user._id
|
|
316
321
|
}, {
|
|
317
322
|
$set: {
|
|
@@ -327,7 +332,7 @@ router.post("/reset-password", async (req, res) => {
|
|
|
327
332
|
message: "Password reset successfully"
|
|
328
333
|
});
|
|
329
334
|
} catch (error) {
|
|
330
|
-
console.error("Error
|
|
335
|
+
console.error("Error in reset password:", error);
|
|
331
336
|
return res.status(500).json({
|
|
332
337
|
success: false,
|
|
333
338
|
message: "Failed to reset password."
|
package/dist/routes/comments.js
CHANGED
|
@@ -5,32 +5,29 @@ const router = express.Router();
|
|
|
5
5
|
const {
|
|
6
6
|
getDb
|
|
7
7
|
} = require("../services/mongo");
|
|
8
|
+
const {
|
|
9
|
+
ObjectId
|
|
10
|
+
} = require("mongodb");
|
|
8
11
|
|
|
9
|
-
// Get comments
|
|
12
|
+
// Get all comments
|
|
10
13
|
router.get("/", async (req, res) => {
|
|
11
|
-
const {
|
|
12
|
-
projectId,
|
|
13
|
-
contentId
|
|
14
|
-
} = req.query;
|
|
15
14
|
try {
|
|
15
|
+
const {
|
|
16
|
+
contentId
|
|
17
|
+
} = req.query;
|
|
18
|
+
const projectId = req.projectId; // Use middleware-injected projectId
|
|
19
|
+
|
|
16
20
|
const query = {
|
|
17
21
|
projectId
|
|
18
22
|
};
|
|
19
23
|
if (contentId) {
|
|
20
24
|
query.contentId = contentId;
|
|
21
25
|
}
|
|
22
|
-
|
|
23
|
-
const commentData = await
|
|
24
|
-
|
|
25
|
-
console.log("Data not found.");
|
|
26
|
-
return res.status(200).json({
|
|
27
|
-
success: true,
|
|
28
|
-
comments: []
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
return res.status(200).json({
|
|
26
|
+
const db = await getDb();
|
|
27
|
+
const commentData = await db.collection("comments").find(query).toArray();
|
|
28
|
+
return res.json({
|
|
32
29
|
success: true,
|
|
33
|
-
|
|
30
|
+
data: commentData
|
|
34
31
|
});
|
|
35
32
|
} catch (error) {
|
|
36
33
|
console.error("Error retrieving comments:", error);
|
|
@@ -41,42 +38,41 @@ router.get("/", async (req, res) => {
|
|
|
41
38
|
}
|
|
42
39
|
});
|
|
43
40
|
|
|
44
|
-
//
|
|
41
|
+
// Create new comment
|
|
45
42
|
router.post("/", async (req, res) => {
|
|
46
|
-
const {
|
|
47
|
-
projectId,
|
|
48
|
-
contentId,
|
|
49
|
-
comment,
|
|
50
|
-
...customFields
|
|
51
|
-
} = req.body;
|
|
52
|
-
const commentData = {
|
|
53
|
-
projectId,
|
|
54
|
-
contentId,
|
|
55
|
-
comment,
|
|
56
|
-
...customFields,
|
|
57
|
-
createdAt: new Date()
|
|
58
|
-
};
|
|
59
43
|
try {
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
console.error("Insert operation failed. Result:", result);
|
|
70
|
-
return res.status(500).json({
|
|
44
|
+
const {
|
|
45
|
+
contentId,
|
|
46
|
+
comment,
|
|
47
|
+
...customFields
|
|
48
|
+
} = req.body;
|
|
49
|
+
const projectId = req.projectId; // Use middleware-injected projectId
|
|
50
|
+
|
|
51
|
+
if (!contentId || !comment) {
|
|
52
|
+
return res.status(400).json({
|
|
71
53
|
success: false,
|
|
72
|
-
message: "
|
|
54
|
+
message: "Content ID and comment are required"
|
|
73
55
|
});
|
|
74
56
|
}
|
|
57
|
+
const commentData = {
|
|
58
|
+
projectId,
|
|
59
|
+
contentId,
|
|
60
|
+
comment,
|
|
61
|
+
...customFields,
|
|
62
|
+
createdAt: new Date()
|
|
63
|
+
};
|
|
64
|
+
const db = await getDb();
|
|
65
|
+
const result = await db.collection("comments").insertOne(commentData);
|
|
66
|
+
return res.status(201).json({
|
|
67
|
+
success: true,
|
|
68
|
+
message: "Comment created successfully",
|
|
69
|
+
id: result.insertedId
|
|
70
|
+
});
|
|
75
71
|
} catch (error) {
|
|
76
|
-
console.error("Error
|
|
72
|
+
console.error("Error creating comment:", error);
|
|
77
73
|
return res.status(500).json({
|
|
78
74
|
success: false,
|
|
79
|
-
message: "Failed to
|
|
75
|
+
message: "Failed to create comment."
|
|
80
76
|
});
|
|
81
77
|
}
|
|
82
78
|
});
|
package/dist/routes/slides.js
CHANGED
|
@@ -1,38 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const express = require(
|
|
3
|
+
const express = require("express");
|
|
4
4
|
const router = express.Router();
|
|
5
5
|
const {
|
|
6
6
|
getDb
|
|
7
7
|
} = require('../services/mongo');
|
|
8
8
|
|
|
9
|
-
// Get slides
|
|
10
|
-
router.get(
|
|
11
|
-
const {
|
|
12
|
-
projectId,
|
|
13
|
-
tag
|
|
14
|
-
} = req.query;
|
|
9
|
+
// Get all slides
|
|
10
|
+
router.get("/", async (req, res) => {
|
|
15
11
|
try {
|
|
12
|
+
const {
|
|
13
|
+
tag
|
|
14
|
+
} = req.query;
|
|
15
|
+
const projectId = req.projectId; // Use middleware-injected projectId
|
|
16
16
|
const query = {
|
|
17
17
|
projectId
|
|
18
18
|
};
|
|
19
19
|
if (tag) {
|
|
20
20
|
query.tag = tag;
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
const slidesData = await
|
|
24
|
-
|
|
25
|
-
console.log("Data not found.");
|
|
26
|
-
return res.status(200).json({
|
|
27
|
-
success: true,
|
|
28
|
-
slides: []
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
const sortedData = slidesData.sort((a, b) => new Date(b === null || b === void 0 ? void 0 : b.createdAt) - new Date(a === null || a === void 0 ? void 0 : a.createdAt));
|
|
32
|
-
console.log("Slides retrieved and sorted:", sortedData);
|
|
33
|
-
return res.status(200).json({
|
|
22
|
+
const db = await getDb();
|
|
23
|
+
const slidesData = await db.collection('slides').find(query).toArray();
|
|
24
|
+
return res.json({
|
|
34
25
|
success: true,
|
|
35
|
-
|
|
26
|
+
data: slidesData
|
|
36
27
|
});
|
|
37
28
|
} catch (error) {
|
|
38
29
|
console.error("Error retrieving slides:", error);
|
|
@@ -43,58 +34,47 @@ router.get('/', async (req, res) => {
|
|
|
43
34
|
}
|
|
44
35
|
});
|
|
45
36
|
|
|
46
|
-
//
|
|
47
|
-
router.post(
|
|
48
|
-
const {
|
|
49
|
-
projectId,
|
|
50
|
-
tag,
|
|
51
|
-
city,
|
|
52
|
-
url,
|
|
53
|
-
title,
|
|
54
|
-
description,
|
|
55
|
-
expiry
|
|
56
|
-
} = req.body;
|
|
57
|
-
if (!url || !title || !description || !expiry) {
|
|
58
|
-
return res.status(400).json({
|
|
59
|
-
success: false,
|
|
60
|
-
message: "All fields are required."
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
const slideData = {
|
|
64
|
-
projectId,
|
|
65
|
-
url,
|
|
66
|
-
title,
|
|
67
|
-
description,
|
|
68
|
-
expiry,
|
|
69
|
-
createdAt: new Date()
|
|
70
|
-
};
|
|
71
|
-
if (city) {
|
|
72
|
-
slideData.city = city;
|
|
73
|
-
}
|
|
74
|
-
if (tag) {
|
|
75
|
-
slideData.tag = tag;
|
|
76
|
-
}
|
|
37
|
+
// Create new slide
|
|
38
|
+
router.post("/", async (req, res) => {
|
|
77
39
|
try {
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
40
|
+
const {
|
|
41
|
+
tag,
|
|
42
|
+
city,
|
|
43
|
+
url,
|
|
44
|
+
title,
|
|
45
|
+
description,
|
|
46
|
+
expiry
|
|
47
|
+
} = req.body;
|
|
48
|
+
const projectId = req.projectId; // Use middleware-injected projectId
|
|
49
|
+
|
|
50
|
+
if (!url || !title) {
|
|
51
|
+
return res.status(400).json({
|
|
89
52
|
success: false,
|
|
90
|
-
message: "
|
|
53
|
+
message: "URL and title are required"
|
|
91
54
|
});
|
|
92
55
|
}
|
|
56
|
+
const slideData = {
|
|
57
|
+
projectId,
|
|
58
|
+
tag,
|
|
59
|
+
city,
|
|
60
|
+
url,
|
|
61
|
+
title,
|
|
62
|
+
description,
|
|
63
|
+
expiry,
|
|
64
|
+
createdAt: new Date()
|
|
65
|
+
};
|
|
66
|
+
const db = await getDb();
|
|
67
|
+
const result = await db.collection('slides').insertOne(slideData);
|
|
68
|
+
return res.status(201).json({
|
|
69
|
+
success: true,
|
|
70
|
+
message: "Slide created successfully",
|
|
71
|
+
id: result.insertedId
|
|
72
|
+
});
|
|
93
73
|
} catch (error) {
|
|
94
|
-
console.error("Error
|
|
74
|
+
console.error("Error creating slide:", error);
|
|
95
75
|
return res.status(500).json({
|
|
96
76
|
success: false,
|
|
97
|
-
message: "Failed to
|
|
77
|
+
message: "Failed to create slide."
|
|
98
78
|
});
|
|
99
79
|
}
|
|
100
80
|
});
|