title: how to validate business rules in node application with sequelize?
body: <p>I have an express/node js application using sequelize orm. I want to know what would be a best place in the application to write validation for business rules. say i have a user model class as below. I have added some model validation to the class (in bold below) , for example Name cannot be empty. other than the model validation, where can i add some business rule validation , like if age is less than 18 or 16, you cannot have employerName or hoursWorkedPerWeek ( this is just for this example). example is contrived for this question.</p>
  <p>is there a way to add such rules to the model class, if now how do i add that to the contorller class below.</p>
  <p>user model class</p>
  <pre><code>const User = sequelize.define(
    'User',
    {
      id: {
        type: DataTypes.BIGINT,
        allowNull: false,
        primaryKey: true,
        autoIncrement: true,
        field: 'id'
      },
      Name: { 
          type: DataTypes.STRING,  
          allowNull: false,
          **validate: {
            notEmpty: true
          }**
       },
      age: {
      }, 
      hoursWorkedPerWeek: {
      }, 
      employerName: {
      }, 
      createdAt: {
       
      },
      updatedAt: {
      
      }
    }
    ....
  );
  </code></pre>
  <p>controller class</p>
  <pre><code>static async add(user) {
        try {
               models.User.create(user).then(newUser =&gt; {
                   //do something
          }).catch(error =&gt; {
            throw error;
          }); 
      
        } catch (error) { 
            throw error;
        }
      }
  
  </code></pre>