Build a blog with Areto Node.js framework

File controller

The FileController class defines a controller of the file model.

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

module/admin/controller/FileController.js

const Base = require('../component/CrudController');
module.exports = class FileController extends Base {

  static getConstants () {
    return {
      METHODS: {
        'upload': ['post']
      },
      actionCreate: null,
      actionUpdate: null
    };
  }
  // place methods here
};
module.exports.init(module);
const async = require('areto/helper/AsyncHelper');
const File = require('../model/File');

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

module/admin/controller/FileController.js

actionUpload () {
  let model = new File;
  async.series([
    cb => model.upload(this, cb),
    cb => model.hasError()
      ? this.sendText(this.translate(model.getFirstError()), 400)
      : this.sendText(model.getId())
  ], err => this.throwError(err));
}