add menu in create and update product admin

This commit is contained in:
hamid.zarghami1@gmail.com
2024-05-13 12:41:43 +03:30
parent e644edbd65
commit 5cc22592f5
4 changed files with 36 additions and 5 deletions
+17 -4
View File
@@ -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
+1
View File
@@ -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}
})
+1
View File
@@ -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)