aboutsummaryrefslogtreecommitdiff
path: root/server/models
diff options
context:
space:
mode:
authorMateja <mail@matejamaric.com>2021-07-11 13:32:43 +0200
committerMateja <mail@matejamaric.com>2021-07-11 13:32:43 +0200
commit3fbd440fe39a2677a12c234f06aaa1bae6a197a4 (patch)
treeb27e26d567a5e8106d597a84fd1d664e61a08cd8 /server/models
parent54677c68f50b7c105a1f6cc5e9593877781fc8d6 (diff)
downloadmevn-ecommerce-3fbd440fe39a2677a12c234f06aaa1bae6a197a4.tar.gz
mevn-ecommerce-3fbd440fe39a2677a12c234f06aaa1bae6a197a4.zip
Added Product routes, model and boilerplate controller.
Diffstat (limited to 'server/models')
-rw-r--r--server/models/Product.js26
-rw-r--r--server/models/User.js4
2 files changed, 30 insertions, 0 deletions
diff --git a/server/models/Product.js b/server/models/Product.js
new file mode 100644
index 0000000..f825a8b
--- /dev/null
+++ b/server/models/Product.js
@@ -0,0 +1,26 @@
+const mongoose = require('mongoose');
+
+const ProductSchema = new mongoose.Schema({
+ name: {
+ type: String,
+ required: [true, "Product must have a name."],
+ maxLength: [100, "Product name can't have more then 100 characters."]
+ },
+ description: {
+ type: String,
+ required: false
+ },
+ imagePath: {
+ type: String,
+ required: false,
+ maxLength: [256, "Product's image path can't have more then 256 characters."]
+ },
+ price: {
+ type: Number,
+ required: [true, "Product must have a price."]
+ }
+});
+
+const ProductModel = new mongoose.model('Product', ProductSchema);
+
+module.exports = ProductModel;
diff --git a/server/models/User.js b/server/models/User.js
index 294c016..e508f4c 100644
--- a/server/models/User.js
+++ b/server/models/User.js
@@ -34,6 +34,10 @@ const UserSchema = new mongoose.Schema({
type: String,
required: [true, "You need to provide a password."],
},
+ admin: {
+ type: Boolean,
+ default: false
+ }
});
const UserModel = new mongoose.model('User', UserSchema);