diff --git a/server/controllers/canteenController.js b/server/controllers/canteenController.js index fc4e569..e36b07c 100644 --- a/server/controllers/canteenController.js +++ b/server/controllers/canteenController.js @@ -212,6 +212,74 @@ const updateCanteen = async (req, res, next) => { res.status(500).json({ success: false, error: "Internal Server Error" }); } }; +//controller to update Canteen FoddItem Details + + +// Controller function to update a breakfast dish +const updateBreakfastDish = asyncHandler(async (req, res, next) => { + const canteenId = req.params.id; + const { dishId, dish } = req.body; + + try { + const updatedDish = await Breakfast.findOneAndUpdate( + { _id: dishId, canteen: canteenId }, + { $set: { dish } }, + { new: true } + ).exec(); + + if (!updatedDish) { + return res.status(404).json({ message: 'Dish not found' }); + } + + res.json({ message: 'Dish updated successfully', data: updatedDish }); + } catch (error) { + res.status(500).json({ success: false, error: error.message }); + } +}); +//Controller to update Lunch +const updateLunchDish = asyncHandler(async (req, res, next) => { + const canteenId = req.params.id; + const { dishId, dish } = req.body; + + try { + const updatedDish = await Lunch.findOneAndUpdate( + { _id: dishId, canteen: canteenId }, + { $set: { dish } }, + { new: true } + ).exec(); + + if (!updatedDish) { + return res.status(404).json({ message: 'Dish not found' }); + } + + res.json({ message: 'Dish updated successfully', data: updatedDish }); + } catch (error) { + res.status(500).json({ success: false, error: error.message }); + } +}); +//Controller to update dinner + +const updateDinnerDish = asyncHandler(async (req, res, next) => { + const canteenId = req.params.id; + const { dishId, dish } = req.body; + + try { + const updatedDish = await Dinner.findOneAndUpdate( + { _id: dishId, canteen: canteenId }, + { $set: { dish } }, + { new: true } + ).exec(); + + if (!updatedDish) { + return res.status(404).json({ message: 'Dish not found' }); + } + + res.json({ message: 'Dish updated successfully', data: updatedDish }); + } catch (error) { + res.status(500).json({ success: false, error: error.message }); + } +}); + module.exports = { getCanteenDashboard, @@ -226,4 +294,7 @@ module.exports = { getLunch, getDinner, updateCanteen, + updateBreakfastDish, + updateLunchDish, + updateDinnerDish, }; diff --git a/server/routes/canteen.js b/server/routes/canteen.js index 28ed8db..83e6242 100644 --- a/server/routes/canteen.js +++ b/server/routes/canteen.js @@ -41,4 +41,9 @@ router.delete('/:id/dinner/remove',auth,isCanteen, canteenController.removeDinne //router to update profile router.put('/:id/update', auth, isCanteen, multerUploads, canteenController.updateCanteen); +// New update routes +router.put('/:id/breakfast/updateitem',auth,isCanteen, canteenController.updateBreakfastDish); +router.put('/:id/lunch/updateitem',auth,isCanteen, canteenController.updateLunchDish); +router.put('/:id/dinner/updateitem',auth,isCanteen, canteenController.updateDinnerDish); + module.exports = router; diff --git a/src/components/Modal-update.js b/src/components/Modal-update.js new file mode 100644 index 0000000..37e99df --- /dev/null +++ b/src/components/Modal-update.js @@ -0,0 +1,40 @@ + +import React, { useState } from "react"; + +const Modalupdate = ({ dish, onUpdate, onCancel }) => { + const [updatedDish, setUpdatedDish] = useState(dish); + + const handleUpdate = () => { + onUpdate(updatedDish); + }; + + return ( +