mirror of
https://github.com/wassname/talk.git
synced 2026-08-03 13:20:59 +08:00
Updating postAction to send reasons to backend.
This commit is contained in:
@@ -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
@@ -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.
|
||||
|
||||
@@ -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'});
|
||||
|
||||
Reference in New Issue
Block a user