import * as actionCore from '../core/action-core';
import {createJsonRoute, throwStatus} from '../util/express';
import {assert} from '../validation';
import * as imageHttp from './image-http';
import * as throttleCore from '../core/throttle-core';

let postAction = createJsonRoute(function(req, res) {
  const action = assert(req.body, 'action');

  if (!throttleCore.canDoAction(action.user, action.type)) {
    throwStatus(429, `Too many actions of type ${ action.type }`);
  }

  let handleAction;
  if (action.type === 'IMAGE') {
    handleAction = imageHttp.postImage(req, res, action);
  } else {
    action.ip = req.ip;

    handleAction = actionCore.getActionType(action.type)
    .then(type => {
      if (type === null) {
        throwStatus(400, 'Action type ' + action.type + ' does not exist');
      }
    })
    .then(() => {
      return actionCore.createAction(action).then(rowsInserted => undefined);
    });
  }

  return handleAction
    .then(() => throttleCore.executeAction(action.user, action.type));
});

export {
  postAction
};

@@ -144,16 +144,61 @@
 ation';%0A
+import * as banCore from '../core/ban-core';%0A
 import *
@@ -515,24 +515,106 @@
 ype %7D%60);%0A  %7D
+ else if (banCore.isUserBanned(action.user)) %7B%0A    banCore.throwBannedError();%0A  %7D
 %0A%0A  let hand

Check if user is banned in /actions API