Removing extra commas and collapsing actions into an object in the backend.

This commit is contained in:
David Jay
2016-12-08 15:27:49 -05:00
parent b3d84d724f
commit 9d28577e9b
7 changed files with 13 additions and 37 deletions
+1 -1
View File
@@ -57,7 +57,7 @@ class FlagButton extends Component {
header: lang.t('step-1-header'),
options: [
{val: 'user', text: lang.t('flag-username')},
{val: 'comments', text: lang.t('flag-comment')},
{val: 'comments', text: lang.t('flag-comment')}
],
button: lang.t('continue'),
sets: 'itemType'
+5 -12
View File
@@ -32,23 +32,16 @@ ActionSchema.statics.findById = function(id) {
/**
* Add an action.
* @param {String} item_id identifier of the comment (uuid)
* @param {String} item_id identifier of the item (uuid)
* @param {String} user_id user id of the action (uuid)
* @param {String} action the new action to the comment
* @param {String} action the new action to the item
* @return {Promise}
*/
ActionSchema.statics.insertUserAction = ({item_id, item_type, user_id, action_type, field, detail}) => {
const action = {
item_id,
item_type,
user_id,
action_type,
field,
detail
};
ActionSchema.statics.insertUserAction = ({item_id, item_type, user_id, action}) => {
let action_obj = Object.assign({}, action, {item_id, item_type, user_id});
// Create/Update the action.
return Action.findOneAndUpdate(action, action, {
return Action.findOneAndUpdate(action_obj, action_obj, {
// Ensure that if it's new, we return the new object created.
new: true,
+2 -4
View File
@@ -284,13 +284,11 @@ CommentSchema.statics.pushStatus = (id, status, assigned_by = null) => Comment.u
* @param {String} action the new action to the comment
* @return {Promise}
*/
CommentSchema.statics.addAction = (item_id, user_id, action_type, field, detail) => Action.insertUserAction({
CommentSchema.statics.addAction = (item_id, user_id, action) => Action.insertUserAction({
item_id,
item_type: 'comment',
user_id,
action_type,
field,
detail
action
});
/**
+2 -4
View File
@@ -555,11 +555,9 @@ UserService.addBio = (id, bio) => (
* @param {String} action the new action to the user
* @return {Promise}
*/
UserService.addAction = (item_id, user_id, action_type, field, detail) => Action.insertUserAction({
UserService.addAction = (item_id, user_id, action) => Action.insertUserAction({
item_id,
item_type: 'comment',
user_id,
action_type,
field,
detail
action
});
+1 -8
View File
@@ -148,15 +148,8 @@ router.put('/:comment_id/status', authorization.needed('admin'), (req, res, next
});
router.post('/:comment_id/actions', (req, res, next) => {
const {
action_type,
field,
detail
} = req.body;
Comment
.addAction(req.params.comment_id, req.user.id, action_type, field, detail)
.addAction(req.params.comment_id, req.user.id, req.body)
.then((action) => {
res.status(201).json(action);
})
+1 -7
View File
@@ -158,15 +158,9 @@ router.put('/:user_id/bio', (req, res, next) => {
});
router.post('/:user_id/actions', authorization.needed(), (req, res, next) => {
console.log('Hit action endpoint');
const {
action_type,
field,
detail
} = req.body;
User
.addAction(req.params.comment_id, req.user.id, action_type, field, detail)
.addAction(req.params.comment_id, req.user.id, req.body)
.then((action) => {
res.status(201).json(action);
})
+1 -1
View File
@@ -350,7 +350,7 @@ describe('/api/v1/comments/:comment_id/actions', () => {
return chai.request(app)
.post('/api/v1/comments/abc/actions')
.set(passport.inject({id: '456', roles: ['admin']}))
.send({'user_id': '456', 'action_type': 'flag'})
.send({'action_type': 'flag'})
.then((res) => {
expect(res).to.have.status(201);
expect(res).to.have.body;