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 -1
View File
@@ -122,6 +122,19 @@
<p v-if="validation.index" class="text-danger" style="margin-top: 5px;">{{ validation.index.msg }}</p>
</CCol>
</CRow>
<CRow>
<CCol s="12">
<span>انتخاب منو</span>
</CCol>
<CCol sm="12" class="err">
<el-select v-model="food.menuType_id" filterable style="width: 100%;margin-top: 5px;">
<el-option v-for="item in menuTypes" :key="item._id" :value="item._id" :label="item.name"/>
</el-select>
<p v-if="validation.category" class="text-danger" style="margin-top: 5px;">{{ validation.menuType_id.msg }}</p>
</CCol>
</CRow>
</CForm>
</CCardBody>
</CCard>
@@ -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,
}
}
}
+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)