title: Cannot read property 'findOne' of undefined with Nodejs and Sequelize
body: <p>I tryng to get a Token with a postman req and the errors ocurrs...</p>
  
  <blockquote>
    <p>TypeError: Cannot read property 'findOne' of undefined
    at User.getByEmail (server/modules/User/service.ts:47:23)
    at TokenRoutes.auth (server/modules/Auth/auth.ts:18:8)</p>
  </blockquote>
  
  <p>Heres the code:</p>
  
  <p><strong>controller.ts</strong></p>
  
  <pre><code>import { Request, Response } from 'express';
  import * as HTTPStatus from 'http-status';
  import * as _ from 'lodash';
  import { onError } from '../../api/responses/errorHandler';
  import { onSuccess } from '../../api/responses/successHandler';
  import { dbErrorHandler } from '../../config/dbErrorHandler';
  import User from './service';
  
  class UserController {
  
    constructor() {}
  
    getAll(req: Request, res: Response){
      User
        .getAll()
        .then(_.partial(onSuccess, res))
        .catch(_.partial(onError, res, `Erro ao buscar todos os usuários`))
    }
  
    createUser(req: Request, res: Response){
      User
        .create(req.body)
        .then(_.partial(onSuccess, res))
        .catch(_.partial(dbErrorHandler, res))
        .catch(_.partial(onError, res, `Erro ao inserir novo usuário`))
    }
  
    getById(req: Request, res: Response){
      const userId = parseInt(req.params.id);
      User.getById(userId)
        .then(_.partial(onSuccess, res))
        .catch(_.partial(onError, res, `Usuário não encontrado`))
    }
  
    updateUser(req: Request, res: Response){
      const userId = parseInt(req.params.id);
      const props = req.body;
      User.update(userId, props)
        .then(_.partial(onSuccess, res))
        .catch(_.partial(onError, res, `Erro ao atualizar usuário`))
    }
  
    deleteUser(req: Request, res: Response){
      const userId = parseInt(req.params.id);
      User.delete(userId)
        .then(_.partial(onSuccess, res))
        .catch(_.partial(onError, res, `Erro ao deletar usuário`))
    }
  }
  
  export default new UserController();
  </code></pre>
  
  <p><strong>routes.ts</strong></p>
  
  <pre><code>import { Request, Response } from 'express';
  import UserController from './controller';
  
  
  class UserRoutes {
  
    constructor(){}
  
    index(req: Request, res: Response){
      return UserController.getAll(req, res);
    }
  
    create(req: Request, res: Response){
      return UserController.createUser(req, res);
    }
  
    findOne(req: Request, res: Response){
      return UserController.getById(req, res);
    }
  
    update(req: Request, res: Response){
      return UserController.updateUser(req, res);
    }
  
    destroy(req: Request, res: Response){
      return UserController.deleteUser(req, res);
    }
  }
  
  export default new UserRoutes();
  </code></pre>
  
  <p><strong>service.ts</strong></p>
  
  <pre><code>import { IUser, IUserDetail, createUser, createUsers, createUserById, createUserByEmail } from './interface';
  import * as Bluebird from 'bluebird';
  const model = require('../../models');
  
  class User implements IUser {
    public id: number;
    public nm_usuario: string;
    public nm_email_usuario: string;
    public cd_senha_usuario: string;
    public nm_tipo_usuario: string;
    public cd_cnpj_usuario: number;
    public cd_cpf_usuario: number;
    public nm_razao_social_usuario: string;
    public nm_sexo_usuario: string;
    public cd_cep_usuario: number;
    public nm_estado_usuario: string;
    public dt_nascimento_usuario: Date;
    public nm_cidade_usuario: string;
    public cd_telefone_usuario: number;
    public cd_ip_usuario: string;
    public nm_endereco_usuario: string;
    public cd_numero_endereco_usuario: number;
    public ds_complemento_endereco_usuario: string;
    public ds_foto_usuario: string;
  
    constructor(){}
  
    create(user: any){
      return model.User.create(user);
    }
  
    getAll(): Bluebird&lt;IUser[]&gt;{
      return model.User.findAll({
        order: ['nm_usuario']
      })
      .then(createUsers);
    }
  
    getById(id: number): Bluebird&lt;IUserDetail&gt;{
      return model.User.findOne({
        where: { id }
      })
      .then(createUserById);
    }
  
    getByEmail(nm_email_usuario: string): Bluebird&lt;IUserDetail&gt;{
      return model.User.findOne({
        where: { nm_email_usuario }
      })
      .then(createUserByEmail);
    }
  
    update(id: number, user: any){
      return model.User.update(user, {
        where: { id },
        fields: ['nm_usuario', 'nm_email_usuario','cd_senha_usuario','nm_tipo_usuario','cd_cnpj_usuario','cd_cpf_usuario','nm_razao_social_usuario','nm_sexo_usuario','cd_cep_usuario','nm_estado_usuario','dt_nascimento_usuario','nm_cidade_usuario','cd_telefone_usuario','cd_ip_usuario','nm_endereco_usuario','cd_numero_endereco_usuario','ds_complemento_endereco_usuario','ds_foto_usuario'],
        hooks: true,
        individualHooks: true
      });
    }
  
    delete(id: number){
      return model.User.destroy({
        where: { id }
      });
    }
  }
  
  export default new User();
  </code></pre>
  
  <p><strong>auth.ts</strong></p>
  
  <pre><code>import { Request, Response } from 'express';
  import * as _ from 'lodash';
  import User from '../User/service';
  import authSuccess from '../../api/responses/authSuccess';
  import authFail from '../../api/responses/authFail';
  
  
  class TokenRoutes {
  
    auth(req: Request, res: Response){
      const credentials = {
        nm_email_usuario: req.body.nm_email_usuario,
        cd_senha_usuario: req.body.cd_senha_usuario
      };
  
      if(credentials.hasOwnProperty('nm_email_usuario') &amp;&amp; credentials.hasOwnProperty('cd_senha_usuario')){
        User
        .getByEmail(credentials.nm_email_usuario)
        .then(_.partial(authSuccess, res, credentials))
        .catch(_.partial(authFail, req, res));
      }
    }
  }
  
  export default new TokenRoutes();
  </code></pre>
  
  <p>So... postman giveme a error 500, probably because can't to execute the method findOne.</p>