@feardread/fear 1.1.1 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -128,6 +128,30 @@ exports.getProductStats = tryCatch(async (req, res) => {
128
128
  });
129
129
  });
130
130
 
131
+
132
+ /**
133
+ * Get trending products (latest products with high ratings)
134
+ * @param {Object} req - Express request object
135
+ * @param {Object} res - Express response object
136
+ */
137
+ exports.featured = tryCatch(async (req, res) => {
138
+ const featuredProducts = await Product.find({isFeatured: true});
139
+ console.log('featured results = ', featuredProducts);
140
+ if (featuredProducts) {
141
+ return res.status(200).json({ success: true, result: featuredProducts })
142
+ }
143
+
144
+
145
+ /*
146
+ return res.status(200).json({
147
+ success: true,
148
+ message: `Top ${featuredProducts.length} trending products`,
149
+ result: featuredProducts,
150
+ count: featuredProducts.length
151
+ });
152
+ */
153
+ });
154
+
131
155
  exports.productSearch = tryCatch(async (req, res) => {
132
156
  return await productSearch(req.query, Product)
133
157
  .then((result) => {
package/models/product.js CHANGED
@@ -7,11 +7,13 @@ const productSchema = new mongoose.Schema({
7
7
  slug: { type: String, required: false, unique: true, lowercase: true },
8
8
  description: { type: String, required: true },
9
9
  price: { type: Number, required: true },
10
+ discount: { type: Number, required: false, default: 0 },
10
11
  category: { type: mongoose.Schema.Types.String, ref: "Category" },
11
12
  brand: { type: mongoose.Schema.Types.String, ref: "Brand" , required: false },
12
13
  quantity: { type: Number, required: true },
13
14
  sold: { type: Number, default: 0 },
14
15
  reviews: [Review.schema],
16
+ isFeatured: {type: Boolean, required: false, default: false},
15
17
  images: [{
16
18
  public_id: String,
17
19
  url: String
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feardread/fear",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/routes/product.js CHANGED
@@ -11,8 +11,8 @@ module.exports = (fear) => {
11
11
  .get("/edit/:id", Product.read);
12
12
 
13
13
  router.route("/search").post(Product.search);
14
- router.route('/search/all').get(Product.productSearch);
15
- router.route("/one").get(handler.async(Product.read));
14
+ router.route("/featured").get(Product.featured);
15
+ router.route("/one").get(Product.read);
16
16
  router.route("/:id")
17
17
  .get(Product.read)
18
18
  .put(Product.update)