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
| var Schema = mongoose.Schema, | |
| ObjectId = Schema.ObjectId; | |
| var submissionSchema = new Schema({ | |
| sweepstakes_id: { | |
| type: Schema.Types.ObjectId, | |
| ref: 'Sweepstakes' | |
| }, | |
| email: { | |
| type: String, |
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
| /** | |
| * Clients | |
| */ | |
| app.post('/clients', routes.clients.create); | |
| app.get('/clients', routes.clients.list); | |
| app.get('/clients/:client_id', routes.clients.get); | |
| app.get('/clients/:client_id/sweepstakes', routes.sweepstakes.get); | |
| app.put('/clients/:client_id', routes.clients.update); |
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 Routes | |
| */ | |
| var requireDir = require('require-dir'), | |
| routes = requireDir('.'); | |
| /** | |
| * Clients | |
| */ |
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
| var Schema = mongoose.Schema, | |
| ObjectId = Schema.ObjectId; | |
| var userSchema = new Schema({ | |
| email: { | |
| type: String, | |
| index: true, | |
| unique: true | |
| }, | |
| password: String, |
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
| { | |
| "design": { | |
| "images": [ | |
| { | |
| "enabled": true, | |
| "url": "https://sweeps-dev.s3.amazonaws.com/a9b0d9a0ac9af495c88ada6695152ef4.png", | |
| "height": 1000, | |
| "width": 810 | |
| } | |
| ], |
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
| // assign update client to var | |
| var updateclient = req.body; | |
| remove default to avoid mongo errors (like Mod on _id not allowed) | |
| delete updateclient._id; | |
| Client.update({_id: req.params.client_id}, updateclient, {}, function(err, client) { | |
| if (err) | |
| return next(new restify.InternalError(err)); |
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
| domain.js:66 | |
| throw er; | |
| ^ | |
| TypeError: Object function model(doc, fields, skipId) { | |
| if (!(this instanceof model)) | |
| return new model(doc, fields, skipId); | |
| Model.call(this, doc, fields, skipId); | |
| } has no method 'pre' | |
| at Promise.exports.destroy (/Applications/MAMP/htdocs/apps/labs/sweeps-api/routes/clients.js:82:10) | |
| at Promise.addBack (/Applications/MAMP/htdocs/apps/labs/sweeps-api/node_modules/mongoose/lib/promise.js:128:8) |
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
| clientSchema.pre('remove', function(next) { | |
| // clean up dependencies | |
| Sweepstakes.remove({client_id: this._id}).exec(); | |
| Submission.remove({client_id: this._id}).exec(); | |
| // remove client id from users | |
| User.update({clients: {$in: [this._id]}}, {$pull: {clients: this._id}}, function(err, numAffected) { | |
| if (err) |
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 Sweepstakes = require('./sweepstakes'); | |
| /** | |
| * Define Variables | |
| */ |
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 | |
| */ |