Build a blog with Areto Node.js framework

User controller

The UserController class is responsible for the actions of a user model.

View user

modules/admin/controllers/UserController.js

'use strict';
const Base = require('../components/CrudController');
module.exports = class UserController extends Base {

  getModelClass () {
    return require('../models/User');
  }
  // place methods here
};
module.exports.init(module);
Update user

The actionIndex method lists all users sorted by ID, name, email or roles. In addition, there is a search by user data.

modules/admin/controllers/UserController.js

...
actionIndex () {
  let Class = this.getModelClass();
  let ActiveDataProvider = require('areto/data/ActiveDataProvider');
  let provider = new ActiveDataProvider({
    controller: this,
    query: Class.findBySearch(this.getQueryParam('search')),
    sort: {
      attrs: {
        [Class.PK]: true,
        name: true,
        email: true,
        role: true
      },
      defaultOrder: {
        [Class.PK]: -1
      }
    }
  });
  provider.prepare(err => {
    err ? this.throwError(err) : this.render('index', {provider});
  });
}
...