src/entities/index.js
/**
   * Scan all entity schemas under a special path
   * @param entitiesPath
   * @param withAssociate
   * @returns {Entities}
   */
Scan all entity schemas under a special path
@param entitiesPath
@param withAssociate
@returns {Entities}
Scan all entity schemas under a special path @param entitiesPath @param withAssociate @returns { Entities }
scan(entitiesPath, withAssociate = true) {
    assert(this.sequelize && this.sequelize instanceof Sequelize, 'Scan entities require a sequelize instance');
    fs
      .readdirSync(entitiesPath)
      .filter((file) => {
        const fileArray = file.split('.');
        return (file.indexOf('.') !== 0) &&
          (['js', 'es6'].indexOf(fileArray.pop()) !== -1) && (fileArray[0] !== 'index');
      })
      .forEach((file) => {
        const entity = this.sequelize.import(path.join(entitiesPath, file));
        this.entities[entity.name] = entity;
      });
    if (!withAssociate) {
      return this;
    }
    Object.values(this.entities).forEach((entity) => {
      if ('associate' in entity) {
        entity.associate(this.entities);
      }
    });
    return this;
  }
scan ( entitiesPath , withAssociate = true ) { assert ( this . sequelize && this . sequelize instanceof Sequelize , 'Scan entities require a sequelize instance' ) ; fs . readdirSync ( entitiesPath ) . filter ( ( file ) => { const fileArray = file . split ( '.' ) ; return ( file . indexOf ( '.' ) !== 0 ) && ( [ 'js' , 'es6' ] . indexOf ( fileArray . pop ( ) ) !== - 1 ) && ( fileArray [ 0 ] !== 'index' ) ; } ) . forEach ( ( file ) => { const entity = this . sequelize . import ( path . join ( entitiesPath , file ) ) ; this . entities [ entity . name ] = entity ; } ) ; if ( ! withAssociate ) { return this ; } Object . values ( this . entities ) . forEach ( ( entity ) => { if ( 'associate' in entity ) { entity . associate ( this . entities ) ; } } ) ; return this ; }
Scan all entity schemas under a special path
 @param entitiesPath
 @param withAssociate
 @returns {Entities}
Scan all entity schemas under a special path @param entitiesPath @param withAssociate @returns { Entities }