Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*===== models/item.js =====*/
- /* Item schema */
- var mongoose = require('mongoose');
- var Schema = mongoose.Schema;
- var itemSchema = new Schema({
- item_id: {
- type: String,
- required: true,
- unique: true
- },
- item_name: { type: String },
- description: { type: String },
- stock: { type: Number },
- image_path: { type: String }
- },
- {
- timestamps: true
- });
- module.exports = mongoose.model('Item', itemSchema);
- /* ===== routes/index.js =====*/
- /* GET home page. */
- router.get('/', function(req, res, next) {
- var messages = req.flash('error');
- Item.find({}, {'item_name':1, 'stock':1}, function(err, docs) {
- res.render('index', { title: 'Express', csrfToken: req.csrfToken(), messages: messages, loginErrors: messages.length > 0, items: docs });
- });
- });
- /* ===== views/index.hbs ===== */
- /* Display list item */
- <div class="list-group list-item-status">
- {{#each items }}
- <li class="list-group-item">
- {{#each this }}
- {{ this.item_name }}
- <span class="badge">{{ this.stock }}</span>
- {{/each}}
- </li>
- {{/each}}
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement