Skip to content

Commit

Permalink
Revert "added searchProduct and filterProduct controllers in product …
Browse files Browse the repository at this point in the history
…controllers"

This reverts commit ff197d7.
  • Loading branch information
ArtiGaund committed May 12, 2024
1 parent ff197d7 commit af16d08
Show file tree
Hide file tree
Showing 7 changed files with 318 additions and 1,898 deletions.
3 changes: 0 additions & 3 deletions controllers/customerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ exports.registerCustomer = catchAsyncErrors(async (req, res, next) => {
url: "ThisisSecureUrl"
},
});
if(!customer){
return next(new ErrorHandler("Invalid email or password", 401));
}

sendToken(customer, 201, res);
});
Expand Down
42 changes: 0 additions & 42 deletions controllers/productController.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,45 +81,3 @@ exports.deleteProduct = catchAsyncErrors(async (req, res, next) => {
});
});

// SEARCH PRODUCT

exports.searchProduct = catchAsyncErrors(async (req, res, next) => {
const product = await Product.findById(req.params.id);

if (!product){
return next(new ErrorHandler("Product not found", 404));
}
res.status(200).json({
success: true,
product,
});
});

// FILTER PRODUCT

exports.filterProduct = catchAsyncErrors(async (req, res, next) => {
const { category, numOfReviews } = req.body;

if(!category || !numOfReviews){
return next(new ErrorHandler("Please select either category or number of reviews ", 404));
}

let filterCriteria = {};

if(category){
filterCriteria.category = category;
}
if(numOfReviews){
filterCriteria.numOfReviews = numOfReviews;
}

const products = await Product.find(filterCriteria);
if(!products){
return next(new ErrorHandler("Error while fetching products", 404));
}

res.status(200).json({
success: true,
products,
});
});
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const errorMiddleware = require("./middlewares/error.js");
dotenv.config({path : `.env`})

/*MONGODB CONNECTION START*/
const MONGO_URL = process.env.MONGO_URL;
const MONGO_URL = process.env.MONGO_URL ;

mongoose.connect(MONGO_URL, {
useNewUrlParser: true,
Expand Down
2 changes: 1 addition & 1 deletion models/productSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const productSchema = mongoose.Schema({
required: [true, "Please Enter Product Description"],
},
author:{
type: String,
type: String,
required: [true, "Please Enter Product Author"],
},
price: {
Expand Down
Loading

0 comments on commit af16d08

Please sign in to comment.