aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/models
diff options
context:
space:
mode:
authorDennis Eriksen <dennis.se@gmail.com>2013-05-09 10:30:53 +0200
committerDennis Eriksen <dennis.se@gmail.com>2013-05-09 10:30:53 +0200
commite7cf0075829e1424d5c2fcbeeac97509b404b856 (patch)
tree0429b098d4cb32e441ef07dde229a0d6eb1b80b1 /models
parentadded project post scheme (diff)
downloadDivid-e7cf0075829e1424d5c2fcbeeac97509b404b856.tar.gz
changed the model
Diffstat (limited to 'models')
-rw-r--r--models/pPost.js47
1 files changed, 15 insertions, 32 deletions
diff --git a/models/pPost.js b/models/pPost.js
index f29c7f8..5ec28b1 100644
--- a/models/pPost.js
+++ b/models/pPost.js
@@ -6,49 +6,32 @@
var mongoose = require('mongoose')
, Schema = mongoose.Schema;
-var ProjectSchema = new Schema({
+var pPostSchema = new Schema({
user: { type: Schema.ObjectId, ref: 'User' },
- name: { type: String, default: '', trim: true },
- description: {type: String, default: '', trim: true },
+ for: { type: Schema.ObjectId, ref: 'User' },
+ project: { type: Schema.ObjectId, ref: 'Project' },
+ what: { type: String, default: '', trim: true },
+ comment: {type: String, default: '', trim: true },
+ participants: [],
+ value: { type: Number, defailt: 0 },
+ file: { type: String, default: '', trim: true },
currency: { type: String, default: 'kr', trim: true },
- public: { type: String, default: 'invite-only' },
created: { type: Date, default: Date.now },
- updated: { type: Date, default: Date.now },
- shortURL: { type: String, unique: true }
+ updated: { type: Date, default: Date.now }
});
-// the four validations below only apply if you are signing up traditionally
-ProjectSchema.path('name').validate(function(name) {
- // if you're authenticated by any of the oauth strategies (facebook, twitter), don't validate
- return name.length;
-}, 'Project name cannot be blank');
+pPostSchema.path('what').validate(function(name) {
+ return what.length;
+}, 'You need to name the expense');
-ProjectSchema.pre('save', function(next) {
- if (this.shortURL !== undefined) return next();
- var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
- this.shortURL = '';
- for (var i = 0; i < 6; i++) {
- var x = Math.floor(Math.random() * chars.length);
- this.shortURL += chars.charAt(x);
- }
- console.log('SHORT: ' + this.shortURL);
- next();
-});
-
-
-
-ProjectSchema.statics = {
-
- log: function() {
- console.log('wat. wat logged this');
- },
+pPostSchema.statics = {
/**
- * Find project by id
+ * Find post by id
*
* @param {ObjectId} id
* @param {Function} callback
@@ -64,4 +47,4 @@ ProjectSchema.statics = {
}
-mongoose.model('Project', ProjectSchema);
+mongoose.model('pPost', pPostSchema);