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: {
type: Number,
default: 0,
@ -34,33 +45,36 @@ const User = mongoose.model('User', {
}
})
const me = new User({
name: ' Jason ',
email: 'J@SON-WILLIAMS.CA '
})
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
// const me = new User({
// name: ' Jason ',
// email: 'J@SON-WILLIAMS.CA ',
// password: 'testpassw0rd'
// })
//
// task.save().then(() => {
// console.log(task);
// me.save().then(() => {
// console.log(me)
// }).catch((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)
})