challenges: WIP beginning challenges feature. some basic CRUD & some

basic subscribe / unsubscribe functional (but buggy)
This commit is contained in:
Tyler Renelle
2013-10-26 17:24:45 -07:00
parent e45d8307e7
commit fa25f3d300
16 changed files with 755 additions and 43 deletions

33
src/models/challenge.js Normal file
View File

@@ -0,0 +1,33 @@
var mongoose = require("mongoose");
var Schema = mongoose.Schema;
var helpers = require('habitrpg-shared/script/helpers');
var _ = require('lodash');
var TaskSchema = require('./task').schema;
var ChallengeSchema = new Schema({
_id: {type: String, 'default': helpers.uuid},
name: String,
description: String,
habits: [TaskSchema],
dailys: [TaskSchema],
todos: [TaskSchema],
rewards: [TaskSchema],
leader: {type: String, ref: 'User'},
group: {type: String, ref: 'Group'},
// FIXME remove below, we don't need it since every time we load a challenge, we'll load it with the group ref. we don't need to look up challenges by type
//type: group.type, //type: {type: String,"enum": ['guild', 'party']},
//id: group._id
//},
timestamp: {type: Date, 'default': Date.now},
members: [{type: String, ref: 'User'}]
});
ChallengeSchema.virtual('tasks').get(function () {
var tasks = this.habits.concat(this.dailys).concat(this.todos).concat(this.rewards);
var tasks = _.object(_.pluck(tasks,'id'), tasks);
return tasks;
});
module.exports.schema = ChallengeSchema;
module.exports.model = mongoose.model("Challenge", ChallengeSchema);