powr-sdk-api 2.4.4 → 2.4.6
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/auth.js +18 -12
- package/dist/routes/invoice.js +8 -4
- package/dist/routes/likes.js +6 -3
- package/dist/routes/notifications.js +4 -2
- package/dist/routes/routes.js +8 -5
- package/package.json +1 -1
package/dist/routes/auth.js
CHANGED
|
@@ -55,7 +55,8 @@ router.post("/register", async (req, res) => {
|
|
|
55
55
|
}]
|
|
56
56
|
};
|
|
57
57
|
console.log(q);
|
|
58
|
-
const
|
|
58
|
+
const db = await getDb();
|
|
59
|
+
const existingUser = await db.collection("users").findOne(q);
|
|
59
60
|
if (existingUser) {
|
|
60
61
|
return res.status(400).json({
|
|
61
62
|
success: false,
|
|
@@ -72,7 +73,7 @@ router.post("/register", async (req, res) => {
|
|
|
72
73
|
password: hashedPassword,
|
|
73
74
|
createdAt: new Date()
|
|
74
75
|
};
|
|
75
|
-
const result = await
|
|
76
|
+
const result = await db.collection("users").insertOne(newUser);
|
|
76
77
|
if (projectId) {
|
|
77
78
|
const newProfile = {
|
|
78
79
|
userId: result.insertedId,
|
|
@@ -80,7 +81,7 @@ router.post("/register", async (req, res) => {
|
|
|
80
81
|
createdAt: new Date(),
|
|
81
82
|
updatedAt: new Date()
|
|
82
83
|
};
|
|
83
|
-
await
|
|
84
|
+
await db.collection("profiles").insertOne(newProfile);
|
|
84
85
|
}
|
|
85
86
|
return res.status(201).json({
|
|
86
87
|
success: true,
|
|
@@ -128,7 +129,8 @@ router.post("/login", async (req, res) => {
|
|
|
128
129
|
}]
|
|
129
130
|
};
|
|
130
131
|
console.log(q);
|
|
131
|
-
const
|
|
132
|
+
const db = await getDb();
|
|
133
|
+
const user = await db.collection("users").findOne(q);
|
|
132
134
|
console.log(user);
|
|
133
135
|
if (!user) {
|
|
134
136
|
return res.status(401).json({
|
|
@@ -147,13 +149,13 @@ router.post("/login", async (req, res) => {
|
|
|
147
149
|
// Fetch profile data if projectId is provided
|
|
148
150
|
let profile = null;
|
|
149
151
|
if (projectId) {
|
|
150
|
-
profile = await
|
|
152
|
+
profile = await db.collection("profiles").findOne({
|
|
151
153
|
userId: user._id,
|
|
152
154
|
projectId: projectId
|
|
153
155
|
});
|
|
154
156
|
if (profile) {
|
|
155
157
|
// Update lastActiveAt
|
|
156
|
-
await
|
|
158
|
+
await db.collection("profiles").updateOne({
|
|
157
159
|
_id: profile._id
|
|
158
160
|
}, {
|
|
159
161
|
$set: {
|
|
@@ -168,7 +170,7 @@ router.post("/login", async (req, res) => {
|
|
|
168
170
|
createdAt: new Date(),
|
|
169
171
|
updatedAt: new Date()
|
|
170
172
|
};
|
|
171
|
-
const profileResult = await
|
|
173
|
+
const profileResult = await db.collection("profiles").insertOne(newProfile);
|
|
172
174
|
profile = {
|
|
173
175
|
_id: profileResult.insertedId,
|
|
174
176
|
...newProfile
|
|
@@ -226,7 +228,8 @@ router.post("/forgot-password", async (req, res) => {
|
|
|
226
228
|
message: "Username is required"
|
|
227
229
|
});
|
|
228
230
|
}
|
|
229
|
-
const
|
|
231
|
+
const db = await getDb();
|
|
232
|
+
const user = await db.collection("users").findOne({
|
|
230
233
|
username: username
|
|
231
234
|
});
|
|
232
235
|
if (!user) {
|
|
@@ -243,7 +246,7 @@ router.post("/forgot-password", async (req, res) => {
|
|
|
243
246
|
exp: Math.floor(Date.now() / 1000) + 60 * 60
|
|
244
247
|
};
|
|
245
248
|
const resetToken = jwt.sign(resetPayload, config.jwtToken);
|
|
246
|
-
await
|
|
249
|
+
await db.collection("users").updateOne({
|
|
247
250
|
_id: user._id
|
|
248
251
|
}, {
|
|
249
252
|
$set: {
|
|
@@ -294,7 +297,8 @@ router.post("/reset-password", async (req, res) => {
|
|
|
294
297
|
message: "Invalid reset token type or missing user ID"
|
|
295
298
|
});
|
|
296
299
|
}
|
|
297
|
-
const
|
|
300
|
+
const db = await getDb();
|
|
301
|
+
const user = await db.collection("users").findOne({
|
|
298
302
|
_id: new ObjectId(decoded.userId),
|
|
299
303
|
resetToken: resetToken,
|
|
300
304
|
resetTokenExpiry: {
|
|
@@ -311,7 +315,9 @@ router.post("/reset-password", async (req, res) => {
|
|
|
311
315
|
// Hash the new password
|
|
312
316
|
const saltRounds = 10;
|
|
313
317
|
const hashedPassword = await bcrypt.hash(newPassword, saltRounds);
|
|
314
|
-
|
|
318
|
+
|
|
319
|
+
// Update user with new password and clear reset token
|
|
320
|
+
await db.collection("users").updateOne({
|
|
315
321
|
_id: user._id
|
|
316
322
|
}, {
|
|
317
323
|
$set: {
|
|
@@ -327,7 +333,7 @@ router.post("/reset-password", async (req, res) => {
|
|
|
327
333
|
message: "Password reset successfully"
|
|
328
334
|
});
|
|
329
335
|
} catch (error) {
|
|
330
|
-
console.error("Error
|
|
336
|
+
console.error("Error in reset password:", error);
|
|
331
337
|
return res.status(500).json({
|
|
332
338
|
success: false,
|
|
333
339
|
message: "Failed to reset password."
|
package/dist/routes/invoice.js
CHANGED
|
@@ -22,7 +22,8 @@ router.get('/', async (req, res) => {
|
|
|
22
22
|
message: 'projectId is required.'
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
-
const
|
|
25
|
+
const db = await getDb();
|
|
26
|
+
const invoiceData = await db.collection("invoices").find(query).toArray();
|
|
26
27
|
return res.status(200).json({
|
|
27
28
|
success: true,
|
|
28
29
|
invoices: invoiceData
|
|
@@ -50,7 +51,8 @@ router.get('/:invoiceId', async (req, res) => {
|
|
|
50
51
|
});
|
|
51
52
|
}
|
|
52
53
|
const _id = new ObjectId(invoiceId);
|
|
53
|
-
const
|
|
54
|
+
const db = await getDb();
|
|
55
|
+
const invoiceData = await db.collection("invoices").findOne({
|
|
54
56
|
_id,
|
|
55
57
|
projectId
|
|
56
58
|
});
|
|
@@ -95,7 +97,8 @@ router.post('/', async (req, res) => {
|
|
|
95
97
|
};
|
|
96
98
|
invoice.projectId = projectId;
|
|
97
99
|
try {
|
|
98
|
-
const
|
|
100
|
+
const db = await getDb();
|
|
101
|
+
const result = await db.collection("invoices").insertOne(invoice);
|
|
99
102
|
if (result && result.insertedId) {
|
|
100
103
|
return res.status(201).json({
|
|
101
104
|
success: true,
|
|
@@ -144,7 +147,8 @@ router.put('/:invoiceId', async (req, res) => {
|
|
|
144
147
|
}
|
|
145
148
|
const updateData = req.body;
|
|
146
149
|
try {
|
|
147
|
-
const
|
|
150
|
+
const db = await getDb();
|
|
151
|
+
const result = await db.collection("invoices").updateOne(filter, {
|
|
148
152
|
$set: updateData
|
|
149
153
|
});
|
|
150
154
|
return res.status(200).json({
|
package/dist/routes/likes.js
CHANGED
|
@@ -37,7 +37,8 @@ router.post('/', async (req, res) => {
|
|
|
37
37
|
query.contentId = contentId;
|
|
38
38
|
setObj.contentId = contentId;
|
|
39
39
|
}
|
|
40
|
-
const
|
|
40
|
+
const db = await getDb();
|
|
41
|
+
const response = await db.collection('likes').updateOne(query, {
|
|
41
42
|
$set: setObj
|
|
42
43
|
}, {
|
|
43
44
|
upsert: true
|
|
@@ -73,7 +74,8 @@ router.get('/', async (req, res) => {
|
|
|
73
74
|
if (contentId) {
|
|
74
75
|
query.contentId = contentId;
|
|
75
76
|
}
|
|
76
|
-
const
|
|
77
|
+
const db = await getDb();
|
|
78
|
+
const likes = await db.collection('likes').find(query).toArray();
|
|
77
79
|
const likesCount = likes.filter(like => like.liked === true).length;
|
|
78
80
|
const unlikesCount = likes.filter(like => like.liked === false).length;
|
|
79
81
|
return res.status(200).json({
|
|
@@ -104,7 +106,8 @@ router.get('/:likeId', async (req, res) => {
|
|
|
104
106
|
};
|
|
105
107
|
if (projectId) filter.projectId = projectId;
|
|
106
108
|
if (contentId) filter.contentId = contentId;
|
|
107
|
-
const
|
|
109
|
+
const db = await getDb();
|
|
110
|
+
const like = await db.collection('likes').findOne(filter);
|
|
108
111
|
if (!like) {
|
|
109
112
|
return res.status(404).json({
|
|
110
113
|
success: false,
|
|
@@ -17,7 +17,8 @@ router.get('/', async (req, res) => {
|
|
|
17
17
|
projectId
|
|
18
18
|
};
|
|
19
19
|
console.log("Filter.....:", query);
|
|
20
|
-
const
|
|
20
|
+
const db = await getDb();
|
|
21
|
+
const notificationData = await db.collection('notifications').find(query).toArray();
|
|
21
22
|
if (!notificationData || notificationData.length === 0) {
|
|
22
23
|
console.log("Data not found.");
|
|
23
24
|
return res.status(200).json({
|
|
@@ -64,7 +65,8 @@ router.post('/', async (req, res) => {
|
|
|
64
65
|
createdAt: new Date()
|
|
65
66
|
};
|
|
66
67
|
try {
|
|
67
|
-
const
|
|
68
|
+
const db = await getDb();
|
|
69
|
+
const result = await db.collection('notifications').insertOne(notificationData);
|
|
68
70
|
if (result && result.insertedId) {
|
|
69
71
|
console.log("Notification added with ID:", result.insertedId);
|
|
70
72
|
|
package/dist/routes/routes.js
CHANGED
|
@@ -21,7 +21,8 @@ router.get('/', async (req, res) => {
|
|
|
21
21
|
message: 'projectId is required.'
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
-
const
|
|
24
|
+
const db = await getDb();
|
|
25
|
+
const routesData = await db.collection("routes").find(query).toArray();
|
|
25
26
|
return res.status(200).json({
|
|
26
27
|
success: true,
|
|
27
28
|
allroutes: routesData
|
|
@@ -55,7 +56,8 @@ router.post('/', async (req, res) => {
|
|
|
55
56
|
message: 'Request body is empty or invalid.'
|
|
56
57
|
});
|
|
57
58
|
}
|
|
58
|
-
const
|
|
59
|
+
const db = await getDb();
|
|
60
|
+
const result = await db.collection('routes').insertOne(newRoute);
|
|
59
61
|
return res.status(201).json({
|
|
60
62
|
success: true,
|
|
61
63
|
entry: result.ops ? result.ops[0] : newRoute
|
|
@@ -97,14 +99,15 @@ router.put('/:route', async (req, res) => {
|
|
|
97
99
|
route,
|
|
98
100
|
projectId
|
|
99
101
|
};
|
|
100
|
-
const
|
|
102
|
+
const db = await getDb();
|
|
103
|
+
const existingRoute = await db.collection('routes').findOne(query);
|
|
101
104
|
if (!existingRoute) {
|
|
102
105
|
return res.status(404).json({
|
|
103
106
|
success: false,
|
|
104
107
|
message: 'Route not found.'
|
|
105
108
|
});
|
|
106
109
|
}
|
|
107
|
-
const result = await
|
|
110
|
+
const result = await db.collection('routes').updateOne(query, {
|
|
108
111
|
$set: {
|
|
109
112
|
code
|
|
110
113
|
}
|
|
@@ -115,7 +118,7 @@ router.put('/:route', async (req, res) => {
|
|
|
115
118
|
message: 'Route not found.'
|
|
116
119
|
});
|
|
117
120
|
}
|
|
118
|
-
const updatedRoute = await
|
|
121
|
+
const updatedRoute = await db.collection('routes').findOne(query);
|
|
119
122
|
return res.status(200).json({
|
|
120
123
|
success: true,
|
|
121
124
|
entry: updatedRoute
|