Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

160
Visualizações
Mongoose statics not found

Created a statics in a userModel.js such as userSchema.statics.login, and trying to refer to it in other file, but WebStorm is saying that is Unresolved function or method login(), pls help).

userSchema.statics.login = async function (email, password)  {
const user = await this.findOne({ email });
if(user){
    const auth = await bcrypt.compare(password, user.password);
    if(auth){
        return user;
    }
    throw Error('Incorrect password');
}
throw Error('Email doesn`t exist');
}
const User = mongoose.model('user', userSchema);
module.exports = User;

File in which i trying to refer:

const User = require("../models/userModel");
module.exports.login_post = async function (req, res) {
  const { email, password } = req.body;

  try {
      const UserLogin = await User.login(email,password);
    res.status(200).json({user: UserLogin._id});
  } catch (err) {
    res.status(400).json({})
  }

}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Fixed that by created a variable at the top of the file in which i want to call that function. Like that:

let User;
User = require("../models/userModel");
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda