Skip to content

Commit 78e8f4a

Browse files
committed
modify get all comments for a dataset function
1 parent b68b16f commit 78e8f4a

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

backend/src/controllers/activity.controller.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const {
44
SavedDataset,
55
Comment,
66
ViewHistory,
7+
User,
78
} = require("../models");
89
const COUCHDB_BASE_URL =
910
process.env.COUCHDB_BASE_URL || "https://neurojson.org/io";
@@ -205,11 +206,11 @@ const addComment = async (req, res) => {
205206
// get comments for a dataset
206207
const getComments = async (req, res) => {
207208
try {
208-
const { couch_db, ds_id } = req.query;
209+
const { dbName, datasetId } = req.params;
209210
const dataset = await Dataset.findOne({
210211
where: {
211-
couch_db,
212-
ds_id,
212+
couch_db: dbName,
213+
ds_id: datasetId,
213214
},
214215
});
215216

@@ -219,6 +220,12 @@ const getComments = async (req, res) => {
219220

220221
const comments = await Comment.findAll({
221222
where: { dataset_id: dataset.id },
223+
include: [
224+
{
225+
model: User,
226+
attributes: ["id", "username"],
227+
},
228+
],
222229
order: [["created_at", "DESC"]],
223230
});
224231
res.status(200).json({ comments });

0 commit comments

Comments
 (0)