From 13d0dec84a3300181a2e9cb9cb9a06954c9b3228 Mon Sep 17 00:00:00 2001 From: David Jay Date: Tue, 6 Dec 2016 18:11:44 -0500 Subject: [PATCH] Updating postAction to send reasons to backend. --- client/coral-framework/actions/items.js | 5 +++-- models/action.js | 8 +++++--- routes/api/comments/index.js | 5 +++-- tests/client/coral-framework/store/itemActions.spec.js | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/client/coral-framework/actions/items.js b/client/coral-framework/actions/items.js index 2029714c7..5ad709111 100644 --- a/client/coral-framework/actions/items.js +++ b/client/coral-framework/actions/items.js @@ -217,11 +217,12 @@ export function postItem (item, type, id) { * */ -export function postAction (item_id, action_type, user_id, item_type) { +export function postAction (item_id, action_type, user_id, item_type, text) { return () => { const action = { action_type, - user_id + user_id, + text }; return coralApi(`/${item_type}/${item_id}/actions`, {method: 'POST', body: action}); diff --git a/models/action.js b/models/action.js index 891dbd4f5..591a7d4c0 100644 --- a/models/action.js +++ b/models/action.js @@ -11,7 +11,8 @@ const ActionSchema = new Schema({ action_type: String, item_type: String, item_id: String, - user_id: String + user_id: String, + text: String, }, { timestamps: { createdAt: 'created_at', @@ -34,12 +35,13 @@ ActionSchema.statics.findById = function(id) { * @param {String} action the new action to the comment * @return {Promise} */ -ActionSchema.statics.insertUserAction = ({item_id, item_type, user_id, action_type}) => { +ActionSchema.statics.insertUserAction = ({item_id, item_type, user_id, action_type, text}) => { const action = { item_id, item_type, user_id, - action_type + action_type, + text }; // Create/Update the action. diff --git a/routes/api/comments/index.js b/routes/api/comments/index.js index 3bdf4afc6..daf3ae121 100644 --- a/routes/api/comments/index.js +++ b/routes/api/comments/index.js @@ -111,11 +111,12 @@ router.put('/:comment_id/status', authorization.needed('admin'), (req, res, next router.post('/:comment_id/actions', (req, res, next) => { const { - action_type + action_type, + text } = req.body; Comment - .addAction(req.params.comment_id, req.user.id, action_type) + .addAction(req.params.comment_id, req.user.id, action_type, text) .then((action) => { res.status(201).json(action); }) diff --git a/tests/client/coral-framework/store/itemActions.spec.js b/tests/client/coral-framework/store/itemActions.spec.js index 45c41025f..ee5951dd6 100644 --- a/tests/client/coral-framework/store/itemActions.spec.js +++ b/tests/client/coral-framework/store/itemActions.spec.js @@ -155,7 +155,7 @@ describe('itemActions', () => { describe('postAction', () => { it ('should post an action', () => { fetchMock.post('*', {id: '456'}); - return actions.postAction('abc', 'flag', '123', 'comments')(store.dispatch) + return actions.postAction('abc', 'flag', '123', 'comments', 'Comment smells funny')(store.dispatch) .then(response => { expect(fetchMock.calls().matched[0][0]).to.equal('/api/v1/comments/abc/actions'); expect(response).to.deep.equal({id:'456'});