mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
Revert "[#1711] back to Schema.Types.Mixed for user.tasks, this makes me sad :("
This reverts commit c0292d0842.
This commit is contained in:
@@ -2,6 +2,7 @@ var mongoose = require("mongoose");
|
||||
var Schema = mongoose.Schema;
|
||||
var helpers = require('habitrpg-shared/script/helpers');
|
||||
var _ = require('lodash');
|
||||
var TaskSchema = require('./task').schema;
|
||||
var Group = require('./group').model;
|
||||
|
||||
var ChallengeSchema = new Schema({
|
||||
@@ -9,10 +10,10 @@ var ChallengeSchema = new Schema({
|
||||
name: String,
|
||||
shortName: String,
|
||||
description: String,
|
||||
habits: [Schema.Types.Mixed],
|
||||
dailys: [Schema.Types.Mixed],
|
||||
todos: [Schema.Types.Mixed],
|
||||
rewards: [Schema.Types.Mixed],
|
||||
habits: [TaskSchema],
|
||||
dailys: [TaskSchema],
|
||||
todos: [TaskSchema],
|
||||
rewards: [TaskSchema],
|
||||
leader: {type: String, ref: 'User'},
|
||||
group: {type: String, ref: 'Group'},
|
||||
timestamp: {type: Date, 'default': Date.now},
|
||||
@@ -30,11 +31,6 @@ ChallengeSchema.virtual('tasks').get(function () {
|
||||
// FIXME this isn't always triggered, since we sometimes use update() or findByIdAndUpdate()
|
||||
// @see https://github.com/LearnBoost/mongoose/issues/964
|
||||
ChallengeSchema.pre('save', function(next){
|
||||
// @see comment in user.js pre(save)
|
||||
this.markModified('habits');
|
||||
this.markModified('dailys');
|
||||
this.markModified('todos');
|
||||
this.markModified('rewards');
|
||||
this.memberCount = _.size(this.members);
|
||||
next()
|
||||
})
|
||||
@@ -43,11 +39,11 @@ ChallengeSchema.methods.toJSON = function(){
|
||||
var doc = this.toObject();
|
||||
doc.memberCount = doc.members ? _.size(doc.members) : doc.memberCount; // @see pre('save') comment above
|
||||
doc._isMember = this._isMember;
|
||||
// _.each(['habits','dailys','todos','rewards'], function(type){
|
||||
// _.each(doc[type],function(task){
|
||||
// task.id = task._id || task.id;
|
||||
// })
|
||||
// })
|
||||
_.each(['habits','dailys','todos','rewards'], function(type){
|
||||
_.each(doc[type],function(task){
|
||||
task.id = task._id;
|
||||
})
|
||||
})
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user