powr-sdk-api 3.0.9 → 3.1.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/chat.js +3 -3
- package/dist/routes/forms.js +3 -7
- package/dist/routes/index.js +2 -2
- package/dist/routes/invoices.js +167 -0
- package/package.json +1 -1
package/dist/routes/chat.js
CHANGED
|
@@ -14,7 +14,7 @@ router.get('/conversations', async (req, res) => {
|
|
|
14
14
|
try {
|
|
15
15
|
const userId = req.user.powrId;
|
|
16
16
|
const userAccess = req.user.access;
|
|
17
|
-
const projectId = req.
|
|
17
|
+
const projectId = req.projectId;
|
|
18
18
|
console.log('Current user ID:', userId, 'Access:', userAccess, 'Project:', projectId);
|
|
19
19
|
const db = await getDb();
|
|
20
20
|
const conversations = await db.collection('conversations').find({
|
|
@@ -84,7 +84,7 @@ router.get('/conversations/:conversationId/messages', async (req, res) => {
|
|
|
84
84
|
conversationId
|
|
85
85
|
} = req.params;
|
|
86
86
|
const userId = req.user.powrId;
|
|
87
|
-
const projectId = req.
|
|
87
|
+
const projectId = req.projectId;
|
|
88
88
|
const db = await getDb();
|
|
89
89
|
|
|
90
90
|
// Verify user is part of conversation
|
|
@@ -310,7 +310,7 @@ router.get('/users', async (req, res) => {
|
|
|
310
310
|
try {
|
|
311
311
|
const userId = req.user.powrId;
|
|
312
312
|
const userAccess = req.user.access;
|
|
313
|
-
const projectId = req.
|
|
313
|
+
const projectId = req.projectId;
|
|
314
314
|
console.log('Current user access level:', userAccess, 'Project:', projectId);
|
|
315
315
|
const db = await getDb();
|
|
316
316
|
|
package/dist/routes/forms.js
CHANGED
|
@@ -140,19 +140,15 @@ router.get('/getCount/:formName', async (req, res) => {
|
|
|
140
140
|
const {
|
|
141
141
|
formName
|
|
142
142
|
} = req.params;
|
|
143
|
-
const
|
|
144
|
-
projectId
|
|
145
|
-
} = req.query;
|
|
143
|
+
const projectId = req.projectId;
|
|
146
144
|
const db = await getDb();
|
|
147
145
|
const studentsFormCollection = db.collection('studentsForm');
|
|
148
146
|
|
|
149
147
|
// Build query object
|
|
150
148
|
let query = {
|
|
151
|
-
formName
|
|
149
|
+
formName,
|
|
150
|
+
projectId
|
|
152
151
|
};
|
|
153
|
-
if (projectId) {
|
|
154
|
-
query.projectId = projectId;
|
|
155
|
-
}
|
|
156
152
|
const submissions = await studentsFormCollection.find(query).toArray();
|
|
157
153
|
res.status(200).json({
|
|
158
154
|
success: true,
|
package/dist/routes/index.js
CHANGED
|
@@ -13,7 +13,7 @@ const functionsManager = require('../services/functions');
|
|
|
13
13
|
const commentsRoutes = require('./comments');
|
|
14
14
|
const filesRoutes = require('./files');
|
|
15
15
|
const formsRoutes = require('./forms');
|
|
16
|
-
const
|
|
16
|
+
const invoicesRoutes = require('./invoices');
|
|
17
17
|
const likesRoutes = require('./likes');
|
|
18
18
|
const functionsRoutes = require('./functions');
|
|
19
19
|
const ratingsRoutes = require('./ratings');
|
|
@@ -36,7 +36,7 @@ const createPowrRoutes = (options = {}) => {
|
|
|
36
36
|
router.use('/comments', verifyToken, commentsRoutes);
|
|
37
37
|
router.use('/files', verifyToken, filesRoutes);
|
|
38
38
|
router.use('/forms', verifyToken, formsRoutes);
|
|
39
|
-
router.use('/
|
|
39
|
+
router.use('/invoices', verifyToken, invoicesRoutes);
|
|
40
40
|
router.use('/likes', verifyToken, likesRoutes);
|
|
41
41
|
router.use('/functions', verifyToken, functionsRoutes);
|
|
42
42
|
router.use('/ratings', verifyToken, ratingsRoutes);
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const express = require('express');
|
|
4
|
+
const router = express.Router();
|
|
5
|
+
const {
|
|
6
|
+
getDb
|
|
7
|
+
} = require("../services/mongo");
|
|
8
|
+
const {
|
|
9
|
+
ObjectId
|
|
10
|
+
} = require("mongodb");
|
|
11
|
+
router.get('/', async (req, res) => {
|
|
12
|
+
const {
|
|
13
|
+
projectId
|
|
14
|
+
} = req.query;
|
|
15
|
+
try {
|
|
16
|
+
const query = {
|
|
17
|
+
projectId
|
|
18
|
+
};
|
|
19
|
+
if (!projectId) {
|
|
20
|
+
return res.status(400).json({
|
|
21
|
+
success: false,
|
|
22
|
+
message: 'projectId is required.'
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const db = await getDb();
|
|
26
|
+
const invoiceData = await db.collection("invoices").find(query).toArray();
|
|
27
|
+
return res.status(200).json({
|
|
28
|
+
success: true,
|
|
29
|
+
invoices: invoiceData
|
|
30
|
+
});
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error("Error retrieving invoices :", error);
|
|
33
|
+
return res.status(500).json({
|
|
34
|
+
success: false,
|
|
35
|
+
message: "Failed to retrieve invoices ."
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
router.get('/:invoiceId', async (req, res) => {
|
|
40
|
+
const {
|
|
41
|
+
invoiceId
|
|
42
|
+
} = req.params;
|
|
43
|
+
const {
|
|
44
|
+
projectId
|
|
45
|
+
} = req.query;
|
|
46
|
+
try {
|
|
47
|
+
if (!projectId) {
|
|
48
|
+
return res.status(400).json({
|
|
49
|
+
success: false,
|
|
50
|
+
message: 'projectId is required.'
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const _id = new ObjectId(invoiceId);
|
|
54
|
+
const db = await getDb();
|
|
55
|
+
const invoiceData = await db.collection("invoices").findOne({
|
|
56
|
+
_id,
|
|
57
|
+
projectId
|
|
58
|
+
});
|
|
59
|
+
return res.status(200).json({
|
|
60
|
+
success: true,
|
|
61
|
+
invoice: invoiceData
|
|
62
|
+
});
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.error("Error retrieving invoice :", error);
|
|
65
|
+
return res.status(500).json({
|
|
66
|
+
success: false,
|
|
67
|
+
message: "Failed to retrieve invoice."
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
router.post('/', async (req, res) => {
|
|
72
|
+
const {
|
|
73
|
+
projectId
|
|
74
|
+
} = req.query;
|
|
75
|
+
const {
|
|
76
|
+
invoiceNumber,
|
|
77
|
+
dateOfIssue,
|
|
78
|
+
paymentStatus,
|
|
79
|
+
customerInfo,
|
|
80
|
+
serviceSection,
|
|
81
|
+
paymentSection
|
|
82
|
+
} = req.body;
|
|
83
|
+
if (!projectId) {
|
|
84
|
+
return res.status(400).json({
|
|
85
|
+
success: false,
|
|
86
|
+
message: "projectId is required."
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
const invoice = {
|
|
90
|
+
invoiceNumber,
|
|
91
|
+
dateOfIssue,
|
|
92
|
+
paymentStatus,
|
|
93
|
+
customerInfo,
|
|
94
|
+
serviceSection,
|
|
95
|
+
paymentSection,
|
|
96
|
+
createdAt: new Date()
|
|
97
|
+
};
|
|
98
|
+
invoice.projectId = projectId;
|
|
99
|
+
try {
|
|
100
|
+
const db = await getDb();
|
|
101
|
+
const result = await db.collection("invoices").insertOne(invoice);
|
|
102
|
+
if (result && result.insertedId) {
|
|
103
|
+
return res.status(201).json({
|
|
104
|
+
success: true,
|
|
105
|
+
message: "Invoice created successfully.",
|
|
106
|
+
invoiceId: result.insertedId,
|
|
107
|
+
invoice
|
|
108
|
+
});
|
|
109
|
+
} else {
|
|
110
|
+
return res.status(500).json({
|
|
111
|
+
success: false,
|
|
112
|
+
message: "Invoice could not be added."
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
} catch (error) {
|
|
116
|
+
console.error("Error adding invoice:", error);
|
|
117
|
+
return res.status(500).json({
|
|
118
|
+
success: false,
|
|
119
|
+
message: "Failed to add invoice due to a server error."
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
router.put('/:invoiceId', async (req, res) => {
|
|
124
|
+
const {
|
|
125
|
+
invoiceId
|
|
126
|
+
} = req.params;
|
|
127
|
+
const {
|
|
128
|
+
projectId
|
|
129
|
+
} = req.query;
|
|
130
|
+
if (!projectId) {
|
|
131
|
+
return res.status(400).json({
|
|
132
|
+
success: false,
|
|
133
|
+
message: "projectId is required."
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
let filter;
|
|
137
|
+
try {
|
|
138
|
+
filter = {
|
|
139
|
+
_id: new ObjectId(invoiceId),
|
|
140
|
+
projectId: projectId
|
|
141
|
+
};
|
|
142
|
+
} catch (e) {
|
|
143
|
+
return res.status(400).json({
|
|
144
|
+
success: false,
|
|
145
|
+
message: "Invalid invoiceId format."
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
const updateData = req.body;
|
|
149
|
+
try {
|
|
150
|
+
const db = await getDb();
|
|
151
|
+
const result = await db.collection("invoices").updateOne(filter, {
|
|
152
|
+
$set: updateData
|
|
153
|
+
});
|
|
154
|
+
return res.status(200).json({
|
|
155
|
+
success: true,
|
|
156
|
+
message: "Invoice updated successfully.",
|
|
157
|
+
result: result
|
|
158
|
+
});
|
|
159
|
+
} catch (error) {
|
|
160
|
+
console.error("Error updating invoice:", error);
|
|
161
|
+
return res.status(500).json({
|
|
162
|
+
success: false,
|
|
163
|
+
message: "Failed to update invoice due to a server error."
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
module.exports = router;
|