Skip to content

Commit

Permalink
chore: Merge branch 'main' into ft/discount
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharbansal22 committed Apr 9, 2024
2 parents 53785ff + 18b4eb0 commit 89f562c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
44 changes: 42 additions & 2 deletions controllers/customerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] };
Expand All @@ -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);
Expand Down Expand Up @@ -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" });
}
});
4 changes: 4 additions & 0 deletions models/vendor.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ const vendorSchema = new Schema(
],
images: [String],
tags: [String],
is_veg: {
type: Boolean,
default: false,
},
},
{ timestamps: true }
);
Expand Down
8 changes: 7 additions & 1 deletion routes/customerRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const {
getVendorById,
getCartPrice,
getVendorDetailsById,
getItem
getItem,
searchRestaurants,
searchMenuItems,
} = require("../controllers/customerController");

router.get("/vendors", getVendors);
Expand All @@ -18,4 +20,8 @@ router.get("/cartprice", getCartPrice);

router.get("/getItem", getItem);

router.get("/searchRestaurant", searchRestaurants);

router.get("/searchItem", searchMenuItems);

module.exports = router;

0 comments on commit 89f562c

Please sign in to comment.