Build a blog with Areto Node.js framework

User controller

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

View user

module/admin/controller/UserController.js

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

  static getConstants ()  {
    return {
      BEHAVIORS: {
        'access': {
          Class: require('areto/filter/AccessControl'),
          rules: [{
            allow: true,
            roles: ['admin']
          }]
        }
      }
    };
  }
  // place methods here
};
module.exports.init(module);
const User = require('../model/User');
Update user

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

module/admin/controller/UserController.js

async actionIndex () {
  let provider = this.createDataProvider({
    query: User.findBySearch(this.getQueryParam('search')),
    sort: {
      attrs: {
        [User.PK]: true,
        name: true,
        email: true,
        role: true
      },
      defaultOrder: {
        [User.PK]: -1
      }
    }
  });
  await this.renderDataProvider(provider, 'index', {provider});
}