add markdown to existing comments.

This commit is contained in:
Andre Casey
2013-09-19 12:51:51 -07:00
committed by Tyler Renelle
parent cbc12b0077
commit 978497656b

View File

@@ -1,9 +1,19 @@
// User.js
// =======
// Defines the user data model (schema) for use via the API.
// Dependencies
// ------------
var mongoose = require("mongoose"); var mongoose = require("mongoose");
var Schema = mongoose.Schema; var Schema = mongoose.Schema;
var helpers = require('habitrpg-shared/script/helpers'); var helpers = require('habitrpg-shared/script/helpers');
var _ = require('lodash'); var _ = require('lodash');
// User Schema
// -----------
var UserSchema = new Schema({ var UserSchema = new Schema({
// ### UUID and API Token
_id: { _id: {
type: String, type: String,
'default': helpers.uuid 'default': helpers.uuid
@@ -13,7 +23,8 @@ var UserSchema = new Schema({
'default': helpers.uuid 'default': helpers.uuid
}, },
//We want to know *every* time an object updates. Mongoose uses __v to designate when an object contains arrays which // ### Mongoode Update Object
// We want to know *every* time an object updates. Mongoose uses __v to designate when an object contains arrays which
// have been updated (http://goo.gl/gQLz41), but we want *every* update // have been updated (http://goo.gl/gQLz41), but we want *every* update
_v: { _v: {
type: Number, type: Number,
@@ -121,33 +132,38 @@ var UserSchema = new Schema({
eggs: [ eggs: [
{ {
dialog: String, //You've found a Wolf Egg! Find a hatching potion to pour on this egg, and one day it will hatch into a loyal pet // example: You've found a Wolf Egg! Find a hatching potion to pour on this egg, and one day it will hatch into a loyal pet
name: String, // Wolf dialog: String,
notes: String, //Find a hatching potion to pour on this egg, and one day it will hatch into a loyal pet. // example: Wolf
text: String, // Wolf name: String,
//type: String, //Egg // this is forcing mongoose to return object as "[object Object]", but I don't think this is needed anyway? // example: Find a hatching potion to pour on this egg, and one day it will hatch into a loyal pet.
value: Number //3 notes: String,
// example: Wolf
text: String,
/* type: String, //Egg // this is forcing mongoose to return object as "[object Object]", but I don't think this is needed anyway? */
// example: 3
value: Number
} }
], ],
hatchingPotions: Array, //["Base", "Skeleton",...] hatchingPotions: Array, // ["Base", "Skeleton",...]
lastDrop: { lastDrop: {
date: {type: Date, 'default': Date.now}, date: {type: Date, 'default': Date.now},
count: {type: Number, 'default': 0} count: {type: Number, 'default': 0}
}, },
/* ["BearCub-Base", "Cactus-Base", ...]*/ // ["BearCub-Base", "Cactus-Base", ...]
pets: Array pets: Array
}, },
/*FIXME store as Date?*/ // FIXME store as Date?
lastCron: { lastCron: {
type: Date, type: Date,
'default': Date.now 'default': Date.now
}, },
/* FIXME remove?*/ // FIXME remove?
party: { party: {
//party._id //FIXME make these populate docs? //party._id // FIXME make these populate docs?
current: String, // party._id current: String, // party._id
invitation: String, // party._id invitation: String, // party._id
lastMessageSeen: String, lastMessageSeen: String,
@@ -167,7 +183,7 @@ var UserSchema = new Schema({
blurb: String, blurb: String,
imageUrl: String, imageUrl: String,
name: String, name: String,
websites: Array //["http://ocdevel.com" ] websites: Array // styled like --> ["http://ocdevel.com" ]
}, },
stats: { stats: {
hp: Number, hp: Number,
@@ -177,15 +193,15 @@ var UserSchema = new Schema({
}, },
tags: [ tags: [
{ {
/* FIXME use refs?*/ // FIXME use refs?
id: String, id: String,
name: String name: String
} }
], ],
/*
# We can't define `tasks` until we move off Derby, since Derby requires dictionary of objects. When we're off, migrate // ### Tasks Definition
# to array of subdocs // We can't define `tasks` until we move off Derby, since Derby requires dictionary of objects. When we're off, migrate
*/ // to array of subdocs
tasks: Schema.Types.Mixed tasks: Schema.Types.Mixed
/* /*
@@ -208,12 +224,13 @@ var UserSchema = new Schema({
strict: true strict: true
}); });
/** // Legacy Derby Function?
Derby requires a strange storage format for somethign called "refLists". Here we hook into loading the data, so we // ----------------------
can provide a more "expected" storage format for our various helper methods. Since the attributes are passed by reference, // Derby requires a strange storage format for somethign called "refLists". Here we hook into loading the data, so we
the underlying data will be modified too - so when we save back to the database, it saves it in the way Derby likes. // can provide a more "expected" storage format for our various helper methods. Since the attributes are passed by reference,
This will go away after the rewrite is complete // the underlying data will be modified too - so when we save back to the database, it saves it in the way Derby likes.
*/ // This will go away after the rewrite is complete
function transformTaskLists(doc) { function transformTaskLists(doc) {
_.each(['habit', 'daily', 'todo', 'reward'], function(type) { _.each(['habit', 'daily', 'todo', 'reward'], function(type) {
// we use _.transform instead of a simple _.where in order to maintain sort-order // we use _.transform instead of a simple _.where in order to maintain sort-order
@@ -246,10 +263,9 @@ UserSchema.methods.toJSON = function() {
return doc; return doc;
}; };
/* // FIXME - since we're using special @post('init') above, we need to flag when the original path was modified.
# FIXME - since we're using special @post('init') above, we need to flag when the original path was modified. // Custom setter/getter virtuals?
# Custom setter/getter virtuals?
*/
UserSchema.pre('save', function(next) { UserSchema.pre('save', function(next) {
this.markModified('tasks'); this.markModified('tasks');
//our own version incrementer //our own version incrementer