Skip to content

Commit 4eec2ac

Browse files
committed
Merge branch 'main' of https://github.com/jency1/PlantWorld
2 parents c3c61ac + e36aaba commit 4eec2ac

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

Backend/controllers/plantController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ exports.createPlant = async (req, res) => {
4747
} catch (err) {
4848
res.status(400).json({
4949
status: 'fail',
50-
message: 'Invalid data sent',
50+
message: err,
5151
});
5252
}
5353
};

Backend/model/plantModel.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const plantSchema = new mongoose.Schema({
1010
ratingsAverage: {
1111
type: Number,
1212
default: 4.5,
13+
min: [1, 'Rating must be above 1.0'],
14+
max: [5, 'Rating must be below 5.0'],
1315
},
1416
ratingsQuantity: {
1517
type: Number,
@@ -22,7 +24,7 @@ const plantSchema = new mongoose.Schema({
2224
shortDescription: {
2325
type: String,
2426
trim: true,
25-
required: [true, 'A plant must have a description'],
27+
required: [true, 'A plant must have a short description'],
2628
},
2729
description: {
2830
type: String,
@@ -37,6 +39,7 @@ const plantSchema = new mongoose.Schema({
3739
tag: {
3840
type: String,
3941
required: [true, 'A plant must have a tag'],
42+
4043
trim: true,
4144
},
4245
color: {
@@ -58,7 +61,16 @@ const plantSchema = new mongoose.Schema({
5861
},
5962
},
6063
images: [String],
61-
priceDiscount: Number,
64+
priceDiscount: {
65+
type: Number,
66+
validate: {
67+
validator: function (val) {
68+
// this only points to current doc on NEW document creation and not on update
69+
return val < this.price; // Ensure discount is less than the price
70+
},
71+
message: 'Discount price ({VALUE}) should be below the regular price',
72+
},
73+
},
6274
createdAt: {
6375
type: Date,
6476
default: Date.now(),

Backend/package-lock.json

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Backend/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
"dotenv": "^16.4.7",
1515
"express": "^4.21.2",
1616
"mongoose": "^5.13.23",
17-
"morgan": "^1.10.0"
17+
"morgan": "^1.10.0",
18+
"slugify": "^1.6.6",
19+
"validator": "^13.12.0"
1820
}
1921
}

0 commit comments

Comments
 (0)