我需要将用户从我的服务模型返回到控制器模型,但是我无法做到这一点,有人可以帮助我吗?
async function create(userParam) {
if (await User.findOne({ username: userParam.username })) {
throw 'Username "' + userParam.username + '" is already taken';
}
const user = new User(userParam);
console.log("User", userParam , user )
// hash password
if (userParam.password) {
user.hash = bcrypt.hashSync(userParam.password, 10);
}
// return user from here
await user.save();
}
答案 0 :(得分:0)
尝试这个`
user.save().then(item =>{
return item ;
}
`