Unable to return user from service model

2020-08-01 04:55发布

问题:

I need to return user from my service model to controller model but i am not able to do that can anybody help me that ?

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();
} 

回答1:

try this `

user.save().then(item =>{
 return item ;
}

`