separate route for loading comments per user

This commit is contained in:
Riley Davis
2016-12-12 13:00:39 -07:00
parent c999e1c1a9
commit c016e29290
2 changed files with 16 additions and 2 deletions
+4 -2
View File
@@ -92,16 +92,19 @@ export const appendItemArray = (id, property, value, add_to_front, item_type) =>
export const fetchCommentsByUserId = userId => {
return (dispatch) => {
dispatch({type: REQUEST_COMMENTS_BY_USER});
return coralApi(`/comments?user_id=${userId}`)
return coralApi(`/comments/user/${userId}`)
.then(comments => {
dispatch({type: RECEIVE_COMMENTS_BY_USER, comments});
console.log('comments?', comments);
comments.forEach(comment => {
dispatch(addItem(comment, 'comments'));
});
})
.catch(error => {
console.error('FAILURE_COMMENTS_BY_USER', error);
dispatch({type: FAILURE_COMMENTS_BY_USER, error});
});
};
@@ -145,7 +148,6 @@ export function getStream (assetUrl) {
/* Sort comments by date*/
json.comments.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
const rels = json.comments.reduce((h, item) => {
/* Check for root and child comments. */
if (
+12
View File
@@ -116,6 +116,18 @@ 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)