mirror of
https://github.com/wassname/talk.git
synced 2026-07-11 03:37:01 +08:00
separate route for loading comments per user
This commit is contained in:
@@ -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 (
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user