File controller

The FileController class defines a file model controller.

To turn off unnecessary actions inherited from the base controller, certain properties is set to NULL values in class constants.


const Base = require('../component/CrudController');

module.exports = class FileController extends Base {

  static getConstants () {
    return {
      METHODS: {
        'upload': ['post']
      actionCreate: null,
      actionUpdate: null
  // place methods here

const File = require('../model/File');

The actionUpload action is limited to the POST request by the METHODS constants. A 404 error will be returned for all other request's types of this action.


actionUpload () {
  const model = this.spawn(File);
  await model.upload(this.req, this.res, this.user)
    ? this.sendText(model.getId())
    : this.sendText(this.translate(model.getFirstError()), 400);