I have this issue whit my code, i have a kind of data i need to get current when the user ask for it, i use promise to get the right data out and thats part working well.
my next issue is first time i ask for the data, its return nothing but, if i click agin for the data its return the right data, so something are wrong here.
my promise function
var insert = new Promise(function(fulfill) {
fulfill('test');
});
my export moduls
exports.signup = function(db, user_conf) {
var self = this;
defineUser(user_conf);
insert.then(function(result) {
self.json_response = result;
console.log(result);
}).catch(function(e) {
console.log(e);
});
return self.json_response;
}
my express route function
router.post('/signup', function(req, res, next) {
var post = req.body;
json_response = users.signup(req.db, {
'fullname' : post["account-fullname"],
'username' : post["account-username"],
'email' : post["account-email"],
'password' : post["account-password"],
'retype-password' : post["account-retype-password"],
'accept-terms' : post["accept-terms"]
});
res.send(json_response);
});
what i need its i need the respons from my signup part to know about the user can be created or there are a kind of validations error the user need to know before the user can be created.