Mongoose based service and CCD controller Also implements the basic CRUD methods
...imports and setup
interface User extends mongoose.Document{
Username:string
}
class UserCtrl extends CCServiceController<User>{
@post('/login')
login(req, res){
//yes, that simple,
//model is regulat mongoose model
return this.model.findOne(req.body);
}
}
//the mongoose model needs to be defined
mongoose.Model<User>('User', new mongoose.Schema({
Username:String
});
app.use('/', new UserCtrl('User').router);
app.listen(3000);
If you like to be more structured and have the db methods in a separate class then you can use the CCService<T>
class for that.