Guest User

Untitled

a guest
Dec 13th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. const userSchema = new mongoose.Schema({
  2. email: { type: String, unique: true, lowercase: true, trim: true },
  3. password: String,
  4. role: [ { type: mongoose.Schema.Types.ObjectId, ref: 'Role' } ]
  5. });
  6. const User = mongoose.model('User', userSchema);
  7. export default User;
  8.  
  9. const roleSchema = new mongoose.Schema({
  10. description: { type: String },
  11. });
  12. const Role = mongoose.model('Role', roleSchema);
  13. export default Role;
  14.  
  15. abstract class BaseCtrl {
  16. abstract model: any;
  17. // Example of read using get all
  18. getAll = (req, res) => {
  19. this.model.find({}, (err, docs) => {
  20. if (err) { return console.error(err); }
  21. res.json(docs);
  22. });
  23. }
  24. export default BaseCtrl;
Add Comment
Please, Sign In to add comment