powr-sdk-api 4.7.0 → 4.7.2
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 +8 -7
- package/dist/routes/comments.js +130 -5
- package/package.json +1 -1
package/dist/routes/chat.js
CHANGED
|
@@ -17,9 +17,9 @@ router.get('/conversations', async (req, res) => {
|
|
|
17
17
|
const projectId = req.projectId;
|
|
18
18
|
console.log('Current user ID:', userId, 'Access:', userAccess, 'Project:', projectId);
|
|
19
19
|
const db = await getDb();
|
|
20
|
+
// Show all conversations user is in (1:1 DMs and groups, any project)
|
|
20
21
|
const conversations = await db.collection('conversations').find({
|
|
21
|
-
participants: userId
|
|
22
|
-
projectId: projectId
|
|
22
|
+
participants: userId
|
|
23
23
|
}).toArray();
|
|
24
24
|
|
|
25
25
|
// Build response for each conversation
|
|
@@ -97,11 +97,13 @@ router.get('/conversations/:conversationId/messages', async (req, res) => {
|
|
|
97
97
|
// Verify user is part of conversation
|
|
98
98
|
const conversation = await db.collection('conversations').findOne({
|
|
99
99
|
_id: new ObjectId(conversationId),
|
|
100
|
-
participants: userId
|
|
101
|
-
projectId: projectId
|
|
100
|
+
participants: userId
|
|
102
101
|
});
|
|
103
102
|
if (!conversation) {
|
|
104
|
-
return res.
|
|
103
|
+
return res.status(404).json({
|
|
104
|
+
success: false,
|
|
105
|
+
message: 'Conversation not found'
|
|
106
|
+
});
|
|
105
107
|
}
|
|
106
108
|
const messages = await db.collection('messages').find({
|
|
107
109
|
conversationId: conversationId
|
|
@@ -164,8 +166,7 @@ router.post('/conversations/:conversationId/messages', async (req, res) => {
|
|
|
164
166
|
// Verify user is part of conversation
|
|
165
167
|
const conversation = await db.collection('conversations').findOne({
|
|
166
168
|
_id: new ObjectId(conversationId),
|
|
167
|
-
participants: userId
|
|
168
|
-
projectId: projectId
|
|
169
|
+
participants: userId
|
|
169
170
|
});
|
|
170
171
|
if (!conversation) {
|
|
171
172
|
return res.status(404).json({
|
package/dist/routes/comments.js
CHANGED
|
@@ -41,24 +41,37 @@ router.get("/", async (req, res) => {
|
|
|
41
41
|
// Create new comment
|
|
42
42
|
router.post("/", async (req, res) => {
|
|
43
43
|
try {
|
|
44
|
+
var _req$user, _req$user2;
|
|
44
45
|
const {
|
|
45
46
|
contentId,
|
|
46
47
|
comment,
|
|
48
|
+
files,
|
|
47
49
|
...customFields
|
|
48
50
|
} = req.body;
|
|
49
|
-
const projectId = req.projectId;
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
const projectId = req.projectId;
|
|
52
|
+
const userId = (_req$user = req.user) === null || _req$user === void 0 ? void 0 : _req$user.powrId;
|
|
53
|
+
const userName = (_req$user2 = req.user) === null || _req$user2 === void 0 ? void 0 : _req$user2.fullName;
|
|
54
|
+
if (!contentId || !comment && (!files || !files.length)) {
|
|
52
55
|
return res.status(400).json({
|
|
53
56
|
success: false,
|
|
54
|
-
message: "Content ID and comment are required"
|
|
57
|
+
message: "Content ID and comment (or files) are required"
|
|
55
58
|
});
|
|
56
59
|
}
|
|
57
60
|
const commentData = {
|
|
58
61
|
projectId,
|
|
59
62
|
contentId,
|
|
60
|
-
comment,
|
|
63
|
+
comment: comment || "",
|
|
64
|
+
...(files && {
|
|
65
|
+
files
|
|
66
|
+
}),
|
|
61
67
|
...customFields,
|
|
68
|
+
userId,
|
|
69
|
+
userName: userName || null,
|
|
70
|
+
createdBy: userId ? {
|
|
71
|
+
id: userId,
|
|
72
|
+
_id: userId,
|
|
73
|
+
name: userName
|
|
74
|
+
} : null,
|
|
62
75
|
createdAt: new Date()
|
|
63
76
|
};
|
|
64
77
|
const db = await getDb();
|
|
@@ -76,4 +89,116 @@ router.post("/", async (req, res) => {
|
|
|
76
89
|
});
|
|
77
90
|
}
|
|
78
91
|
});
|
|
92
|
+
|
|
93
|
+
// Update comment (owner only)
|
|
94
|
+
router.patch("/:id", async (req, res) => {
|
|
95
|
+
try {
|
|
96
|
+
var _req$user3;
|
|
97
|
+
const {
|
|
98
|
+
id
|
|
99
|
+
} = req.params;
|
|
100
|
+
const {
|
|
101
|
+
comment
|
|
102
|
+
} = req.body;
|
|
103
|
+
const projectId = req.projectId;
|
|
104
|
+
const userId = (_req$user3 = req.user) === null || _req$user3 === void 0 ? void 0 : _req$user3.powrId;
|
|
105
|
+
if (!ObjectId.isValid(id)) {
|
|
106
|
+
return res.status(400).json({
|
|
107
|
+
success: false,
|
|
108
|
+
message: "Invalid comment id"
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
if (comment === undefined) {
|
|
112
|
+
return res.status(400).json({
|
|
113
|
+
success: false,
|
|
114
|
+
message: "comment is required"
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
const db = await getDb();
|
|
118
|
+
const existing = await db.collection("comments").findOne({
|
|
119
|
+
_id: new ObjectId(id),
|
|
120
|
+
projectId
|
|
121
|
+
});
|
|
122
|
+
if (!existing) {
|
|
123
|
+
return res.status(404).json({
|
|
124
|
+
success: false,
|
|
125
|
+
message: "Comment not found"
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
if (existing.userId !== userId) {
|
|
129
|
+
return res.status(403).json({
|
|
130
|
+
success: false,
|
|
131
|
+
message: "Not allowed to edit this comment"
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
await db.collection("comments").updateOne({
|
|
135
|
+
_id: new ObjectId(id),
|
|
136
|
+
projectId
|
|
137
|
+
}, {
|
|
138
|
+
$set: {
|
|
139
|
+
comment,
|
|
140
|
+
updatedAt: new Date()
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return res.json({
|
|
144
|
+
success: true,
|
|
145
|
+
message: "Comment updated"
|
|
146
|
+
});
|
|
147
|
+
} catch (error) {
|
|
148
|
+
console.error("Error updating comment:", error);
|
|
149
|
+
return res.status(500).json({
|
|
150
|
+
success: false,
|
|
151
|
+
message: "Failed to update comment."
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// Delete comment (owner only)
|
|
157
|
+
router.delete("/:id", async (req, res) => {
|
|
158
|
+
try {
|
|
159
|
+
var _req$user4;
|
|
160
|
+
const {
|
|
161
|
+
id
|
|
162
|
+
} = req.params;
|
|
163
|
+
const projectId = req.projectId;
|
|
164
|
+
const userId = (_req$user4 = req.user) === null || _req$user4 === void 0 ? void 0 : _req$user4.powrId;
|
|
165
|
+
if (!ObjectId.isValid(id)) {
|
|
166
|
+
return res.status(400).json({
|
|
167
|
+
success: false,
|
|
168
|
+
message: "Invalid comment id"
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
const db = await getDb();
|
|
172
|
+
const existing = await db.collection("comments").findOne({
|
|
173
|
+
_id: new ObjectId(id),
|
|
174
|
+
projectId
|
|
175
|
+
});
|
|
176
|
+
if (!existing) {
|
|
177
|
+
return res.status(404).json({
|
|
178
|
+
success: false,
|
|
179
|
+
message: "Comment not found"
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
if (existing.userId !== userId) {
|
|
183
|
+
return res.status(403).json({
|
|
184
|
+
success: false,
|
|
185
|
+
message: "Not allowed to delete this comment"
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
await db.collection("comments").deleteOne({
|
|
189
|
+
_id: new ObjectId(id),
|
|
190
|
+
projectId
|
|
191
|
+
});
|
|
192
|
+
return res.json({
|
|
193
|
+
success: true,
|
|
194
|
+
message: "Comment deleted"
|
|
195
|
+
});
|
|
196
|
+
} catch (error) {
|
|
197
|
+
console.error("Error deleting comment:", error);
|
|
198
|
+
return res.status(500).json({
|
|
199
|
+
success: false,
|
|
200
|
+
message: "Failed to delete comment."
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
});
|
|
79
204
|
module.exports = router;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "powr-sdk-api",
|
|
3
|
-
"version": "4.7.
|
|
3
|
+
"version": "4.7.2",
|
|
4
4
|
"description": "Shared API core library for PowrStack projects. Zero dependencies - works with Express, Next.js API routes, and other frameworks. All features are optional and install only what you need.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|