Skip to content

Commit b68b16f

Browse files
committed
modify add comment function
1 parent 6aa6403 commit b68b16f

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

backend/src/controllers/activity.controller.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,21 @@ const unsaveDataset = async (req, res) => {
178178
const addComment = async (req, res) => {
179179
try {
180180
const user = req.user;
181-
const { couch_db, ds_id, body } = req.body;
181+
const { dbName, datasetId } = req.params;
182+
const { body } = req.body;
182183

183-
const dataset = await getOrCreateDataset(couch_db, ds_id);
184+
if (!body || body.trim() === "") {
185+
return res.status(400).json({ message: "Comment body is required" });
186+
}
187+
188+
const dataset = await getOrCreateDataset(dbName, datasetId);
184189

185190
const comment = await Comment.create({
186191
user_id: user.id,
187192
dataset_id: dataset.id,
188193
body,
189194
});
195+
190196
res.status(201).json({ message: "Comment added successfully", comment });
191197
} catch (error) {
192198
console.error("Add comment error:", error);

0 commit comments

Comments
 (0)