Updating postAction to send reasons to backend.

This commit is contained in:
David Jay
2016-12-06 18:11:44 -05:00
parent 3438024624
commit 13d0dec84a
4 changed files with 12 additions and 8 deletions
+3 -2
View File
@@ -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});
+5 -3
View File
@@ -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.
+3 -2
View File
@@ -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);
})
@@ -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'});