diff --git a/client/coral-framework/actions/user.js b/client/coral-framework/actions/user.js index 5cbd04792..e1d12b3e3 100644 --- a/client/coral-framework/actions/user.js +++ b/client/coral-framework/actions/user.js @@ -31,8 +31,8 @@ export const saveBio = (user_id, formData) => dispatch => { export const fetchCommentsByUserId = userId => { return (dispatch) => { dispatch({type: actions.REQUEST_COMMENTS_BY_USER}); - return coralApi(`/comments/user/${userId}`) - .then(comments => { + return coralApi(`/comments?user_id${userId}`) + .then(({comments}) => { comments.forEach(comment => { dispatch(addItem(comment, 'comments')); }); diff --git a/routes/api/comments/index.js b/routes/api/comments/index.js index 534b14366..fca2bcb31 100644 --- a/routes/api/comments/index.js +++ b/routes/api/comments/index.js @@ -14,7 +14,8 @@ router.get('/', authorization.needed('admin'), (req, res, next) => { const { status = null, action_type = null, - asset_id = null + asset_id = null, + user_id = null } = req.query; /** @@ -32,6 +33,8 @@ router.get('/', authorization.needed('admin'), (req, res, next) => { if (status) { query = assetIDWrap(Comment.findByStatus(status === 'new' ? null : status)); + } else if (user_id) { + query = Comment.findByUserId(user_id); } else if (action_type) { query = Comment .findIdsByActionType(action_type) @@ -121,18 +124,6 @@ router.post('/', wordlist.filter('body'), (req, res, next) => { }); }); -router.get('/user/:user_id', (req, res, next) => { - // how to only get YOUR comments? - Comment.findByUserId(req.params.user_id) - .then(comments => { - res.json(comments); - }) - .catch(error => { - error.status = 500; - next(error); - }); -}); - router.get('/:comment_id', authorization.needed('admin'), (req, res, next) => { Comment .findById(req.params.comment_id) diff --git a/tests/helpers/browser.js b/tests/helpers/browser.js index 0714b83af..3fd54e0fe 100644 --- a/tests/helpers/browser.js +++ b/tests/helpers/browser.js @@ -26,7 +26,7 @@ function storageMock() { }; } -global.document = jsdom(fs.readFileSync(path.resolve(__dirname, '/index.test.html'))); +global.document = jsdom(fs.readFileSync(path.resolve(__dirname, 'index.test.html'))); global.window = document.defaultView; // these lines are required for react-mdl