-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
lmarkus
committed
Dec 5, 2013
1 parent
00c4817
commit f37f1f6
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |