Add json header, update status, and lint

This commit is contained in:
David Erwin
2016-11-10 10:49:55 -05:00
parent 465437b04a
commit a234eeb3ba
3 changed files with 18 additions and 13 deletions
@@ -7,8 +7,8 @@ import Comment from 'components/Comment';
// Each action has different meaning and configuration
const actions = {
'reject': {status: 'Rejected', icon: 'close', key: 'r'},
'approve': {status: 'Approved', icon: 'done', key: 't'},
'reject': {status: 'rejected', icon: 'close', key: 'r'},
'approve': {status: 'accepted', icon: 'done', key: 't'},
'flag': {status: 'flagged', icon: 'flag', filter: 'Untouched'}
};
@@ -7,6 +7,9 @@
* for the coral but also for wordpress comments, disqus and many more.
*/
// Default headers for json payloads.
const jsonHeader = new Headers({'Content-Type': 'application/json'});
// Intercept redux actions and act over the ones we are interested
export default store => next => action => {
@@ -18,7 +21,6 @@ export default store => next => action => {
// fetchCommentStream(store);
// break;
case 'COMMENT_UPDATE':
console.log('asdadasd')
updateComment(store, action.comment);
break;
case 'COMMENT_CREATE':
@@ -44,14 +46,16 @@ Promise.all([fetch('/api/v1/comments/status/pending'), fetch('/api/v1/comments/s
// Update a comment. Now to update a comment we need to send back the whole object
const updateComment = (store, comment) => {
fetch(`/api/v1/comments/${comment.get('id')}/status`, {
method: 'POST',
body: JSON.stringify({status: comment.get('status')})
})
fetch(`/api/v1/comments/${comment.get('id')}/status`, {
method: 'POST',
headers: jsonHeader,
body: JSON.stringify({status: comment.get('status')})
})
.then(res => res.json())
.then(res => store.dispatch({type: 'COMMENT_UPDATE_SUCCESS', res}))
.catch(error => store.dispatch({type: 'COMMENT_UPDATE_FAILED', error}));
}
};
// Create a new comment
const createComment = (store, name, comment) =>
fetch('/api/v1/comments', {
+6 -5
View File
@@ -94,11 +94,12 @@ router.post('/:comment_id', (req, res, next) => {
});
router.post('/:comment_id/status', (req, res, next) => {
Comment.changeStatus(req.params.comment_id, req.body.status).then((comment) => {
res.status(200).send(comment);
}).catch(error => {
next(error);
});
Comment
.changeStatus(req.params.comment_id, req.body.status)
.then(comment => res.status(200).send(comment))
.catch(error => next(error));
});
router.post('/:comment_id/actions', (req, res, next) => {