diff --git a/app/models/note.js b/app/models/note.js index 60f5f7c..e1be838 100644 --- a/app/models/note.js +++ b/app/models/note.js @@ -1,9 +1,14 @@ -var mongoose = require('mongoose'); -var Schema = mongoose.Schema; +const mongoose = require('mongoose'); -var NoteSchema = new Schema({ - title: String, - text: String -}); +const { Schema } = mongoose; -module.exports = mongoose.model('Note', NoteSchema); +const NoteSchema = new Schema({ + title: { + type: String, required: [true, "can't be blank"], + }, + text: { + type: String, required: [true, "can't be blank"], + }, +}, { timestamps: true }); + +module.exports = NoteSchema; diff --git a/app/models/user.js b/app/models/user.js index 97f136f..e0bbbe5 100644 --- a/app/models/user.js +++ b/app/models/user.js @@ -1,25 +1,18 @@ -var mongoose = require('mongoose'); -var Schema = mongoose.Schema; -var bcrypt = require('bcrypt-nodejs'); +const mongoose = require('mongoose'); -var UserSchema = new Schema({ +const { Schema } = mongoose; + +const UserSchema = new Schema({ firstname: { - type: String, - required: true + type: String, required: [true, "can't be blank"], }, lastname: { - type: String, - required: true + type: String, required: [true, "can't be blank"], }, username: { - type: String, - unique: true, - required: true + type: String, lowercase: true, unique: true, required: [true, "can't be blank"], match: [/^[a-zA-Z0-9]+$/, 'is invalid'], index: true, }, - password: { - type: String, - required: true - } -}); + password: String, +}, { timestamps: true }); -module.exports = mongoose.model('User', UserSchema); +module.exports = UserSchema;