powr-sdk-api 2.5.2 → 2.5.3
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 +20 -7
- 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.projectId;
|
|
17
|
+
const projectId = req.query.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.projectId;
|
|
87
|
+
const projectId = req.query.projectId || req.projectId;
|
|
88
88
|
const db = await getDb();
|
|
89
89
|
|
|
90
90
|
// Verify user is part of conversation
|
|
@@ -141,10 +141,11 @@ router.post('/conversations/:conversationId/messages', async (req, res) => {
|
|
|
141
141
|
conversationId
|
|
142
142
|
} = req.params;
|
|
143
143
|
const {
|
|
144
|
-
content
|
|
144
|
+
content,
|
|
145
|
+
projectId: bodyProjectId
|
|
145
146
|
} = req.body;
|
|
146
147
|
const userId = req.user.powrId;
|
|
147
|
-
const projectId = req.projectId;
|
|
148
|
+
const projectId = bodyProjectId || req.projectId;
|
|
148
149
|
if (!content || content.trim() === '') {
|
|
149
150
|
return res.status(400).json({
|
|
150
151
|
success: false,
|
|
@@ -217,11 +218,12 @@ router.post('/conversations/:conversationId/messages', async (req, res) => {
|
|
|
217
218
|
router.post('/conversations', async (req, res) => {
|
|
218
219
|
try {
|
|
219
220
|
const {
|
|
220
|
-
participantId
|
|
221
|
+
participantId,
|
|
222
|
+
projectId: bodyProjectId
|
|
221
223
|
} = req.body;
|
|
222
224
|
const userId = req.user.powrId;
|
|
223
225
|
const userAccess = req.user.access;
|
|
224
|
-
const projectId = req.projectId;
|
|
226
|
+
const projectId = bodyProjectId || req.projectId;
|
|
225
227
|
if (!participantId) {
|
|
226
228
|
return res.status(400).json({
|
|
227
229
|
success: false,
|
|
@@ -308,7 +310,7 @@ router.get('/users', async (req, res) => {
|
|
|
308
310
|
try {
|
|
309
311
|
const userId = req.user.powrId;
|
|
310
312
|
const userAccess = req.user.access;
|
|
311
|
-
const projectId = req.projectId;
|
|
313
|
+
const projectId = req.query.projectId || req.projectId;
|
|
312
314
|
console.log('Current user access level:', userAccess, 'Project:', projectId);
|
|
313
315
|
const db = await getDb();
|
|
314
316
|
|
|
@@ -316,7 +318,18 @@ router.get('/users', async (req, res) => {
|
|
|
316
318
|
const projectUsers = await db.collection('profiles').find({
|
|
317
319
|
projectId: projectId
|
|
318
320
|
}).toArray();
|
|
321
|
+
console.log('Project users found:', projectUsers.length, 'for projectId:', projectId);
|
|
319
322
|
const userIds = projectUsers.map(profile => profile.userId);
|
|
323
|
+
console.log('User IDs extracted:', userIds);
|
|
324
|
+
|
|
325
|
+
// If no users found for this project, return empty array
|
|
326
|
+
if (userIds.length === 0) {
|
|
327
|
+
console.log('No users found for project:', projectId);
|
|
328
|
+
return res.json({
|
|
329
|
+
success: true,
|
|
330
|
+
data: []
|
|
331
|
+
});
|
|
332
|
+
}
|
|
320
333
|
let userQuery = {
|
|
321
334
|
_id: {
|
|
322
335
|
$in: userIds.map(id => new ObjectId(id))
|