diff --git a/task-manager/src/db/mongoose.js b/task-manager/src/db/mongoose.js index d84a814..e5342cd 100644 --- a/task-manager/src/db/mongoose.js +++ b/task-manager/src/db/mongoose.js @@ -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) +})