aboutsummaryrefslogtreecommitdiff
path: root/server/models
diff options
context:
space:
mode:
authorMateja <mail@matejamaric.com>2021-07-09 17:13:23 +0200
committerMateja <mail@matejamaric.com>2021-07-09 17:13:23 +0200
commitfd0fafa68d638b729a506ba668165e29eea71a49 (patch)
tree0e857d875f5a534bfa19887d1581806beaa65cb7 /server/models
parent5a55212b17e203c62112214b97c00f0974d3029d (diff)
downloadmevn-ecommerce-fd0fafa68d638b729a506ba668165e29eea71a49.tar.gz
mevn-ecommerce-fd0fafa68d638b729a506ba668165e29eea71a49.zip
Backend boilerplate code...
Diffstat (limited to 'server/models')
-rw-r--r--server/models/User.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/server/models/User.js b/server/models/User.js
new file mode 100644
index 0000000..401fb32
--- /dev/null
+++ b/server/models/User.js
@@ -0,0 +1,40 @@
+const mongoose = require('mongoose');
+const validator = require('validator');
+
+const UserSchema = new mongoose.Schema({
+ 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 => "Provided email is not valid."
+ }
+ },
+ password: {
+ type: String,
+ required: [true, "You need to provide a password."],
+ },
+});
+
+const UserModel = new mongoose.model('User', UserSchema);
+
+module.exports = UserModel;