Created
January 16, 2013 23:57
-
-
Save astrotars/4552176 to your computer and use it in GitHub Desktop.
sweepstakes schema
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
| /** | |
| * Require Dependencies | |
| */ | |
| var Submission = require('./submission'); | |
| /** | |
| * Define Variables | |
| */ | |
| var Schema = mongoose.Schema, | |
| ObjectId = Schema.ObjectId; | |
| /** | |
| * Schema Definition | |
| */ | |
| var sweepstakesSchema = new Schema({ | |
| client_id: { | |
| type: Schema.Types.ObjectId, | |
| ref: 'Client', | |
| index: true, | |
| required: true | |
| }, | |
| name: { | |
| type: String, | |
| trim: true, | |
| default: 'Sweepstakes', | |
| }, | |
| design: { | |
| images: { | |
| type: [], | |
| default: [] | |
| }, | |
| elements: { | |
| type: [], | |
| default: [] | |
| } | |
| }, | |
| enabled: { | |
| type: Boolean, | |
| default: false | |
| }, | |
| schedule: { | |
| start: { | |
| type: Date, | |
| default: Date.now | |
| }, | |
| end: { | |
| type: Date, | |
| default: Date.now | |
| } | |
| }, | |
| submissions: { | |
| type: Number, | |
| default: 0 | |
| } | |
| }); | |
| /** | |
| * Custom Middleware | |
| */ | |
| // invoked on call to the remove(); | |
| sweepstakesSchema.pre('remove', function(next) { | |
| // clean up dependencies | |
| Submission.remove({ sweepstakes_id: this._id }).exec(); | |
| next(); | |
| }); | |
| /** | |
| * Third Party Plugins | |
| */ | |
| sweepstakesSchema.plugin(mongooseQuery); | |
| sweepstakesSchema.plugin(mongooseCreatedModified, {index: true}); | |
| /** | |
| * Export Model for Use Within Routes | |
| */ | |
| module.exports = mongoose.model('Sweepstakes', sweepstakesSchema); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment