Guest User

Untitled

a guest
Feb 17th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. let mongoose = require('mongoose');
  2. let Schema = mongoose.Schema;
  3. let BookSchema = new Schema(
  4. {
  5. title: {type: String,required: true},
  6. author: {type: Schema.ObjectId,ref:'Author',required: true},
  7. summary: {type: String, required:true},
  8. isbn: {type: String, required:true},
  9. genre: [{type: Schema.ObjectId, ref:'Genre'}]
  10. }
  11. );
  12. BookSchema
  13. .pre('countDocuments');
  14. BookSchema
  15. .virtual('url')
  16. .get(function () {
  17. return '/catalog/book/'+this._id;
  18. });
  19.  
  20. module.exports = mongoose.model('Book',BookSchema);
  21.  
  22. var Book = require('../models/book');
  23. var Author = require('../models/author');
  24. var Genre = require('../models/genre');
  25. var BookInstance = require('../models/bookinstance');
  26. var async = require('async');
  27.  
  28. exports.index = function(req, res) {
  29. async.parallel({
  30. book_count: function (callback) {
  31. Book.countDocuments({},callback);
  32. }
  33. },
  34. function (err,results) {
  35. res.render('index',{title: 'Local Library Home',error:err, data:results});
  36. res.json({data: results});
  37. });
  38. res.send('NOT IMPLEMENTED: Site Home Page');
  39. };
Add Comment
Please, Sign In to add comment