diff --git a/pages/admin/_branch/foods/_food.vue b/pages/admin/_branch/foods/_food.vue index 3772695..e4d4260 100644 --- a/pages/admin/_branch/foods/_food.vue +++ b/pages/admin/_branch/foods/_food.vue @@ -122,6 +122,19 @@

{{ validation.index.msg }}

+ + + + انتخاب منو + + + + + +

{{ validation.menuType_id.msg }}

+
+
+ @@ -416,6 +429,7 @@ export default { data.append('static_discount', this.food.static_discount) data.append('special', this.food.special) data.append('index', this.food.index) + data.append('menuType_id', this.food.menuType_id) data.append('havePoint', this.food.havePoint) data.append('club', this.food.club) data.append('point', this.food.point) @@ -446,6 +460,7 @@ export default { this.validation = {} const data = new FormData() data.append('name', this.food.name) + data.append('menuType_id', this.food.menuType_id) data.append('price', this.food.price) data.append('description', this.food.description || '') data.append('short_description', this.food.short_description || '') @@ -522,7 +537,8 @@ export default { havePoint : false, club : false, sale: true, - point : 0 + point : 0, + menuType_id: 0, } } } diff --git a/server/controllers/foodsController.js b/server/controllers/foodsController.js index b03307e..44afda8 100644 --- a/server/controllers/foodsController.js +++ b/server/controllers/foodsController.js @@ -58,6 +58,9 @@ module.exports.create = [ body('category') .notEmpty().withMessage(_sr['fa'].required.category), + body('menuType_id') + .notEmpty().withMessage(_sr['fa'].required.menuType_id), + body('havePoint') .optional().isBoolean().withMessage(_sr['fa'].format.boolean), @@ -87,8 +90,8 @@ module.exports.create = [ async (req, res) => { if (req.files?.image && !_sr.supportedImageFormats.includes(req.files.image.mimetype.split('/')[1])) return res.status(422).json({validation: {image: {msg: _sr['fa'].format.image}}}) - const {name, description, short_description, price, stock, static_discount, estimated_time, category, index, special, havePoint, club, point, sale , branchId} = req.body - const data = {name, description, short_description, price, stock, static_discount, estimated_time, category, index, special, havePoint, club, point, sale , branchId} + const {name, description, short_description, price, stock, static_discount, estimated_time, category, index, special, havePoint, club, point, sale , branchId, menuType_id} = req.body + const data = {name, description, short_description, price, stock, static_discount, estimated_time, category, index, special, havePoint, club, point, sale , branchId, menuType_id} if (req?.files?.image) { const image = req?.files?.image @@ -143,6 +146,16 @@ module.exports.getAllForWebSite = [ } } ] +module.exports.getAllRestaurant = [ + async (req, res) => { + try { + const allFoods = await Food.find().select('-ratings').sort({index: 1}); + return res.json(allFoods); + } catch (error) { + return res500(res, _sr['fa'].response.unknownError); + } + } +] module.exports.getAllForPanel = [ async (req, res) => { @@ -267,8 +280,8 @@ module.exports.update = [ async (req, res) => { if (req.files?.image && !_sr.supportedImageFormats.includes(req.files.image.mimetype.split('/')[1])) return res.status(422).json({validation: {image: {msg: _sr['fa'].format.image}}}) - const {name, description, short_description, price, stock, static_discount, estimated_time, category, index, special, havePoint, club, point, sale , branchId} = req.body - const data = {name, description, short_description, price, stock, static_discount, estimated_time, category, index, special, havePoint, club, point, sale , branchId} + const {name, description, short_description, price, stock, static_discount, estimated_time, category, index, special, havePoint, club, point, sale , branchId, menuType_id} = req.body + const data = {name, description, short_description, price, stock, static_discount, estimated_time, category, index, special, havePoint, club, point, sale , branchId, menuType_id} if (req.files?.image) { const image = req.files.image diff --git a/server/models/Food.js b/server/models/Food.js index c536e47..ba3d45a 100644 --- a/server/models/Food.js +++ b/server/models/Food.js @@ -41,6 +41,7 @@ const FoodSchema = mongoose.Schema({ index: Number, havePoint : {type: Boolean ,default : true}, canReview : {type :Array , default: []}, + menuType_id: {type: mongoose.ObjectId, ref: 'MenuType'} // deleted : {type: Boolean , default : false} }) diff --git a/server/routes/public.js b/server/routes/public.js index 5d4234f..f1a18cd 100644 --- a/server/routes/public.js +++ b/server/routes/public.js @@ -35,6 +35,7 @@ router.get('/foodCategory/:id', foodCategoryController.get_one) //////////////// foods router.get('/foods/allWebsite' , foodsController.getAllForWebSite) +router.get('/foods/restaurant' , foodsController.getAllRestaurant) router.get('/foods/getAll/:branchId', isLoggedIn , foodsController.getAll) router.get('/food/:id', isLoggedIn , foodsController.getOne)