Skip to content

Instantly share code, notes, and snippets.

@dstollie
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dstollie/aecf54754aaa53f4fdf1 to your computer and use it in GitHub Desktop.
Save dstollie/aecf54754aaa53f4fdf1 to your computer and use it in GitHub Desktop.
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));
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