powr-sdk-api 4.3.13 → 4.4.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/routes/forms.js +8 -5
- package/dist/routes/index.js +1 -1
- package/package.json +9 -7
- 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/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/services/dbService.js +0 -42
- package/dist/services/functions.js +0 -229
- package/dist/services/plexx.js +0 -229
package/dist/admin/waitlists.js
DELETED
|
@@ -1,94 +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 waitlist entries
|
|
10
|
-
router.get('/', async (req, res) => {
|
|
11
|
-
const {
|
|
12
|
-
projectId
|
|
13
|
-
} = req.query;
|
|
14
|
-
try {
|
|
15
|
-
const query = {
|
|
16
|
-
projectId
|
|
17
|
-
};
|
|
18
|
-
console.log("Filter.....:", query);
|
|
19
|
-
const waitlistData = await getDb().collection("waitlists").find(query).toArray();
|
|
20
|
-
if (!waitlistData || waitlistData.length === 0) {
|
|
21
|
-
console.log("Data not found.");
|
|
22
|
-
return res.status(200).json({
|
|
23
|
-
success: true,
|
|
24
|
-
entries: []
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
const sortedData = waitlistData.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));
|
|
28
|
-
console.log("Waitlist entries retrieved and sorted:", sortedData);
|
|
29
|
-
return res.status(200).json({
|
|
30
|
-
success: true,
|
|
31
|
-
entries: sortedData
|
|
32
|
-
});
|
|
33
|
-
} catch (error) {
|
|
34
|
-
console.error("Error retrieving waitlist entries:", error);
|
|
35
|
-
return res.status(500).json({
|
|
36
|
-
success: false,
|
|
37
|
-
message: "Failed to retrieve waitlist entries."
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// Original POST endpoint for adding to waitlist
|
|
43
|
-
router.post("/", async (req, res) => {
|
|
44
|
-
const {
|
|
45
|
-
projectId,
|
|
46
|
-
email
|
|
47
|
-
} = req.body;
|
|
48
|
-
try {
|
|
49
|
-
const existingEntry = await getDb().collection("waitlists").findOne({
|
|
50
|
-
projectId,
|
|
51
|
-
email
|
|
52
|
-
});
|
|
53
|
-
if (existingEntry) {
|
|
54
|
-
return res.status(400).json({
|
|
55
|
-
success: false,
|
|
56
|
-
message: "You are already in the waitlist "
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
} catch (error) {
|
|
60
|
-
console.error("Error checking waitlist:", error);
|
|
61
|
-
return res.status(500).json({
|
|
62
|
-
success: false,
|
|
63
|
-
message: "Failed to check waitlist due to a server error."
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
const waitListData = {
|
|
67
|
-
projectId,
|
|
68
|
-
email,
|
|
69
|
-
createdAt: new Date()
|
|
70
|
-
};
|
|
71
|
-
try {
|
|
72
|
-
const result = await getDb().collection("waitlists").insertOne(waitListData);
|
|
73
|
-
if (result && result.insertedId) {
|
|
74
|
-
return res.status(200).json({
|
|
75
|
-
success: true,
|
|
76
|
-
message: "you are added in the waitist",
|
|
77
|
-
userId: result.insertedId
|
|
78
|
-
});
|
|
79
|
-
} else {
|
|
80
|
-
console.error("Insert operation failed. Result:", result);
|
|
81
|
-
return res.status(500).json({
|
|
82
|
-
success: false,
|
|
83
|
-
message: "user could not be added."
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
} catch (error) {
|
|
87
|
-
console.error("Error adding user:", error);
|
|
88
|
-
return res.status(500).json({
|
|
89
|
-
success: false,
|
|
90
|
-
message: "Failed to add user due to a server error."
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
module.exports = router;
|
|
@@ -1,520 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// Admin routes for powr-sdk-api
|
|
4
|
-
// This file contains the admin route handlers for common admin operations
|
|
5
|
-
|
|
6
|
-
const {
|
|
7
|
-
MongoClient
|
|
8
|
-
} = require('mongodb');
|
|
9
|
-
const createAdminRoutes = (app, options = {}) => {
|
|
10
|
-
const {
|
|
11
|
-
projectId,
|
|
12
|
-
apiUrl = '/admin',
|
|
13
|
-
authMiddleware = null,
|
|
14
|
-
logger = console,
|
|
15
|
-
mongoUrl = process.env.MONGODB_URI || 'mongodb://localhost:27017/powrbase'
|
|
16
|
-
} = options;
|
|
17
|
-
let db;
|
|
18
|
-
|
|
19
|
-
// Connect to MongoDB
|
|
20
|
-
const connectDB = async () => {
|
|
21
|
-
try {
|
|
22
|
-
const client = new MongoClient(mongoUrl);
|
|
23
|
-
await client.connect();
|
|
24
|
-
db = client.db();
|
|
25
|
-
logger.info('Connected to MongoDB');
|
|
26
|
-
} catch (error) {
|
|
27
|
-
logger.error('MongoDB connection error:', error);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// Initialize database connection
|
|
32
|
-
connectDB();
|
|
33
|
-
|
|
34
|
-
// Forms Admin Routes
|
|
35
|
-
app.get(`${apiUrl}/forms`, async (req, res) => {
|
|
36
|
-
try {
|
|
37
|
-
const forms = await db.collection('forms').find({
|
|
38
|
-
projectId
|
|
39
|
-
}).toArray();
|
|
40
|
-
res.json({
|
|
41
|
-
success: true,
|
|
42
|
-
forms
|
|
43
|
-
});
|
|
44
|
-
} catch (error) {
|
|
45
|
-
logger.error('Error fetching forms:', error);
|
|
46
|
-
res.status(500).json({
|
|
47
|
-
success: false,
|
|
48
|
-
error: 'Failed to fetch forms'
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
app.post(`${apiUrl}/forms`, async (req, res) => {
|
|
53
|
-
try {
|
|
54
|
-
const {
|
|
55
|
-
name,
|
|
56
|
-
fields,
|
|
57
|
-
settings
|
|
58
|
-
} = req.body;
|
|
59
|
-
const form = {
|
|
60
|
-
projectId,
|
|
61
|
-
name,
|
|
62
|
-
fields,
|
|
63
|
-
settings,
|
|
64
|
-
createdAt: new Date(),
|
|
65
|
-
updatedAt: new Date()
|
|
66
|
-
};
|
|
67
|
-
const result = await db.collection('forms').insertOne(form);
|
|
68
|
-
res.json({
|
|
69
|
-
success: true,
|
|
70
|
-
form: {
|
|
71
|
-
...form,
|
|
72
|
-
_id: result.insertedId
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
} catch (error) {
|
|
76
|
-
logger.error('Error creating form:', error);
|
|
77
|
-
res.status(500).json({
|
|
78
|
-
success: false,
|
|
79
|
-
error: 'Failed to create form'
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
app.put(`${apiUrl}/forms/:id`, async (req, res) => {
|
|
84
|
-
try {
|
|
85
|
-
const {
|
|
86
|
-
id
|
|
87
|
-
} = req.params;
|
|
88
|
-
const {
|
|
89
|
-
name,
|
|
90
|
-
fields,
|
|
91
|
-
settings
|
|
92
|
-
} = req.body;
|
|
93
|
-
const result = await db.collection('forms').updateOne({
|
|
94
|
-
_id: id,
|
|
95
|
-
projectId
|
|
96
|
-
}, {
|
|
97
|
-
$set: {
|
|
98
|
-
name,
|
|
99
|
-
fields,
|
|
100
|
-
settings,
|
|
101
|
-
updatedAt: new Date()
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
if (result.matchedCount === 0) {
|
|
105
|
-
return res.status(404).json({
|
|
106
|
-
success: false,
|
|
107
|
-
error: 'Form not found'
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
res.json({
|
|
111
|
-
success: true,
|
|
112
|
-
message: 'Form updated successfully'
|
|
113
|
-
});
|
|
114
|
-
} catch (error) {
|
|
115
|
-
logger.error('Error updating form:', error);
|
|
116
|
-
res.status(500).json({
|
|
117
|
-
success: false,
|
|
118
|
-
error: 'Failed to update form'
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
app.delete(`${apiUrl}/forms/:id`, async (req, res) => {
|
|
123
|
-
try {
|
|
124
|
-
const {
|
|
125
|
-
id
|
|
126
|
-
} = req.params;
|
|
127
|
-
const result = await db.collection('forms').deleteOne({
|
|
128
|
-
_id: id,
|
|
129
|
-
projectId
|
|
130
|
-
});
|
|
131
|
-
if (result.deletedCount === 0) {
|
|
132
|
-
return res.status(404).json({
|
|
133
|
-
success: false,
|
|
134
|
-
error: 'Form not found'
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
res.json({
|
|
138
|
-
success: true,
|
|
139
|
-
message: 'Form deleted successfully'
|
|
140
|
-
});
|
|
141
|
-
} catch (error) {
|
|
142
|
-
logger.error('Error deleting form:', error);
|
|
143
|
-
res.status(500).json({
|
|
144
|
-
success: false,
|
|
145
|
-
error: 'Failed to delete form'
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
// Waitlists Admin Routes
|
|
151
|
-
app.get(`${apiUrl}/waitlists`, async (req, res) => {
|
|
152
|
-
try {
|
|
153
|
-
const waitlists = await db.collection('waitlists').find({
|
|
154
|
-
projectId
|
|
155
|
-
}).toArray();
|
|
156
|
-
res.json({
|
|
157
|
-
success: true,
|
|
158
|
-
waitlists
|
|
159
|
-
});
|
|
160
|
-
} catch (error) {
|
|
161
|
-
logger.error('Error fetching waitlists:', error);
|
|
162
|
-
res.status(500).json({
|
|
163
|
-
success: false,
|
|
164
|
-
error: 'Failed to fetch waitlists'
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
app.post(`${apiUrl}/waitlists`, async (req, res) => {
|
|
169
|
-
try {
|
|
170
|
-
const {
|
|
171
|
-
email,
|
|
172
|
-
name,
|
|
173
|
-
phone,
|
|
174
|
-
additionalInfo
|
|
175
|
-
} = req.body;
|
|
176
|
-
const entry = {
|
|
177
|
-
projectId,
|
|
178
|
-
email,
|
|
179
|
-
name,
|
|
180
|
-
phone,
|
|
181
|
-
additionalInfo,
|
|
182
|
-
createdAt: new Date()
|
|
183
|
-
};
|
|
184
|
-
const result = await db.collection('waitlists').insertOne(entry);
|
|
185
|
-
res.json({
|
|
186
|
-
success: true,
|
|
187
|
-
entry: {
|
|
188
|
-
...entry,
|
|
189
|
-
_id: result.insertedId
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
} catch (error) {
|
|
193
|
-
logger.error('Error adding waitlist entry:', error);
|
|
194
|
-
res.status(500).json({
|
|
195
|
-
success: false,
|
|
196
|
-
error: 'Failed to add entry'
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
// Slides Admin Routes
|
|
202
|
-
app.get(`${apiUrl}/slides`, async (req, res) => {
|
|
203
|
-
try {
|
|
204
|
-
const slides = await db.collection('slides').find({
|
|
205
|
-
projectId
|
|
206
|
-
}).toArray();
|
|
207
|
-
res.json({
|
|
208
|
-
success: true,
|
|
209
|
-
slides
|
|
210
|
-
});
|
|
211
|
-
} catch (error) {
|
|
212
|
-
logger.error('Error fetching slides:', error);
|
|
213
|
-
res.status(500).json({
|
|
214
|
-
success: false,
|
|
215
|
-
error: 'Failed to fetch slides'
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
app.post(`${apiUrl}/slides`, async (req, res) => {
|
|
220
|
-
try {
|
|
221
|
-
const {
|
|
222
|
-
title,
|
|
223
|
-
description,
|
|
224
|
-
imageUrl,
|
|
225
|
-
link,
|
|
226
|
-
order
|
|
227
|
-
} = req.body;
|
|
228
|
-
const slide = {
|
|
229
|
-
projectId,
|
|
230
|
-
title,
|
|
231
|
-
description,
|
|
232
|
-
imageUrl,
|
|
233
|
-
link,
|
|
234
|
-
order: order || 0,
|
|
235
|
-
createdAt: new Date(),
|
|
236
|
-
updatedAt: new Date()
|
|
237
|
-
};
|
|
238
|
-
const result = await db.collection('slides').insertOne(slide);
|
|
239
|
-
res.json({
|
|
240
|
-
success: true,
|
|
241
|
-
slide: {
|
|
242
|
-
...slide,
|
|
243
|
-
_id: result.insertedId
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
} catch (error) {
|
|
247
|
-
logger.error('Error creating slide:', error);
|
|
248
|
-
res.status(500).json({
|
|
249
|
-
success: false,
|
|
250
|
-
error: 'Failed to create slide'
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
app.put(`${apiUrl}/slides/:id`, async (req, res) => {
|
|
255
|
-
try {
|
|
256
|
-
const {
|
|
257
|
-
id
|
|
258
|
-
} = req.params;
|
|
259
|
-
const {
|
|
260
|
-
title,
|
|
261
|
-
description,
|
|
262
|
-
imageUrl,
|
|
263
|
-
link,
|
|
264
|
-
order
|
|
265
|
-
} = req.body;
|
|
266
|
-
const result = await db.collection('slides').updateOne({
|
|
267
|
-
_id: id,
|
|
268
|
-
projectId
|
|
269
|
-
}, {
|
|
270
|
-
$set: {
|
|
271
|
-
title,
|
|
272
|
-
description,
|
|
273
|
-
imageUrl,
|
|
274
|
-
link,
|
|
275
|
-
order,
|
|
276
|
-
updatedAt: new Date()
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
if (result.matchedCount === 0) {
|
|
280
|
-
return res.status(404).json({
|
|
281
|
-
success: false,
|
|
282
|
-
error: 'Slide not found'
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
res.json({
|
|
286
|
-
success: true,
|
|
287
|
-
message: 'Slide updated successfully'
|
|
288
|
-
});
|
|
289
|
-
} catch (error) {
|
|
290
|
-
logger.error('Error updating slide:', error);
|
|
291
|
-
res.status(500).json({
|
|
292
|
-
success: false,
|
|
293
|
-
error: 'Failed to update slide'
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
app.delete(`${apiUrl}/slides/:id`, async (req, res) => {
|
|
298
|
-
try {
|
|
299
|
-
const {
|
|
300
|
-
id
|
|
301
|
-
} = req.params;
|
|
302
|
-
const result = await db.collection('slides').deleteOne({
|
|
303
|
-
_id: id,
|
|
304
|
-
projectId
|
|
305
|
-
});
|
|
306
|
-
if (result.deletedCount === 0) {
|
|
307
|
-
return res.status(404).json({
|
|
308
|
-
success: false,
|
|
309
|
-
error: 'Slide not found'
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
res.json({
|
|
313
|
-
success: true,
|
|
314
|
-
message: 'Slide deleted successfully'
|
|
315
|
-
});
|
|
316
|
-
} catch (error) {
|
|
317
|
-
logger.error('Error deleting slide:', error);
|
|
318
|
-
res.status(500).json({
|
|
319
|
-
success: false,
|
|
320
|
-
error: 'Failed to delete slide'
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
// Invoices Admin Routes
|
|
326
|
-
app.get(`${apiUrl}/invoices`, async (req, res) => {
|
|
327
|
-
try {
|
|
328
|
-
const invoices = await db.collection('invoices').find({
|
|
329
|
-
projectId
|
|
330
|
-
}).toArray();
|
|
331
|
-
res.json({
|
|
332
|
-
success: true,
|
|
333
|
-
invoices
|
|
334
|
-
});
|
|
335
|
-
} catch (error) {
|
|
336
|
-
logger.error('Error fetching invoices:', error);
|
|
337
|
-
res.status(500).json({
|
|
338
|
-
success: false,
|
|
339
|
-
error: 'Failed to fetch invoices'
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
app.post(`${apiUrl}/invoices`, async (req, res) => {
|
|
344
|
-
try {
|
|
345
|
-
const {
|
|
346
|
-
invoiceNumber,
|
|
347
|
-
clientName,
|
|
348
|
-
clientEmail,
|
|
349
|
-
amount,
|
|
350
|
-
description,
|
|
351
|
-
dueDate,
|
|
352
|
-
status = 'pending'
|
|
353
|
-
} = req.body;
|
|
354
|
-
const invoice = {
|
|
355
|
-
projectId,
|
|
356
|
-
invoiceNumber,
|
|
357
|
-
clientName,
|
|
358
|
-
clientEmail,
|
|
359
|
-
amount,
|
|
360
|
-
description,
|
|
361
|
-
dueDate: new Date(dueDate),
|
|
362
|
-
status,
|
|
363
|
-
createdAt: new Date(),
|
|
364
|
-
updatedAt: new Date()
|
|
365
|
-
};
|
|
366
|
-
const result = await db.collection('invoices').insertOne(invoice);
|
|
367
|
-
res.json({
|
|
368
|
-
success: true,
|
|
369
|
-
invoice: {
|
|
370
|
-
...invoice,
|
|
371
|
-
_id: result.insertedId
|
|
372
|
-
}
|
|
373
|
-
});
|
|
374
|
-
} catch (error) {
|
|
375
|
-
logger.error('Error creating invoice:', error);
|
|
376
|
-
res.status(500).json({
|
|
377
|
-
success: false,
|
|
378
|
-
error: 'Failed to create invoice'
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
});
|
|
382
|
-
app.put(`${apiUrl}/invoices/:id`, async (req, res) => {
|
|
383
|
-
try {
|
|
384
|
-
const {
|
|
385
|
-
id
|
|
386
|
-
} = req.params;
|
|
387
|
-
const {
|
|
388
|
-
invoiceNumber,
|
|
389
|
-
clientName,
|
|
390
|
-
clientEmail,
|
|
391
|
-
amount,
|
|
392
|
-
description,
|
|
393
|
-
dueDate,
|
|
394
|
-
status
|
|
395
|
-
} = req.body;
|
|
396
|
-
const result = await db.collection('invoices').updateOne({
|
|
397
|
-
_id: id,
|
|
398
|
-
projectId
|
|
399
|
-
}, {
|
|
400
|
-
$set: {
|
|
401
|
-
invoiceNumber,
|
|
402
|
-
clientName,
|
|
403
|
-
clientEmail,
|
|
404
|
-
amount,
|
|
405
|
-
description,
|
|
406
|
-
dueDate: new Date(dueDate),
|
|
407
|
-
status,
|
|
408
|
-
updatedAt: new Date()
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
|
-
if (result.matchedCount === 0) {
|
|
412
|
-
return res.status(404).json({
|
|
413
|
-
success: false,
|
|
414
|
-
error: 'Invoice not found'
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
res.json({
|
|
418
|
-
success: true,
|
|
419
|
-
message: 'Invoice updated successfully'
|
|
420
|
-
});
|
|
421
|
-
} catch (error) {
|
|
422
|
-
logger.error('Error updating invoice:', error);
|
|
423
|
-
res.status(500).json({
|
|
424
|
-
success: false,
|
|
425
|
-
error: 'Failed to update invoice'
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
// Notifications Admin Routes
|
|
431
|
-
app.get(`${apiUrl}/notifications`, async (req, res) => {
|
|
432
|
-
try {
|
|
433
|
-
const notifications = await db.collection('notifications').find({
|
|
434
|
-
projectId
|
|
435
|
-
}).toArray();
|
|
436
|
-
res.json({
|
|
437
|
-
success: true,
|
|
438
|
-
notifications
|
|
439
|
-
});
|
|
440
|
-
} catch (error) {
|
|
441
|
-
logger.error('Error fetching notifications:', error);
|
|
442
|
-
res.status(500).json({
|
|
443
|
-
success: false,
|
|
444
|
-
error: 'Failed to fetch notifications'
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
});
|
|
448
|
-
app.post(`${apiUrl}/notifications`, async (req, res) => {
|
|
449
|
-
try {
|
|
450
|
-
const {
|
|
451
|
-
title,
|
|
452
|
-
message,
|
|
453
|
-
type = 'info',
|
|
454
|
-
priority = 'normal',
|
|
455
|
-
targetUsers = 'all'
|
|
456
|
-
} = req.body;
|
|
457
|
-
const notification = {
|
|
458
|
-
projectId,
|
|
459
|
-
title,
|
|
460
|
-
message,
|
|
461
|
-
type,
|
|
462
|
-
priority,
|
|
463
|
-
targetUsers,
|
|
464
|
-
isRead: false,
|
|
465
|
-
createdAt: new Date()
|
|
466
|
-
};
|
|
467
|
-
const result = await db.collection('notifications').insertOne(notification);
|
|
468
|
-
res.json({
|
|
469
|
-
success: true,
|
|
470
|
-
notification: {
|
|
471
|
-
...notification,
|
|
472
|
-
_id: result.insertedId
|
|
473
|
-
}
|
|
474
|
-
});
|
|
475
|
-
} catch (error) {
|
|
476
|
-
logger.error('Error creating notification:', error);
|
|
477
|
-
res.status(500).json({
|
|
478
|
-
success: false,
|
|
479
|
-
error: 'Failed to create notification'
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
});
|
|
483
|
-
app.put(`${apiUrl}/notifications/:id/read`, async (req, res) => {
|
|
484
|
-
try {
|
|
485
|
-
const {
|
|
486
|
-
id
|
|
487
|
-
} = req.params;
|
|
488
|
-
const result = await db.collection('notifications').updateOne({
|
|
489
|
-
_id: id,
|
|
490
|
-
projectId
|
|
491
|
-
}, {
|
|
492
|
-
$set: {
|
|
493
|
-
isRead: true,
|
|
494
|
-
updatedAt: new Date()
|
|
495
|
-
}
|
|
496
|
-
});
|
|
497
|
-
if (result.matchedCount === 0) {
|
|
498
|
-
return res.status(404).json({
|
|
499
|
-
success: false,
|
|
500
|
-
error: 'Notification not found'
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
|
-
res.json({
|
|
504
|
-
success: true,
|
|
505
|
-
message: 'Notification marked as read'
|
|
506
|
-
});
|
|
507
|
-
} catch (error) {
|
|
508
|
-
logger.error('Error updating notification:', error);
|
|
509
|
-
res.status(500).json({
|
|
510
|
-
success: false,
|
|
511
|
-
error: 'Failed to update notification'
|
|
512
|
-
});
|
|
513
|
-
}
|
|
514
|
-
});
|
|
515
|
-
logger.info('Admin routes initialized for project:', projectId);
|
|
516
|
-
return app;
|
|
517
|
-
};
|
|
518
|
-
module.exports = {
|
|
519
|
-
createAdminRoutes
|
|
520
|
-
};
|
package/dist/routes/blogs.js
DELETED
|
@@ -1,94 +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
|
-
router.post('/', async (req, res) => {
|
|
9
|
-
const {
|
|
10
|
-
projectId
|
|
11
|
-
} = req.query;
|
|
12
|
-
const {
|
|
13
|
-
title,
|
|
14
|
-
author,
|
|
15
|
-
date,
|
|
16
|
-
description,
|
|
17
|
-
tags,
|
|
18
|
-
imageUrl
|
|
19
|
-
} = req.body;
|
|
20
|
-
if (!projectId || !title || !author || !date || !description) {
|
|
21
|
-
return res.status(400).json({
|
|
22
|
-
success: false,
|
|
23
|
-
message: 'projectId, title, author, date,and description are required.'
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
const blog = {
|
|
27
|
-
title,
|
|
28
|
-
author,
|
|
29
|
-
date,
|
|
30
|
-
description,
|
|
31
|
-
tags: tags || '',
|
|
32
|
-
imageUrl,
|
|
33
|
-
projectId,
|
|
34
|
-
createdAt: new Date()
|
|
35
|
-
};
|
|
36
|
-
try {
|
|
37
|
-
const result = await getDb().collection('blogs').insertOne(blog);
|
|
38
|
-
if (result && result.insertedId) {
|
|
39
|
-
return res.status(201).json({
|
|
40
|
-
success: true,
|
|
41
|
-
message: 'Blog created successfully.',
|
|
42
|
-
blogId: result.insertedId,
|
|
43
|
-
blog
|
|
44
|
-
});
|
|
45
|
-
} else {
|
|
46
|
-
return res.status(500).json({
|
|
47
|
-
success: false,
|
|
48
|
-
message: 'Blog could not be created.'
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
} catch (error) {
|
|
52
|
-
console.error('Error while creating blog:', error);
|
|
53
|
-
return res.status(500).json({
|
|
54
|
-
success: false,
|
|
55
|
-
message: 'Failed to create blog due to a server error.'
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
router.get('/', async (req, res) => {
|
|
60
|
-
const {
|
|
61
|
-
projectId,
|
|
62
|
-
contentId,
|
|
63
|
-
userId
|
|
64
|
-
} = req.query;
|
|
65
|
-
if (!projectId) {
|
|
66
|
-
return res.status(400).json({
|
|
67
|
-
success: false,
|
|
68
|
-
message: 'projectId is required in query.'
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
try {
|
|
72
|
-
const query = {
|
|
73
|
-
projectId
|
|
74
|
-
};
|
|
75
|
-
if (contentId) {
|
|
76
|
-
query.contentId = contentId;
|
|
77
|
-
}
|
|
78
|
-
if (userId) {
|
|
79
|
-
query.author = userId;
|
|
80
|
-
}
|
|
81
|
-
const blogs = await getDb().collection('blogs').find(query).toArray();
|
|
82
|
-
return res.status(200).json({
|
|
83
|
-
success: true,
|
|
84
|
-
blogs: blogs
|
|
85
|
-
});
|
|
86
|
-
} catch (error) {
|
|
87
|
-
console.error('Error fetching blogs:', error);
|
|
88
|
-
return res.status(500).json({
|
|
89
|
-
success: false,
|
|
90
|
-
message: 'Failed to fetch blogs.'
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
module.exports = router;
|