diff --git a/controllers/customerController.js b/controllers/customerController.js index 9dd66d7..6870eeb 100644 --- a/controllers/customerController.js +++ b/controllers/customerController.js @@ -20,7 +20,7 @@ exports.getVendors = asyncHandler(async (req, res) => { } = req.query; const filters = {}; if (primary_location) { - filters.location_served = { $in: [primary_location] }; + filters.supported_location = { $in: [primary_location] }; } if (tag) { filters.tags = { $in: [tag] }; @@ -39,7 +39,7 @@ exports.getVendors = asyncHandler(async (req, res) => { }); } - const vendors = await Vendor.find({...filters, status: 'active'}) + const vendors = await Vendor.find({ ...filters, status: "active" }) .sort(sortOptions) .skip((page - 1) * pageSize) .limit(pageSize); @@ -183,3 +183,43 @@ exports.getItem = asyncHandler(async (req, res) => { return res.status(500).json({ error: "Internal Server Error" }); } }); + +//@desc Search Restaurants +//@route GET /api/customer/search/restaurants +//@access public +exports.searchRestaurants = asyncHandler(async (req, res) => { + const searchTerm = req.query.restaurantName; + + if (!searchTerm) { + return res.status(400).json({ error: "Search term is required" }); + } + try { + const restaurants = await Vendor.find({ + restaurantName: { $regex: searchTerm, $options: "i" }, + }); + return res.status(200).json(restaurants); + } catch (error) { + return res.status(500).json({ error: "Internal Server Error" }); + } +}); + +//@desc Search Menu Items +//@route GET /api/customer/search/menuitems +//@access public + +exports.searchMenuItems = asyncHandler(async (req, res) => { + const itemName = req.query.itemName; + + if (!itemName) { + return res.status(400).json({ error: "Item name is required" }); + } + + try { + const menuItems = await MenuItem.find({ + name: { $regex: itemName, $options: "i" }, + }); + return res.status(200).json(menuItems); + } catch (error) { + return res.status(500).json({ error: "Internal Server Error" }); + } +}); diff --git a/models/vendor.model.js b/models/vendor.model.js index 701db11..8b0d1e4 100644 --- a/models/vendor.model.js +++ b/models/vendor.model.js @@ -55,6 +55,10 @@ const vendorSchema = new Schema( ], images: [String], tags: [String], + is_veg: { + type: Boolean, + default: false, + }, }, { timestamps: true } ); diff --git a/routes/customerRoutes.js b/routes/customerRoutes.js index 40a904f..cc73341 100644 --- a/routes/customerRoutes.js +++ b/routes/customerRoutes.js @@ -5,7 +5,9 @@ const { getVendorById, getCartPrice, getVendorDetailsById, - getItem + getItem, + searchRestaurants, + searchMenuItems, } = require("../controllers/customerController"); router.get("/vendors", getVendors); @@ -18,4 +20,8 @@ router.get("/cartprice", getCartPrice); router.get("/getItem", getItem); +router.get("/searchRestaurant", searchRestaurants); + +router.get("/searchItem", searchMenuItems); + module.exports = router;