aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-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() {