Advertisement
nubilfi

expressjs

Jan 4th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*===== models/item.js =====*/
  2.  
  3. /* Item schema */
  4. var mongoose = require('mongoose');
  5. var Schema = mongoose.Schema;
  6.  
  7. var itemSchema = new Schema({
  8.     item_id: {
  9.         type: String,
  10.         required: true,
  11.         unique: true
  12.     },
  13.     item_name: { type: String },
  14.     description: { type: String },
  15.     stock: { type: Number },
  16.     image_path: { type: String }
  17. },
  18. {
  19.     timestamps: true
  20. });
  21.  
  22. module.exports = mongoose.model('Item', itemSchema);
  23.  
  24.  
  25. /* ===== routes/index.js =====*/
  26.  
  27. /* GET home page. */
  28. router.get('/', function(req, res, next) {
  29.     var messages = req.flash('error');
  30.     Item.find({}, {'item_name':1, 'stock':1}, function(err, docs) {
  31.         res.render('index', { title: 'Express', csrfToken: req.csrfToken(), messages: messages, loginErrors: messages.length > 0, items: docs });
  32.     });
  33. });
  34.  
  35. /* ===== views/index.hbs ===== */
  36.  
  37. /* Display list item */
  38. <div class="list-group list-item-status">
  39.     {{#each items }}
  40.         <li class="list-group-item">
  41.             {{#each this }}
  42.                {{ this.item_name }}
  43.                <span class="badge">{{ this.stock }}</span>
  44.             {{/each}}
  45.         </li>
  46.     {{/each}}
  47. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement