I recently developed a code with 2 essential 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 purpose of newAccount is to handle the user model while newCustomer is responsible for the order model. After running some tests, I encountered no errors with the codes, but unfortunately, newCustomer isn't being saved in its designated model as expected. I even attempted switching the positions of the two models, which resulted in the same outcome switch. Is there any effective method to ensure that both operations work flawlessly together? Any suggestions or tips would be greatly appreciated.