Last active
August 29, 2015 14:21
-
-
Save dstollie/aecf54754aaa53f4fdf1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AnswerSchema = new SimpleSchema(_.extend({ | |
body: { | |
type: String | |
}, | |
questionId: { | |
type: String | |
}, | |
upvotes: { | |
type: Number, | |
optional: true, | |
defaultValue: 0 | |
}, | |
upvoters: { | |
type: [String], | |
optional: true, | |
defaultValue: [] | |
}, | |
downvotes: { | |
type: Number, | |
optional: true, | |
defaultValue: 0 | |
}, | |
downvoters: { | |
type: [String], | |
optional: true, | |
defaultValue: [] | |
}, | |
right: { | |
type: Boolean, | |
defaultValue: false | |
} | |
}, SchemaDefaults.atDates, SchemaDefaults.currentUser)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SchemaDefaults = {}; | |
SchemaDefaults.atDates = { | |
// Force value to be current date (on server) upon insert | |
// and prevent updates thereafter. | |
createdAt: { | |
type: Date, | |
autoValue: function() { | |
if (this.isInsert) { | |
return new Date; | |
} else if (this.isUpsert) { | |
return {$setOnInsert: new Date}; | |
} else { | |
this.unset(); | |
} | |
} | |
}, | |
// Force value to be current date (on server) upon update | |
// and don't allow it to be set upon insert. | |
updatedAt: { | |
type: Date, | |
autoValue: function() { | |
if (this.isUpdate) { | |
return new Date(); | |
} | |
}, | |
denyInsert: true, | |
optional: true | |
} | |
}; | |
SchemaDefaults.currentUser = { | |
userId: { | |
type: String, | |
autoValue: function() { | |
if(!Fixtures.isLoading()) { | |
if (this.isInsert) { | |
return Meteor.userId(); | |
} else { | |
this.unset(); | |
} | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment