aboutsummaryrefslogtreecommitdiff
path: root/models/user.js
diff options
context:
space:
mode:
Diffstat (limited to 'models/user.js')
-rw-r--r--models/user.js37
1 files changed, 33 insertions, 4 deletions
diff --git a/models/user.js b/models/user.js
index 3751aae..525e5df 100644
--- a/models/user.js
+++ b/models/user.js
@@ -1,10 +1,39 @@
const mongoose = require('mongoose');
+const validator = require('validator');
const userSchema = new mongoose.Schema({
- firstname: {type: String, required: true},
- lastname: {type: String, required: true},
- email: {type: String, required: true},
- password: {type: String, required: true},
+ firstname: {
+ type: String,
+ required: [true, "You need to provide your first name."],
+ maxLength: [32, "You can't have a first name longer than 32 characters."],
+ validate: {
+ validator: validator.isAlpha,
+ message: props => "Your first name can only contain characters."
+ }
+ },
+ lastname: {
+ type: String,
+ required: [true, "You need to provide your last name."],
+ maxLength: [32, "You can't have a last name longer than 32 characters."],
+ validate: {
+ validator: validator.isAlpha,
+ message: props => "Your last name can only contain characters."
+ }
+ },
+ email: {
+ type: String,
+ required: [true, "You need to provide an email."],
+ maxLength: [100, "You can't have a email longer than 100 characters."],
+ validate: {
+ validator: validator.isEmail,
+ message: props => "Email is not valid."
+ }
+ },
+ password: {
+ type: String,
+ required: [true, "You need to provide a password."],
+ maxLength: [100, "You can't have a password longer than 100 characters."]
+ },
});
const userModel = new mongoose.model('user', userSchema);