Skip to content

Commit

Permalink
Created a Product model
Browse files Browse the repository at this point in the history
  • Loading branch information
lmarkus committed Dec 5, 2013
1 parent 00c4817 commit f37f1f6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Empty file removed models/index.js
Empty file.
34 changes: 34 additions & 0 deletions models/productModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

var mongoose = require('mongoose');

var productModel = function () {

//Define a super simple schema for our products.
var productSchema = mongoose.Schema({
name: String,
price: Number
});

/**
* Verbose toString method
*/
productSchema.methods.whatAmI = function () {
var greeting = this.name ?
'Hello, I\'m a ' + this.name + ' and I\'m worth $' + this.price
: 'I don\'t have a name :(';
console.log(greeting);
};

/**
* Format the price of the product to show a dollar sign, and two decimal places
*/
productSchema.methods.prettyPrice = function () {
return '$' + this.price.toFixed(2);
};

return mongoose.model('Product', productSchema);

};

module.exports = new productModel();

0 comments on commit f37f1f6

Please sign in to comment.