I created a code that has 2 functions;
module.exports.registerAccount = (reqBody) => {
let newAccount = new User({
firstName : reqBody.firstName,
lastName : reqBody.lastName,
email : reqBody.email,
mobileNum : reqBody.mobileNum,
password : bcrypt.hashSync(reqBody.password, 10)
})
return await newAccount.save().then((account, error) =>{
if(error){
return false;
}
else{
return true;
}
})
let newCustomer = new Order ({
FirstName : reqBody.firstName,
LastName : reqBody.lastName,
MobileNum : reqBody.mobileNum
})
return await newCustomer.save().then((customer, error) =>{
if(error){
return false;
}
else{
return true;
}
})
}
The newAccount is for the user model and the newCustomer is for the order model, I tried the codes and there's no error but the newCustomer is not saving in its model. I also tried to swap the position of the two model and the result is also swap. is there a way to make both of it work in one go? can I have some tips?
I found the solution;
return newAccount.save() && newCustomer.save().then((account, error) =>{
if(error){
return false;
}
else{
return true;
}
})
since that only one return statement is working I used && in between newAccount and newCustomer.