M
M
mr_blaze2017-09-25 19:49:39
JavaScript
mr_blaze, 2017-09-25 19:49:39

How to call return on parent?

Hello!
Please, help! I haven’t eaten or slept for two days, but I don’t understand HOW!
There is a Use.js code

exports.checkUser = function () {
    let user = new User({
        username: arguments[0],
        password: arguments[1]
    });

    User.findOne({username: user.username})
        .then(function (doc) {
            let uid;
            if (find) {
                if (user.checkPassword(find.salt, find.hashedPassword)) {
                    uid = user.rsaEncrypt(arguments[2], find._id);
                    console.log("12");
                    if (arguments.length === 3) {
                        console.log("1");
                        console.log(uid);
                        return Promise.resolve(uid);
                    } else if (arguments.length === 4) {
                        console.log("2");
                        console.log(uid);
                        return uid === arguments[3];
                    }
                } else return false;
            } else return false;
        });
};

And this is how I call this function
res.send(User.checkUser(req.body.username, req.body.pwd, req.ip));

But an empty string is sent.
I understand that the problem is in return, but no matter how I try - it does not work!
Help me please!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
gleendo, 2017-09-25
@evgeniy8705

return User.findOne...

I
Ilya Gerasimov, 2017-09-25
@Omashu

Read about Promise

return User.findOne

User.checkUser().then(result => {
  res.send(result);
  }).catch(err => {

    })

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question