import { Controller} from "egg";
export default class Login extends Controller{
public async login(){
const {ctx}=this;
ctx.body= await ctx.service.login.login("admin","admin");
};
public async register(){
const {ctx}=this;
let {username,password}=ctx.query;
console.log(username);
ctx.body= await ctx.service.register.register(username,password);
};
}
< hr >
public async register(name: String, psw: String) {
mongoose.connect("mongodb://localhost/egg");
let loginData = mongoose.Schema({
username: String,
password: String
})
let loginModel = mongoose.model("loginModel", loginData);
var data = new loginModel({ username: name, password: psw });
data.save(function(err){
if(!err){
return ""
}
});
return ""
}
how can Controller get the result of asynchronous save callback return in service by using native mongoose instead of egg-monogoose in egg