diff --git a/db.js b/db.js index f98ae83..6f1d550 100644 --- a/db.js +++ b/db.js @@ -15,4 +15,10 @@ var Image = new Schema({ });   mongoose.model( 'Image', Image ); + +//Image.schema.path('desc').validate(function (value) { + // example: //return /blue|green|white|red|orange|periwinkle/i.test(value); + //return (value.split(' ').length > 1000); +//}, 'Description must be less than 1000 words'); + mongoose.connect( 'mongodb://localhost/infragram' ); diff --git a/routes/index.js b/routes/index.js index 9814efc..22fd05e 100644 --- a/routes/index.js +++ b/routes/index.js @@ -53,6 +53,10 @@ exports.create = function ( req, res ){ src: req.body.src, updated_at : Date.now(), }).save( function( err, todo, count ){ + // if err, redirect to a filled-out form of the data, with validation errors + // ...i don't yet know how to do this, but here are some relevant things: + //if (err) return handleError(err); + //err.errors.desc.type // <= 'Description must be less than 1000 words' res.redirect( '/' ); }); };