1
0

Video 86: Data Validation and Sanitization: Part II

This commit is contained in:
JayWll 2020-02-22 14:45:03 -07:00
parent 3bd2ece69b
commit a340b108f1

View File

@ -23,6 +23,17 @@ const User = mongoose.model('User', {
} }
} }
}, },
password: {
type: String,
required: true,
minlength: 7,
trim: true,
validate(value) {
if (value.toLowerCase().includes('password')) {
throw new Error('Password cannot contain "password"')
}
}
},
age: { age: {
type: Number, type: Number,
default: 0, default: 0,
@ -34,33 +45,36 @@ const User = mongoose.model('User', {
} }
}) })
const me = new User({ // const me = new User({
name: ' Jason ', // name: ' Jason ',
email: 'J@SON-WILLIAMS.CA ' // email: 'J@SON-WILLIAMS.CA ',
}) // password: 'testpassw0rd'
me.save().then(() => {
console.log(me)
}).catch((error) => {
console.log('Error!', error)
})
const Task = mongoose.model('Task', {
description: {
type: String
},
completed: {
type: Boolean
}
})
// const task = new Task({
// description: 'Learn the Mongoose library',
// completed: false
// }) // })
// //
// task.save().then(() => { // me.save().then(() => {
// console.log(task); // console.log(me)
// }).catch((error) => { // }).catch((error) => {
// console.log('Error!', error) // console.log('Error!', error)
// }) // })
const Task = mongoose.model('Task', {
description: {
type: String,
required: true,
trim: true
},
completed: {
type: Boolean,
default: false
}
})
const task = new Task({
description: ' Eat lunch '
})
task.save().then(() => {
console.log(task);
}).catch((error) => {
console.log('Error!', error)
})