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 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;
  await model.upload(this.req, this.res, this.user)
    ? this.sendText(model.getId())
    : this.sendText(this.translate(model.getFirstError()), 400);
}