Skip to content

Commit ac32edd

Browse files
committed
commented-out start on validation, not sure where to display errors yet p-v-o-s#33
1 parent cbfd469 commit ac32edd

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

db.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,10 @@ var Image = new Schema({
1515
});
1616

1717
mongoose.model( 'Image', Image );
18+
19+
//Image.schema.path('desc').validate(function (value) {
20+
// example: //return /blue|green|white|red|orange|periwinkle/i.test(value);
21+
//return (value.split(' ').length > 1000);
22+
//}, 'Description must be less than 1000 words');
23+
1824
mongoose.connect( 'mongodb://localhost/infragram' );

routes/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ exports.create = function ( req, res ){
5353
src: req.body.src,
5454
updated_at : Date.now(),
5555
}).save( function( err, todo, count ){
56+
// if err, redirect to a filled-out form of the data, with validation errors
57+
// ...i don't yet know how to do this, but here are some relevant things:
58+
//if (err) return handleError(err);
59+
//err.errors.desc.type // <= 'Description must be less than 1000 words'
5660
res.redirect( '/' );
5761
});
5862
};

0 commit comments

Comments
 (0)