diff --git a/src/controllers/user.js b/src/controllers/user.js index 1d7414695a..6850d21858 100644 --- a/src/controllers/user.js +++ b/src/controllers/user.js @@ -70,7 +70,6 @@ function deleteTask(user, task) { function addTask(user, task) { task = helpers.taskDefaults(task); - task._id = task.id; user[task.type+'s'].unshift(task); return task; } diff --git a/src/models/challenge.js b/src/models/challenge.js index 6ad5725168..395a927240 100644 --- a/src/models/challenge.js +++ b/src/models/challenge.js @@ -41,7 +41,7 @@ ChallengeSchema.methods.toJSON = function(){ doc._isMember = this._isMember; _.each(['habits','dailys','todos','rewards'], function(type){ _.each(doc[type],function(task){ - task.id = task._id; + task.id = task.id || task._id; }) }) return doc; diff --git a/src/models/task.js b/src/models/task.js index 64d8f6914c..dcbea7db95 100644 --- a/src/models/task.js +++ b/src/models/task.js @@ -12,9 +12,9 @@ var _ = require('lodash'); // Task Schema // ----------- -var TaskSchema = new Schema({ +var TaskSchema = { _id:{type: String,'default': helpers.uuid}, - history: [{date:Date, value:Number}], + history: Array, // [{date:Date, value:Number}], // this causes major performance problems text: String, notes: {type: String, 'default': ''}, tags: {type: Schema.Types.Mixed, 'default': {}}, //{ "4ddf03d9-54bd-41a3-b011-ca1f1d2e9371" : true }, @@ -32,21 +32,6 @@ var TaskSchema = new Schema({ winner: String // user.profile.name // group: {type: 'Strign', ref: 'Group'} // if we restore this, rename `id` above to `challenge` } -}, { - minimize: 'false' -}); +}; -/** - * FIXME why is this function is never called? Instead we're doing a _.each(obj.tasks) in challenges & user - */ -TaskSchema.methods.toJSON = function() { - var doc = this.toObject(); - doc.id = doc._id; - return doc; -} -TaskSchema.virtual('id').get(function(){ - return this._id; -}) - -module.exports.schema = TaskSchema; -module.exports.model = mongoose.model("Task", TaskSchema); \ No newline at end of file +module.exports.schema = TaskSchema; \ No newline at end of file diff --git a/src/models/user.js b/src/models/user.js index 48ff54f540..697e3abe88 100644 --- a/src/models/user.js +++ b/src/models/user.js @@ -83,8 +83,8 @@ var UserSchema = new Schema({ rest: {type: Boolean, 'default': false} // fixme - change to preferences.resting once we're off derby }, history: { - exp: [{date: Date, value: Number}], - todos: [{data: Date, value: Number}] + exp: Array, // [{date: Date, value: Number}], // big peformance issues if these are defined + todos: Array //[{data: Date, value: Number}] // big peformance issues if these are defined }, /* FIXME remove?*/ @@ -209,10 +209,9 @@ UserSchema.methods.toJSON = function() { doc.filters = {}; doc._tmp = this._tmp; // be sure to send down drop notifs - // TODO why isnt' this happening automatically given the TaskSchema.methods.toJSON above? _.each(['habits','dailys','todos','rewards'], function(type){ _.each(doc[type],function(task){ - task.id = task._id; + task.id = task.id || task._id; }) })