aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/models/project.js
diff options
context:
space:
mode:
authorDennis Eriksen <dennis.se@gmail.com>2013-04-30 13:28:45 +0200
committerDennis Eriksen <dennis.se@gmail.com>2013-04-30 13:28:45 +0200
commitc0630c6db730ba50ab247435bff14a36a4303e93 (patch)
treeb046ea65ae857d0893da73f2ac8a14b29cc05ce5 /models/project.js
parentmade the dashboard work somewhat better (diff)
downloadDivid-c0630c6db730ba50ab247435bff14a36a4303e93.tar.gz
added shorturl for projects
Diffstat (limited to 'models/project.js')
-rw-r--r--models/project.js18
1 files changed, 17 insertions, 1 deletions
diff --git a/models/project.js b/models/project.js
index 2641fe5..f29c7f8 100644
--- a/models/project.js
+++ b/models/project.js
@@ -13,7 +13,8 @@ var ProjectSchema = new Schema({
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 }
+ updated: { type: Date, default: Date.now },
+ shortURL: { type: String, unique: true }
});
// the four validations below only apply if you are signing up traditionally
@@ -23,6 +24,21 @@ ProjectSchema.path('name').validate(function(name) {
return name.length;
}, 'Project name cannot be blank');
+
+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() {