diff --git a/api/controllers/adminController.js b/api/controllers/adminController.js index 3657a13..11b2fbe 100644 --- a/api/controllers/adminController.js +++ b/api/controllers/adminController.js @@ -8,136 +8,136 @@ const v_m = require('../validation_messages') /////////////////////////////////////////////////////////////////////// register module.exports.register = [ - [ - body('name') - .isLength({min: 2}).withMessage(v_m['fa'].min_char.min2), + [ + body('name') + .isLength({min: 2}).withMessage(v_m['fa'].min_char.min2), - body('username') - .isLength({min: 4}).withMessage(v_m['fa'].min_char.min4) - .custom((value, {req}) => { - return Admin.findOne({username: value}) - .then(admin => { - if (admin && admin.username === value) return Promise.reject(v_m['fa'].duplicated.username) - else return true - }) - }), - - body('password') - .isLength({min: 4}).withMessage(v_m['fa'].min_char.min4) - .custom((value, {req}) => { - if (value === req.body.password_confirmation) return true - else return Promise.reject(v_m['fa'].response.passwords_not_match) - }) - ], - (req, res) => { - const errors = validationResult(req) - if (!errors.isEmpty()) return res.status(422).json({validation: errors.mapped()}) - - const data = {} - data.name = req.body.name - data.username = req.body.username - data.created_at = dateformat(Date.now(), 'yyyy-mm-dd HH:MM:ss') - - bcrypt.genSalt(10, (err, salt) => { - bcrypt.hash(req.body.password, salt, (err, hash) => { - if (err) console.log(err) - data.password = hash - - const admin = new Admin(data) - admin.save(err => { - if (err) console.log(err) - return res.json({message: v_m['fa'].response.success_save}) + body('username') + .isLength({min: 4}).withMessage(v_m['fa'].min_char.min4) + .custom((value, {req}) => { + return Admin.findOne({username: value}) + .then(admin => { + if (admin && admin.username === value) return Promise.reject(v_m['fa'].duplicated.username) + else return true }) - }) - }) + }), - } + body('password') + .isLength({min: 4}).withMessage(v_m['fa'].min_char.min4) + .custom((value, {req}) => { + if (value === req.body.password_confirmation) return true + else return Promise.reject(v_m['fa'].response.passwords_not_match) + }) + ], + (req, res) => { + const errors = validationResult(req) + if (!errors.isEmpty()) return res.status(422).json({validation: errors.mapped()}) + + const data = {} + data.name = req.body.name + data.username = req.body.username + data.created_at = dateformat(Date.now(), 'yyyy-mm-dd HH:MM:ss') + + bcrypt.genSalt(10, (err, salt) => { + bcrypt.hash(req.body.password, salt, (err, hash) => { + if (err) console.log(err) + data.password = hash + + const admin = new Admin(data) + admin.save(err => { + if (err) console.log(err) + return res.json({message: v_m['fa'].response.success_save}) + }) + }) + }) + + } ] /////////////////////////////////////////////////////////////////////// login module.exports.login = [ - [ - body('username') - .isLength({min: 4}).withMessage(v_m['fa'].min_char.min4) - .bail() - .if((value, {req}) => { - return req.body.password && req.body.password.length >= 4 - }) - .custom((value, {req}) => { - return Admin.findOne({username: value}) - .then(admin => { - if (!admin) return Promise.reject(v_m['fa'].not_found.admin_id) - else return true - }) - }), - - body('password') - .notEmpty().withMessage(v_m['fa'].required.password) - .bail() - .isLength({min: 4}).withMessage(v_m['fa'].min_char.min4), - - body('remember_me') - .exists().withMessage(v_m['fa'].required.remember_me) - .bail() - .isBoolean().withMessage('مقدار باید از جنس Boolean باشد.') - ], - (req, res) => { - const errors = validationResult(req) - if (!errors.isEmpty()) return res.status(422).json({validation: errors.mapped()}) - - Admin.findOne({username: req.body.username}, (err, user) => { - if (err) console.log(err) - bcrypt.compare(req.body.password, user.password, (err, isMatch) => { - if (err) console.log(err) - if (!isMatch) return res.status(422).json({validation: {password: {msg: v_m['fa'].not_found.password}}}) - - let token - if (req.body.remember_me) token = jwt.sign({_id: user._id}, config.secretKey) - else token = jwt.sign({_id: user._id}, config.secretKey, {expiresIn: '1h'}) - - user.token = token - user.save(err => { - if (err) console.log(err) - return res.json({token: token}) + [ + body('username') + .isLength({min: 4}).withMessage(v_m['fa'].min_char.min4) + .bail() + .if((value, {req}) => { + return req.body.password && req.body.password.length >= 4 + }) + .custom((value, {req}) => { + return Admin.findOne({username: value}) + .then(admin => { + if (!admin) return Promise.reject(v_m['fa'].not_found.admin_id) + else return true }) - }) + }), + + body('password') + .notEmpty().withMessage(v_m['fa'].required.password) + .bail() + .isLength({min: 4}).withMessage(v_m['fa'].min_char.min4), + + body('remember_me') + .exists().withMessage(v_m['fa'].required.remember_me) + .bail() + .isBoolean().withMessage('مقدار باید از جنس Boolean باشد.') + ], + (req, res) => { + const errors = validationResult(req) + if (!errors.isEmpty()) return res.status(422).json({validation: errors.mapped()}) + + Admin.findOne({username: req.body.username}, (err, user) => { + if (err) return res.status(404).json({message: err}) + bcrypt.compare(req.body.password, user.password, (err, isMatch) => { + if (err) console.log(err) + if (!isMatch) return res.status(422).json({validation: {password: {msg: v_m['fa'].not_found.password}}}) + + let token + if (req.body.remember_me) token = jwt.sign({_id: user._id}, config.secretKey) + else token = jwt.sign({_id: user._id}, config.secretKey, {expiresIn: '1h'}) + + user.token = token + user.save(err => { + if (err) console.log(err) + return res.json({token: token}) + }) }) - } + }) + } ] /////////////////////////////////////////////////////////////////////// logout module.exports.logout = [ - (req, res) => { - const token = req.headers.authorization - if (token) { - Admin.findOneAndUpdate({token: token}, {token: null}, (err, oldData) => { - if (err) console.log(err) - if (oldData) return res.json({message: v_m['fa'].response.logged_out}) - return res.status(401).json({message: v_m['fa'].response.not_logged_in}) - }) - } else { - return res.status(401).json({message: v_m['fa'].response.not_logged_in}) - } - } + (req, res) => { + const token = req.headers.authorization + if (token) { + Admin.findOneAndUpdate({token: token}, {token: null}, (err, oldData) => { + if (err) return res.status(404).json({message: err}) + if (oldData) return res.json({message: v_m['fa'].response.logged_out}) + return res.status(401).json({message: v_m['fa'].response.not_logged_in}) + }) + } else { + return res.status(401).json({message: v_m['fa'].response.not_logged_in}) + } + } ] /////////////////////////////////////////////////////////////////////// get user module.exports.getUser = [ - config.isAdmin, - (req, res) => { - const token = req.headers.authorization - if (token) { - jwt.verify(token, config.secretKey, (err, decoded) => { - if (err) return res.status(401).json({message: 'unauthenticated'}) - Admin.findById(decoded._id, (err, data) => { - if (err) console.log(err) - return res.json({user: data}) - }) - }) - } else { - return res.status(401).json({message: 'unauthenticated'}) - } - } + config.isAdmin, + (req, res) => { + const token = req.headers.authorization + if (token) { + jwt.verify(token, config.secretKey, (err, decoded) => { + if (err) return res.status(401).json({message: 'unauthenticated'}) + Admin.findById(decoded._id, (err, data) => { + if (err) return res.status(404).json({message: err}) + return res.json({user: data}) + }) + }) + } else { + return res.status(401).json({message: 'unauthenticated'}) + } + } ] /////////////////////////////////////////////////////////////////////// delete diff --git a/api/controllers/blogCategoryController.js b/api/controllers/blogCategoryController.js index b2ab71d..982ea04 100644 --- a/api/controllers/blogCategoryController.js +++ b/api/controllers/blogCategoryController.js @@ -105,7 +105,7 @@ module.exports.update = [ updated_at: dateformat(Date.now(), 'yyyy-mm-dd HH:MM:ss') } BlogCategory.findByIdAndUpdate(req.params.id, data, (err, oldData) => { - if (err) console.log(err) + if (err) return res.status(404).json({message: err}) return res.json({message: v_m['fa'].response.success_save}) }) } @@ -115,10 +115,10 @@ module.exports.update = [ module.exports.delete = [ (req, res) => { BlogPost.find({category: req.params.id}, (err, posts) => { - if (err) console.log(err) + if (err) return res.status(404).json({message: err}) if (!posts.length) { - BlogCategory.findByIdAndDelete(req.params.id, (err) => { - if (err) return res.status(404).json({message: err}) + BlogCategory.findByIdAndDelete(req.params.id, (err1) => { + if (err1) return res.status(404).json({message: err1}) return res.json({message: v_m['fa'].response.success_save}) }) } else { diff --git a/api/controllers/blogPostController.js b/api/controllers/blogPostController.js index bd8d1c3..8b5b10c 100644 --- a/api/controllers/blogPostController.js +++ b/api/controllers/blogPostController.js @@ -80,6 +80,9 @@ module.exports.create = [ .cover(thumbWith, thumbHeight) .write(`./static/uploads/images/blog/thumb_${coverName}`) }) + .catch(err => { + console.log(err) + }) const data = { post_details: { @@ -112,7 +115,7 @@ module.exports.create = [ module.exports.getAll = [ (req, res) => { BlogPost.find({}).sort({_id: -1}).exec((err, posts) => { - if (err) console.log(err) + if (err) return res.status(500).json({message: err}) return res.json(posts) }) } @@ -122,7 +125,7 @@ module.exports.getAll = [ module.exports.getOne = [ (req, res) => { BlogPost.findById(req.params.id, (err, post) => { - if (err) console.log(err) + if (err) return res.status(404).json({message: err}) return res.json(post) }) } @@ -213,10 +216,13 @@ module.exports.update = [ .cover(thumbWith, thumbHeight) .write(`./static/uploads/images/blog/thumb_${coverName}`) }) + .catch(err => { + console.log(err) + }) } BlogPost.findByIdAndUpdate(req.params.id, data, (err, oldData) => { - if (err) console.log(err) + if (err) return res.status(404).json({message: err}) if (cover && cover.data) { fs.unlink(`./static/${oldData.cover}`, err => { if (err) console.log(err) @@ -225,8 +231,8 @@ module.exports.update = [ if (err) console.log(err) }) } - BlogPost.findById(oldData._id, (err, newData) => { - if (err) console.log(err) + BlogPost.findById(oldData._id, (err1, newData) => { + if (err1) return res.status(404).json({message: err1}) return res.json(newData) }) }) @@ -238,11 +244,11 @@ module.exports.delete = [ (req, res) => { BlogPost.findByIdAndDelete(req.params.id, (err, post) => { if (err) return res.status(404).json({message: err}) - fs.unlink(`./static/${post.cover}`, err => { - if (err) console.log(err) + fs.unlink(`./static/${post.cover}`, err1 => { + if (err1) console.log(err1) }) - fs.unlink(`./static/${post.thumb}`, err => { - if (err) console.log(err) + fs.unlink(`./static/${post.thumb}`, err2 => { + if (err2) console.log(err2) }) return res.json({message: v_m['fa'].response.success_remove}) }) diff --git a/api/controllers/contactPageController.js b/api/controllers/contactPageController.js index 93ef3b3..539412f 100644 --- a/api/controllers/contactPageController.js +++ b/api/controllers/contactPageController.js @@ -4,110 +4,110 @@ const dateformat = require('dateformat') const v_m = require('../validation_messages') module.exports.create = [ - [ - body('first_name') - .notEmpty() - .withMessage((value, {req}) => { - return v_m[req.body.locale].required.first_name - }) - .bail() - .isLength({min: 2}) - .withMessage((value, {req}) => { - return v_m[req.body.locale].min_char.min2 - }), + [ + body('first_name') + .notEmpty() + .withMessage((value, {req}) => { + return v_m[req.body.locale].required.first_name + }) + .bail() + .isLength({min: 2}) + .withMessage((value, {req}) => { + return v_m[req.body.locale].min_char.min2 + }), - body('last_name') - .notEmpty() - .withMessage((value, {req}) => { - return v_m[req.body.locale].required.last_name - }) - .bail() - .isLength({min: 2}) - .withMessage((value, {req}) => { - return v_m[req.body.locale].min_char.min2 - }), + body('last_name') + .notEmpty() + .withMessage((value, {req}) => { + return v_m[req.body.locale].required.last_name + }) + .bail() + .isLength({min: 2}) + .withMessage((value, {req}) => { + return v_m[req.body.locale].min_char.min2 + }), - body('phone_number') - .notEmpty() - .withMessage((value, {req}) => { - return v_m[req.body.locale].required.phone_number - }) - .bail() - .isNumeric() - .withMessage((value, {req}) => { - return v_m[req.body.locale].format.phone_number - }), + body('phone_number') + .notEmpty() + .withMessage((value, {req}) => { + return v_m[req.body.locale].required.phone_number + }) + .bail() + .isNumeric() + .withMessage((value, {req}) => { + return v_m[req.body.locale].format.phone_number + }), - body('email') - .notEmpty() - .withMessage((value, {req}) => { - return v_m[req.body.locale].required.email - }) - .bail() - .isEmail() - .withMessage((value, {req}) => { - return v_m[req.body.locale].format.email - }), + body('email') + .notEmpty() + .withMessage((value, {req}) => { + return v_m[req.body.locale].required.email + }) + .bail() + .isEmail() + .withMessage((value, {req}) => { + return v_m[req.body.locale].format.email + }), - body('reason') - .custom((value, {req}) => { - if (!value) return Promise.reject(v_m[req.body.locale].required.reason) - else return true - }), + body('reason') + .custom((value, {req}) => { + if (!value) return Promise.reject(v_m[req.body.locale].required.reason) + else return true + }), - body('message') - .isLength({min: 50}) - .withMessage((value, {req}) => { - return v_m[req.body.locale].min_char.min50 - }) + body('message') + .isLength({min: 50}) + .withMessage((value, {req}) => { + return v_m[req.body.locale].min_char.min50 + }) - ], - (req, res) => { - const errors = validationResult(req) - if (!errors.isEmpty()) return res.status(422).json({validation: errors.mapped()}) + ], + (req, res) => { + const errors = validationResult(req) + if (!errors.isEmpty()) return res.status(422).json({validation: errors.mapped()}) - const data = { - first_name: req.body.first_name, - last_name: req.body.last_name, - phone_number: req.body.phone_number, - email: req.body.email, - message: req.body.message, - reason: req.body.reason, - created_at: dateformat(Date.now(), 'yyyy-mm-dd HH:MM:ss') - } - const message = new ContactPageMessage(data) - message.save((err, message) => { - if (err) console.log(err) - return res.json({message: v_m[req.body.locale].response.success_save}) - }) - } + const data = { + first_name: req.body.first_name, + last_name: req.body.last_name, + phone_number: req.body.phone_number, + email: req.body.email, + message: req.body.message, + reason: req.body.reason, + created_at: dateformat(Date.now(), 'yyyy-mm-dd HH:MM:ss') + } + const message = new ContactPageMessage(data) + message.save((err, message) => { + if (err) console.log(err) + return res.json({message: v_m[req.body.locale].response.success_save}) + }) + } ] module.exports.getAll = [ - (req, res) => { - ContactPageMessage.find({}).select('-message') - .then(messages => { - return res.json(messages) - }) - .catch(err => { - console.log(err) - return res.status(500).json(err) - }) - } + (req, res) => { + ContactPageMessage.find({}).select('-message') + .then(messages => { + return res.json(messages) + }) + .catch(err => { + console.log(err) + return res.status(500).json({message: err}) + }) + } ] module.exports.getOne = [ - (req, res) => { - ContactPageMessage.findById(req.params.id) - .then(message => { - message.read = true - message.save() - return res.json(message) - }) - .catch(err => { - return res.status(404).json(err) - }) - } + (req, res) => { + ContactPageMessage.findById(req.params.id) + .then(message => { + message.read = true + message.save() + return res.json(message) + }) + .catch(err => { + return res.status(404).json({message: err}) + }) + } ] diff --git a/api/controllers/contactUsReasonController.js b/api/controllers/contactUsReasonController.js index 24272fc..f4d8827 100644 --- a/api/controllers/contactUsReasonController.js +++ b/api/controllers/contactUsReasonController.js @@ -5,54 +5,54 @@ const v_m = require('../validation_messages') module.exports.create = [ - [ - body('fa_reason') - .notEmpty().withMessage(v_m['fa'].required.title), + [ + body('fa_reason') + .notEmpty().withMessage(v_m['fa'].required.title), - body('en_reason') - .notEmpty().withMessage(v_m['fa'].required.title) - ], - (req, res) => { - const errors = validationResult(req) - if (!errors.isEmpty()) return res.status(422).json({validation: errors.mapped()}) + body('en_reason') + .notEmpty().withMessage(v_m['fa'].required.title) + ], + (req, res) => { + const errors = validationResult(req) + if (!errors.isEmpty()) return res.status(422).json({validation: errors.mapped()}) - const data = { - reason_details: { - fa: { - reason: req.body.fa_reason - }, - en: { - reason: req.body.en_reason - } - }, - created_at: dateformat(Date.now(), 'yyyy-mm-dd HH:MM:ss') - } + const data = { + reason_details: { + fa: { + reason: req.body.fa_reason + }, + en: { + reason: req.body.en_reason + } + }, + created_at: dateformat(Date.now(), 'yyyy-mm-dd HH:MM:ss') + } - const reason = new Reason(data) - reason.save(err => { - if (err) console.log(err) - Reason.find({}, (err2, data) => { - if (err2) console.log(err2) - return res.json(data) - }) + const reason = new Reason(data) + reason.save(err => { + if (err) console.log(err) + Reason.find({}, (err2, data) => { + if (err2) console.log(err2) + return res.json(data) }) - } + }) + } ] module.exports.getAll = [ - (req, res) => { - Reason.find({}, (err, data) => { - if (err) console.log(err) - return res.json(data) - }) - } + (req, res) => { + Reason.find({}, (err, data) => { + if (err) console.log(err) + return res.json(data) + }) + } ] module.exports.delete = [ - (req, res) => { - Reason.findByIdAndDelete(req.params.id, (err, reason) => { - if (err) console.log(err) - return res.json({message: v_m['fa'].response.success_remove}) - }) - } + (req, res) => { + Reason.findByIdAndDelete(req.params.id, (err, reason) => { + if (err) return res.status(404).json({message: err}) + return res.json({message: v_m['fa'].response.success_remove}) + }) + } ] diff --git a/api/controllers/historyController.js b/api/controllers/historyController.js index f6cd288..070df9c 100644 --- a/api/controllers/historyController.js +++ b/api/controllers/historyController.js @@ -84,7 +84,7 @@ module.exports.getAll = [ module.exports.getOne = [ (req, res) => { History.findById(req.params.id, (err, data) => { - if (err) return res.status(404).json(err) + if (err) return res.status(404).json({message: err}) return res.json(data) }) } @@ -151,7 +151,7 @@ module.exports.update = [ }) } else { History.findByIdAndUpdate(req.params.id, data, (err, oldData) => { - if (err) console.log(err) + if (err) return res.status(404).json({message: err}) return res.json(v_m['fa'].response.success_save) }) } @@ -162,7 +162,7 @@ module.exports.update = [ module.exports.delete = [ (req, res) => { History.findByIdAndDelete(req.params.id, (err, data) => { - if (err) console.log(err) + if (err) return res.status(404).json({message: err}) fs.unlink(`./static/${data.image}`, err => { if (err) console.log(err) return res.json(v_m['fa'].response.success_remove) diff --git a/api/controllers/mainCatalogController.js b/api/controllers/mainCatalogController.js index a0b82c4..a9e5fe3 100644 --- a/api/controllers/mainCatalogController.js +++ b/api/controllers/mainCatalogController.js @@ -8,11 +8,10 @@ module.exports.create = [ if (!req.files || !req.files.pdf) return res.status(422).json({validation: {pdf: {msg: v_m['fa'].required.file}}}) if (req.files.pdf.mimetype.split('/')[1] !== 'pdf') return res.status(422).json({validation: {pdf: {msg: v_m['fa'].file_types.pdf}}}) - MainCatalog.find({}, (err, catalogs) => { + if (err) console.log(err) if (catalogs.length) { let firstFile = catalogs[0] - if (firstFile.file[req.body.locale]) fs.unlink(`./static/${firstFile.file[req.body.locale]}`, err => { if (err) console.log(err) }) @@ -24,8 +23,6 @@ module.exports.create = [ req.files.pdf.mv(`./static/uploads/pdf/${req.body.locale}_${req.files.pdf.name}`) return res.json(firstFile) }) - - } else { const data = {created_at: dateformat(Date.now(), 'yyyy-mm-dd HH:MM:ss'), file: {}} data.file[req.body.locale] = req.body.locale + '_' + req.files.pdf.name diff --git a/api/controllers/productController.js b/api/controllers/productController.js index 714fb54..00fb940 100644 --- a/api/controllers/productController.js +++ b/api/controllers/productController.js @@ -168,6 +168,9 @@ module.exports.createProduct = [ .quality(thumbQuality) .write(`./static/uploads/images/products/${thumb}`) }) + .catch(err => { + console.log(err) + }) } if (req.files.more_section_image1) { await jimp.read(req.files.more_section_image1.data) @@ -178,6 +181,9 @@ module.exports.createProduct = [ .quality(moreSectionQuality) .write(`./static/uploads/images/products/${more_section_image1}`) }) + .catch(err => { + console.log(err) + }) } if (req.files.more_section_image2) { await jimp.read(req.files.more_section_image2.data) @@ -188,6 +194,9 @@ module.exports.createProduct = [ .quality(moreSectionQuality) .write(`./static/uploads/images/products/${more_section_image2}`) }) + .catch(err => { + console.log(err) + }) } if (req.files.render_image1) { await jimp.read(req.files.render_image1.data) @@ -198,6 +207,9 @@ module.exports.createProduct = [ .quality(renderImageQuality) .write(`./static/uploads/images/products/${render_image1}`) }) + .catch(err => { + console.log(err) + }) } if (req.files.render_image2) { await jimp.read(req.files.render_image2.data) @@ -208,6 +220,9 @@ module.exports.createProduct = [ .quality(renderImageQuality) .write(`./static/uploads/images/products/${render_image2}`) }) + .catch(err => { + console.log(err) + }) } if (req.files.chart_image) { await jimp.read(req.files.chart_image.data) @@ -216,6 +231,9 @@ module.exports.createProduct = [ .quality(chartImageQuality) .write(`./static/uploads/images/products/${chart_image}`) }) + .catch(err => { + console.log(err) + }) } } @@ -249,8 +267,8 @@ module.exports.getAllProducts = [ ] module.exports.getOneProduct = [ - async (req, res) => { - await Product.findById(req.params.id, async (err, product) => { + (req, res) => { + Product.findById(req.params.id, (err, product) => { if (err) return res.status(404).json({message: err}) return res.json(product) }) @@ -394,6 +412,9 @@ module.exports.updateProduct = [ .quality(thumbQuality) .write(`./static/uploads/images/products/${thumb}`) }) + .catch(err => { + console.log(err) + }) } if (req.files.more_section_image1) { @@ -406,6 +427,9 @@ module.exports.updateProduct = [ .quality(moreSectionQuality) .write(`./static/uploads/images/products/${more_section_image1}`) }) + .catch(err => { + console.log(err) + }) } if (req.files.more_section_image2) { @@ -418,6 +442,9 @@ module.exports.updateProduct = [ .quality(moreSectionQuality) .write(`./static/uploads/images/products/${more_section_image2}`) }) + .catch(err => { + console.log(err) + }) } if (req.files.render_image1) { @@ -430,6 +457,9 @@ module.exports.updateProduct = [ .quality(renderImageQuality) .write(`./static/uploads/images/products/${render_image1}`) }) + .catch(err => { + console.log(err) + }) } if (req.files.render_image2) { @@ -442,6 +472,9 @@ module.exports.updateProduct = [ .quality(renderImageQuality) .write(`./static/uploads/images/products/${render_image2}`) }) + .catch(err => { + console.log(err) + }) } if (req.files.chart_image) { @@ -452,6 +485,9 @@ module.exports.updateProduct = [ .quality(chartImageQuality) .write(`./static/uploads/images/products/${chart_image}`) }) + .catch(err => { + console.log(err) + }) } } @@ -584,6 +620,9 @@ module.exports.createProductImage = [ return res.json(product) }) }) + .catch(err => { + console.log(err) + }) } else { return res.status(422).json({validation: {images: {image: {msg: v_m['fa'].required.image}}}}) diff --git a/api/controllers/projectController.js b/api/controllers/projectController.js index aaa0f16..8d28bef 100644 --- a/api/controllers/projectController.js +++ b/api/controllers/projectController.js @@ -7,196 +7,200 @@ const v_m = require('../validation_messages') ///////////////////////////////////////// create project module.exports.create = [ - [ - body('fa_name') - .notEmpty().withMessage(v_m['fa'].required.title) - .bail() - .custom((value, {req}) => { - return Project.findOne({'project_details.fa.name': value}) - .then(project => { - if (project) return Promise.reject(v_m['fa'].duplicated.name) - else return true - }) - }), + [ + body('fa_name') + .notEmpty().withMessage(v_m['fa'].required.title) + .bail() + .custom((value, {req}) => { + return Project.findOne({'project_details.fa.name': value}) + .then(project => { + if (project) return Promise.reject(v_m['fa'].duplicated.name) + else return true + }) + }), - body('en_name') - .notEmpty().withMessage(v_m['fa'].required.title) - .bail() - .custom((value, {req}) => { - return Project.findOne({'project_details.en.name': value}) - .then(project => { - if (project) return Promise.reject(v_m['fa'].duplicated.name) - else return true - }) - }), + body('en_name') + .notEmpty().withMessage(v_m['fa'].required.title) + .bail() + .custom((value, {req}) => { + return Project.findOne({'project_details.en.name': value}) + .then(project => { + if (project) return Promise.reject(v_m['fa'].duplicated.name) + else return true + }) + }), - body('date') - .notEmpty().withMessage(v_m['fa'].required.date), - ], - (req, res) => { - const errors = validationResult(req) - if (!errors.isEmpty()) return res.status(422).json({validation: errors.mapped()}) + body('date') + .notEmpty().withMessage(v_m['fa'].required.date), + ], + (req, res) => { + const errors = validationResult(req) + if (!errors.isEmpty()) return res.status(422).json({validation: errors.mapped()}) - const data = { - date: req.body.date, - project_details: { - fa: { - name: req.body.fa_name, - description: req.body.fa_description, - }, - en: { - name: req.body.en_name, - description: req.body.en_description, - } - }, - created_at: dateFormat(Date.now(), 'yyyy-mm-dd HH:MM:ss') - } + const data = { + date: req.body.date, + project_details: { + fa: { + name: req.body.fa_name, + description: req.body.fa_description, + }, + en: { + name: req.body.en_name, + description: req.body.en_description, + } + }, + created_at: dateFormat(Date.now(), 'yyyy-mm-dd HH:MM:ss') + } - const project = new Project(data) - project.save((err, project) => { - if (err) console.log(err) - return res.json(project) - }) - } + const project = new Project(data) + project.save((err, project) => { + if (err) console.log(err) + return res.json(project) + }) + } ] ///////////////////////////////////////// get all projects module.exports.getAll = [ - (req, res) => { - Project.find({}, (err, projects) => { - if (err) return res.json({errors: err}) - return res.json(projects) - }) - } + (req, res) => { + Project.find({}, (err, projects) => { + if (err) return res.json({errors: err}) + return res.json(projects) + }) + } ] ///////////////////////////////////////// get one project module.exports.getOne = [ - (req, res) => { - Project.findById(req.params.id, (err, project) => { - if (err) return res.json({errors: err}) - return res.json(project) - }) - } + (req, res) => { + Project.findById(req.params.id, (err, project) => { + if (err) return res.status(404).json({errors: err}) + return res.json(project) + }) + } ] ///////////////////////////////////////// update one project module.exports.update = [ - [ - body('fa_name') - .notEmpty().withMessage(v_m['fa'].required.title) - .bail() - .custom((value, {req}) => { - return Project.findOne({'project_details.fa.name': value}) - .then(project => { - if (project && project._id.toString() !== req.params.id) return Promise.reject(v_m['fa'].duplicated.name) - else return true - }) - }), + [ + body('fa_name') + .notEmpty().withMessage(v_m['fa'].required.title) + .bail() + .custom((value, {req}) => { + return Project.findOne({'project_details.fa.name': value}) + .then(project => { + if (project && project._id.toString() !== req.params.id) return Promise.reject(v_m['fa'].duplicated.name) + else return true + }) + }), - body('en_name') - .notEmpty().withMessage(v_m['fa'].required.title) - .bail() - .custom((value, {req}) => { - return Project.findOne({'project_details.en.name': value}) - .then(project => { - if (project && project._id.toString() !== req.params.id) return Promise.reject(v_m['fa'].duplicated.name) - else return true - }) - }), + body('en_name') + .notEmpty().withMessage(v_m['fa'].required.title) + .bail() + .custom((value, {req}) => { + return Project.findOne({'project_details.en.name': value}) + .then(project => { + if (project && project._id.toString() !== req.params.id) return Promise.reject(v_m['fa'].duplicated.name) + else return true + }) + }), - body('date') - .notEmpty().withMessage(v_m['fa'].required.date), - ], - (req, res) => { - const errors = validationResult(req) - if (!errors.isEmpty()) return res.status(422).json({validation: errors.mapped()}) + body('date') + .notEmpty().withMessage(v_m['fa'].required.date), + ], + (req, res) => { + const errors = validationResult(req) + if (!errors.isEmpty()) return res.status(422).json({validation: errors.mapped()}) - const data = { - date: req.body.date, - project_details: { - fa: { - name: req.body.fa_name, - description: req.body.fa_description, - }, - en: { - name: req.body.en_name, - description: req.body.en_description, - } - }, - updated_at: dateFormat(Date.now(), 'yyyy-mm-dd HH:MM:ss') - } + const data = { + date: req.body.date, + project_details: { + fa: { + name: req.body.fa_name, + description: req.body.fa_description, + }, + en: { + name: req.body.en_name, + description: req.body.en_description, + } + }, + updated_at: dateFormat(Date.now(), 'yyyy-mm-dd HH:MM:ss') + } - Project.findByIdAndUpdate(req.params.id, data, (err, oldData) => { - if (err) console.log(err) - return res.json({message: v_m['fa'].response.success_save}) - }) - } + Project.findByIdAndUpdate(req.params.id, data, (err, oldData) => { + if (err) return res.status(404).json({message: err}) + return res.json({message: v_m['fa'].response.success_save}) + }) + } ] ///////////////////////////////////////// delete project module.exports.delete = [ - (req, res) => { - Project.findByIdAndRemove(req.params.id, (err, data) => { - if (err) return res.json({error: err}) - data.images.forEach(async item => { - await fs.unlink(`./static/${item.image}`, err => { - if (err) console.log(err) - }) - }) - return res.json({message: v_m['fa'].response.success_remove}) + (req, res) => { + Project.findByIdAndRemove(req.params.id, (err, data) => { + if (err) return res.status(404).json({message: err}) + data.images.forEach(async item => { + try { + await fs.unlink(`./static/${item.image}`, err => { + if (err) console.log(err) + }) + } catch (e) { + console.log(e) + } }) - } + return res.json({message: v_m['fa'].response.success_remove}) + }) + } ] //////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////// add images to project module.exports.addImage = [ - (req, res) => { - Project.findById(req.params.id) - .then(project => { - if (!req.files || !req.files.image) return res.status(422).json({validation: {image: {msg: v_m['fa'].required.image}}}) + (req, res) => { + Project.findById(req.params.id) + .then(project => { + if (!req.files || !req.files.image) return res.status(422).json({validation: {image: {msg: v_m['fa'].required.image}}}) - let fileName = 'project_' + Date.now() + '.' + req.files.image.mimetype.split('/')[1] - jimp.read(req.files.image.data) - .then(img => { - img - .cover(1010, 534) - .quality(80) - .write(`./static/uploads/images/projects/${fileName}`) + let fileName = 'project_' + Date.now() + '.' + req.files.image.mimetype.split('/')[1] + jimp.read(req.files.image.data) + .then(img => { + img + .cover(1010, 534) + .quality(80) + .write(`./static/uploads/images/projects/${fileName}`) - //// - const data = { - image: fileName, - created_at: dateFormat(Date.now(), 'yyyy-mm-dd HH:MM:ss') - } - project.images.push(data) - project.save(cb => { - return res.json(project) - }) - }) - .catch(err => { - console.log(err) - }) - }) - } + //// + const data = { + image: fileName, + created_at: dateFormat(Date.now(), 'yyyy-mm-dd HH:MM:ss') + } + project.images.push(data) + project.save(cb => { + return res.json(project) + }) + }) + .catch(err => { + console.log(err) + }) + }) + } ] module.exports.deleteImage = [ - (req, res) => { - Project.findOne({'images._id': req.params.id}, (err, project) => { - if (err) console.log(err) - if (project) { - let image = project.images.id(req.params.id) - fs.unlink(`./static/${image.image}`, err => { - if (err) console.log(err) - image.remove() - project.save(cb => { - return res.json({message: v_m['fa'].response.success_remove}) - }) - }) - } - }) - } + (req, res) => { + Project.findOne({'images._id': req.params.id}, (err, project) => { + if (err) console.log(err) + if (project) { + let image = project.images.id(req.params.id) + fs.unlink(`./static/${image.image}`, err => { + if (err) console.log(err) + image.remove() + project.save(cb => { + return res.json({message: v_m['fa'].response.success_remove}) + }) + }) + } + }) + } ] diff --git a/api/controllers/sliderController.js b/api/controllers/sliderController.js index 725a762..9f3e68f 100644 --- a/api/controllers/sliderController.js +++ b/api/controllers/sliderController.js @@ -7,167 +7,167 @@ const v_m = require('../validation_messages') //////////////////////////////////////////////////////////////////////////////// create module.exports.create = [ - [ - body('fa_title') - .isLength({max: 40}).withMessage(v_m['fa'].max_char.max40), + [ + body('fa_title') + .isLength({max: 40}).withMessage(v_m['fa'].max_char.max40), - body('en_title') - .isLength({max: 40}).withMessage(v_m['fa'].max_char.max40), + body('en_title') + .isLength({max: 40}).withMessage(v_m['fa'].max_char.max40), - body('fa_caption') - .isLength({max: 100}).withMessage(v_m['fa'].max_char.max100), + body('fa_caption') + .isLength({max: 100}).withMessage(v_m['fa'].max_char.max100), - body('en_caption') - .isLength({max: 100}).withMessage(v_m['fa'].max_char.max100) - ], - (req, res) => { - const errors = validationResult(req) - if (!errors.isEmpty()) return res.status(422).json({validation: errors.mapped()}) + body('en_caption') + .isLength({max: 100}).withMessage(v_m['fa'].max_char.max100) + ], + (req, res) => { + const errors = validationResult(req) + if (!errors.isEmpty()) return res.status(422).json({validation: errors.mapped()}) - if (req.files) { - let file = req.files.image - jimp.read(file.data) - .then(img => { - let fileName = 'image_' + Date.now() + '.' + img.getExtension() - if (img.bitmap.width >= 1920 && img.bitmap.height >= 1080) { - if (file.size / 1024 < 450) { - file.mv(`./static/uploads/images/slider/${fileName}`, (err, img) => { - const slider = new Slider({ - image: fileName, - slider_details: { - fa: { - title: req.body.fa_title, - caption: req.body.fa_caption - }, - en: { - title: req.body.en_title, - caption: req.body.en_caption - } - }, - created_at: dateFormat(Date.now(), 'yyyy-mm-dd HH:MM:ss') - }) - slider.save((err, data) => { - if (err) return res.status(500).json({error: err}) - return res.json({message: v_m['fa'].response.success_save}) - }) - }) - } else { - return res.status(422).json({validation: {image: {msg: 'حجم تصویر نباید بیشتر از 450 کیلوبایت باشد'}}}) - } - } else { - return res.status(422).json({validation: {image: {msg: 'ابعاد تصویر حداقل 1920*1080 پیکسل قابل قبول میباشد.'}}}) - } - }) - .catch(err => { - console.log(err) - }) - } else { - return res.status(422).json({validation: {image: {msg: v_m['fa'].required.image}}}) - } - } + if (req.files) { + let file = req.files.image + jimp.read(file.data) + .then(img => { + let fileName = 'image_' + Date.now() + '.' + img.getExtension() + if (img.bitmap.width >= 1920 && img.bitmap.height >= 1080) { + if (file.size / 1024 < 450) { + file.mv(`./static/uploads/images/slider/${fileName}`, (err, img) => { + const slider = new Slider({ + image: fileName, + slider_details: { + fa: { + title: req.body.fa_title, + caption: req.body.fa_caption + }, + en: { + title: req.body.en_title, + caption: req.body.en_caption + } + }, + created_at: dateFormat(Date.now(), 'yyyy-mm-dd HH:MM:ss') + }) + slider.save((err, data) => { + if (err) return res.status(500).json({error: err}) + return res.json({message: v_m['fa'].response.success_save}) + }) + }) + } else { + return res.status(422).json({validation: {image: {msg: 'حجم تصویر نباید بیشتر از 450 کیلوبایت باشد'}}}) + } + } else { + return res.status(422).json({validation: {image: {msg: 'ابعاد تصویر حداقل 1920*1080 پیکسل قابل قبول میباشد.'}}}) + } + }) + .catch(err => { + console.log(err) + }) + } else { + return res.status(422).json({validation: {image: {msg: v_m['fa'].required.image}}}) + } + } ] //////////////////////////////////////////////////////////////////////////////// get all module.exports.getAll = [ - (req, res) => { - Slider.find({}, (err, slides) => { - if (err) return res.status(404).json({error: err}) - return res.json(slides) - }) - } + (req, res) => { + Slider.find({}, (err, slides) => { + if (err) return res.status(404).json({error: err}) + return res.json(slides) + }) + } ] //////////////////////////////////////////////////////////////////////////////// get one module.exports.getOne = [ - (req, res) => { - Slider.findById(req.params.id, (err, slide) => { - if (err) return res.status(404).json({error: v_m['fa'].not_found.item_id}) - return res.json(slide) - }) - } + (req, res) => { + Slider.findById(req.params.id, (err, slide) => { + if (err) return res.status(404).json({error: v_m['fa'].not_found.item_id}) + return res.json(slide) + }) + } ] //////////////////////////////////////////////////////////////////////////////// update module.exports.update = [ - [ - body('fa_title') - .isLength({max: 40}).withMessage(v_m['fa'].max_char.max40), + [ + body('fa_title') + .isLength({max: 40}).withMessage(v_m['fa'].max_char.max40), - body('en_title') - .isLength({max: 40}).withMessage(v_m['fa'].max_char.max40), + body('en_title') + .isLength({max: 40}).withMessage(v_m['fa'].max_char.max40), - body('fa_caption') - .isLength({max: 100}).withMessage(v_m['fa'].max_char.max100), + body('fa_caption') + .isLength({max: 100}).withMessage(v_m['fa'].max_char.max100), - body('en_caption') - .isLength({max: 100}).withMessage(v_m['fa'].max_char.max100) - ], - (req, res) => { - const errors = validationResult(req) - if (!errors.isEmpty()) return res.status(422).json({validation: errors.mapped()}) + body('en_caption') + .isLength({max: 100}).withMessage(v_m['fa'].max_char.max100) + ], + (req, res) => { + const errors = validationResult(req) + if (!errors.isEmpty()) return res.status(422).json({validation: errors.mapped()}) - const data = { - slider_details: { - fa: { - title: req.body.fa_title, - caption: req.body.fa_caption - }, - en: { - title: req.body.en_title, - caption: req.body.en_caption - } - }, - updated_at: dateFormat(Date.now(), 'yyyy-mm-dd HH:MM:ss') - } + const data = { + slider_details: { + fa: { + title: req.body.fa_title, + caption: req.body.fa_caption + }, + en: { + title: req.body.en_title, + caption: req.body.en_caption + } + }, + updated_at: dateFormat(Date.now(), 'yyyy-mm-dd HH:MM:ss') + } - if (req.files) { - let file = req.files.image - jimp.read(file.data) - .then(img => { - let fileName = 'image_' + Date.now() + '.' + img.getExtension() - data.image = fileName - if (img.bitmap.width >= 1920 && img.bitmap.height >= 1080) { - if (file.size / 1024 < 450) { - file.mv(`./static/uploads/images/slider/${fileName}`, (err) => { - if (err) console.log(err) + if (req.files) { + let file = req.files.image + jimp.read(file.data) + .then(img => { + let fileName = 'image_' + Date.now() + '.' + img.getExtension() + data.image = fileName + if (img.bitmap.width >= 1920 && img.bitmap.height >= 1080) { + if (file.size / 1024 < 450) { + file.mv(`./static/uploads/images/slider/${fileName}`, (err) => { + if (err) console.log(err) - Slider.findByIdAndUpdate(req.params.id, data, (err, oldSlide) => { - if (err) return res.status(500).json({error: err}) - fs.unlink(`./static/${oldSlide.image}`, err => { - if (err) console.log(err) - }) - return res.json({message: v_m['fa'].response.success_save}) - }) - }) - } else { - return res.status(422).json({validation: {image: {msg: 'حجم تصویر نباید بیشتر از 450 کیلوبایت باشد'}}}) - } - } else { - return res.status(422).json({validation: {image: {msg: 'ابعاد تصویر حداقل 1920*1080 پیکسل قابل قبول میباشد.'}}}) - } - }) - .catch(err => { - console.log(err) - }) - - } else { - Slider.findByIdAndUpdate(req.params.id, data, (err, oldSlide) => { - if (err) return res.status(500).json({error: err}) - return res.json({message: v_m['fa'].response.success_save}) + Slider.findByIdAndUpdate(req.params.id, data, (err, oldSlide) => { + if (err) return res.status(500).json({error: err}) + fs.unlink(`./static/${oldSlide.image}`, err => { + if (err) console.log(err) + }) + return res.json({message: v_m['fa'].response.success_save}) + }) + }) + } else { + return res.status(422).json({validation: {image: {msg: 'حجم تصویر نباید بیشتر از 450 کیلوبایت باشد'}}}) + } + } else { + return res.status(422).json({validation: {image: {msg: 'ابعاد تصویر حداقل 1920*1080 پیکسل قابل قبول میباشد.'}}}) + } }) - } - } + .catch(err => { + console.log(err) + }) + + } else { + Slider.findByIdAndUpdate(req.params.id, data, (err, oldSlide) => { + if (err) return res.status(500).json({error: err}) + return res.json({message: v_m['fa'].response.success_save}) + }) + } + } ] //////////////////////////////////////////////////////////////////////////////// delete module.exports.delete = [ - (req, res) => { - Slider.findByIdAndRemove(req.params.id, (err, data) => { - if (err) return res.json({error: err}) - fs.unlink(`./static/${data.image}`, err => { - if (err) console.log(err) - }) - return res.json({message: v_m['fa'].response.success_remove}) + (req, res) => { + Slider.findByIdAndRemove(req.params.id, (err, data) => { + if (err) return res.json({error: err}) + fs.unlink(`./static/${data.image}`, err => { + if (err) console.log(err) }) - } + return res.json({message: v_m['fa'].response.success_remove}) + }) + } ] diff --git a/components/SiteHeader.vue b/components/SiteHeader.vue index daa7516..ac6994c 100644 --- a/components/SiteHeader.vue +++ b/components/SiteHeader.vue @@ -37,7 +37,7 @@ {{ staticData.home }} - + {{ staticData.about }} @@ -114,8 +114,12 @@ export default { } }, async fetch() { - let catalog = await this.$axios.get('/api/public/catalog') - this.catalog = catalog.data + try { + let catalog = await this.$axios.get('/api/public/catalog') + this.catalog = catalog.data + } catch (e) { + this.$nuxt.context.error({status: 404, message: 'Catalog file not found'}) + } }, computed: { staticData() { diff --git a/pages/_lang/about/index.vue b/pages/_lang/about/index.vue index 56be4fd..86b0702 100644 --- a/pages/_lang/about/index.vue +++ b/pages/_lang/about/index.vue @@ -44,7 +44,7 @@ -
+
@@ -157,10 +157,14 @@ export default { title: this.staticData.hero } }, - async asyncData({$axios}) { - const history = await $axios.get(`/api/public/history`) - return { - history: history.data + async asyncData({$axios, error}) { + try { + const history = await $axios.get(`/api/public/history`) + return { + history: history.data + } + } catch (e) { + error({status: 404, message: 'There is problem here'}) } } } diff --git a/pages/_lang/blog/_post.vue b/pages/_lang/blog/_post.vue index d605e7a..447ad47 100644 --- a/pages/_lang/blog/_post.vue +++ b/pages/_lang/blog/_post.vue @@ -84,12 +84,16 @@ export default { title: this.post.post_details[this.$route.params.lang].title } }, - async asyncData({$axios, params}) { - const post = await $axios.get(`/api/public/blog/${params.post}`) - const blogCategories = await $axios.get(`/api/public/blogCategories`) - return { - post: post.data, - blogCategories: blogCategories.data + async asyncData({$axios, params, error}) { + try { + const post = await $axios.get(`/api/public/blog/${params.post}`) + const blogCategories = await $axios.get(`/api/public/blogCategories`) + return { + post: post.data, + blogCategories: blogCategories.data + } + } catch (e) { + error({status: 404, message: 'Page not found'}) } } } diff --git a/pages/_lang/blog/index.vue b/pages/_lang/blog/index.vue index 343e56d..baaf047 100644 --- a/pages/_lang/blog/index.vue +++ b/pages/_lang/blog/index.vue @@ -119,12 +119,16 @@ export default { title: this.staticData.hero } }, - async asyncData({$axios, store}) { - let posts = await $axios.get(`/api/public/blog`) - const blogCategories = await $axios.get(`/api/public/blogCategories`) - return { - posts: posts.data, - blogCategories: blogCategories.data + async asyncData({$axios, store, error}) { + try { + let posts = await $axios.get(`/api/public/blog`) + const blogCategories = await $axios.get(`/api/public/blogCategories`) + return { + posts: posts.data, + blogCategories: blogCategories.data + } + } catch (e) { + error({status: 404, message: 'There is a problem here'}) } } } diff --git a/pages/_lang/contact/index.vue b/pages/_lang/contact/index.vue index 1b0d43a..3a25ba3 100644 --- a/pages/_lang/contact/index.vue +++ b/pages/_lang/contact/index.vue @@ -179,10 +179,14 @@ export default { title: this.staticData.hero } }, - async asyncData({$axios}) { - const reasons = await $axios.get(`/api/public/contact/reason`) - return { - reasons: reasons.data + async asyncData({$axios, error}) { + try { + const reasons = await $axios.get(`/api/public/contact/reason`) + return { + reasons: reasons.data + } + } catch (e) { + error({status: 404, message: 'There is a problem here'}) } } } diff --git a/pages/_lang/index.vue b/pages/_lang/index.vue index a085e26..f656d6f 100644 --- a/pages/_lang/index.vue +++ b/pages/_lang/index.vue @@ -42,7 +42,7 @@

{{ staticData.s1_2.t2 }}

{{ staticData.s1_2.t3 }}

- {{ staticData.s1_2.link }} + {{ staticData.s1_2.link }}
@@ -247,15 +247,19 @@ export default { title: this.staticData.title } }, - async asyncData({$axios}) { - const slider = await $axios.get('/api/public/slider') - const favoriteProducts = await $axios.get(`/api/public/favoriteProducts`) - const catalog = await $axios.get('/api/public/catalog') + async asyncData({$axios, error}) { + try { + const slider = await $axios.get('/api/public/slider') + const favoriteProducts = await $axios.get(`/api/public/favoriteProducts`) + const catalog = await $axios.get('/api/public/catalog') - return { - slider: slider.data, - favoriteProducts: favoriteProducts.data, - catalog: catalog.data + return { + slider: slider.data, + favoriteProducts: favoriteProducts.data, + catalog: catalog.data + } + } catch (e) { + error({status: 404, message: 'There is a problem here'}) } } } diff --git a/pages/_lang/products/_product.vue b/pages/_lang/products/_product.vue index e14ee6b..c036aa7 100644 --- a/pages/_lang/products/_product.vue +++ b/pages/_lang/products/_product.vue @@ -177,12 +177,16 @@ export default { title: this.product.product_details[this.$route.params.lang].name } }, - async asyncData({$axios, params}) { - let product = await $axios.get(`/api/public/product/${params.product}`) - let productCategories = await $axios.get(`/api/public/productCategories`) - return { - product: product.data, - productCategories: productCategories.data + async asyncData({$axios, params, error}) { + try { + let product = await $axios.get(`/api/public/product/${params.product}`) + let productCategories = await $axios.get(`/api/public/productCategories`) + return { + product: product.data, + productCategories: productCategories.data + } + } catch (e) { + error({status: 404, message: 'Page not found'}) } } } diff --git a/pages/_lang/products/index.vue b/pages/_lang/products/index.vue index f168dcc..8cc281f 100644 --- a/pages/_lang/products/index.vue +++ b/pages/_lang/products/index.vue @@ -106,15 +106,19 @@ export default { title: this.staticData.hero } }, - async asyncData({$axios, store}) { - const products = await $axios.get(`/api/public/products`) - const productCategories = await $axios.get(`/api/public/productCategories`) - const catalog = await $axios.get('/api/public/catalog') + async asyncData({$axios, store, error}) { + try { + const products = await $axios.get(`/api/public/products`) + const productCategories = await $axios.get(`/api/public/productCategories`) + const catalog = await $axios.get('/api/public/catalog') - return { - products: products.data, - productCategories: productCategories.data, - catalog: catalog.data + return { + products: products.data, + productCategories: productCategories.data, + catalog: catalog.data + } + } catch (e) { + error({status: 404, message: 'There is a problem here'}) } } } diff --git a/pages/_lang/projects/index.vue b/pages/_lang/projects/index.vue index 7603f87..85a4a5e 100644 --- a/pages/_lang/projects/index.vue +++ b/pages/_lang/projects/index.vue @@ -107,10 +107,14 @@ export default { title: this.staticData.hero } }, - async asyncData({$axios}) { - const projects = await $axios.get(`/api/public/projects`) - return { - projects: projects.data + async asyncData({$axios, error}) { + try { + const projects = await $axios.get(`/api/public/projects`) + return { + projects: projects.data + } + } catch (e) { + error({status: 404, message: 'There is a problem here'}) } } } diff --git a/pages/_lang/services/index.vue b/pages/_lang/services/index.vue index a9ab963..e71629b 100644 --- a/pages/_lang/services/index.vue +++ b/pages/_lang/services/index.vue @@ -1,198 +1,198 @@ diff --git a/pages/_lang/tech/gTech.vue b/pages/_lang/tech/gTech.vue index 8f72fed..6f8c5b5 100644 --- a/pages/_lang/tech/gTech.vue +++ b/pages/_lang/tech/gTech.vue @@ -1,93 +1,93 @@ diff --git a/pages/admin/blog/_post.vue b/pages/admin/blog/_post.vue index 283e23f..c419be6 100644 --- a/pages/admin/blog/_post.vue +++ b/pages/admin/blog/_post.vue @@ -180,12 +180,16 @@ export default { } }, layout: 'admin', - async asyncData({$axios, params}) { - const post = await $axios.get(`/api/public/blog/${params.post}`) - const blogCategories = await $axios.get(`/api/public/blogCategories`) - return { - post: post.data, - blogCategories: blogCategories.data + async asyncData({$axios, params, error}) { + try { + const post = await $axios.get(`/api/public/blog/${params.post}`) + const blogCategories = await $axios.get(`/api/public/blogCategories`) + return { + post: post.data, + blogCategories: blogCategories.data + } + } catch (e) { + error({status: 404, message: 'Page not found'}) } } } diff --git a/pages/admin/blog/category/_category.vue b/pages/admin/blog/category/_category.vue index 9d23ed2..e9be46b 100644 --- a/pages/admin/blog/category/_category.vue +++ b/pages/admin/blog/category/_category.vue @@ -1,102 +1,106 @@ diff --git a/pages/admin/blog/category/index.vue b/pages/admin/blog/category/index.vue index a8808a3..1387505 100644 --- a/pages/admin/blog/category/index.vue +++ b/pages/admin/blog/category/index.vue @@ -1,97 +1,101 @@ diff --git a/pages/admin/blog/category/new.vue b/pages/admin/blog/category/new.vue index 42d9a4e..4fb2120 100644 --- a/pages/admin/blog/category/new.vue +++ b/pages/admin/blog/category/new.vue @@ -1,107 +1,105 @@ diff --git a/pages/admin/blog/index.vue b/pages/admin/blog/index.vue index 9da63f1..bb3dc02 100644 --- a/pages/admin/blog/index.vue +++ b/pages/admin/blog/index.vue @@ -1,132 +1,136 @@ diff --git a/pages/admin/blog/new.vue b/pages/admin/blog/new.vue index 7d120ad..5b278fd 100644 --- a/pages/admin/blog/new.vue +++ b/pages/admin/blog/new.vue @@ -1,207 +1,211 @@ diff --git a/pages/admin/catalog/index.vue b/pages/admin/catalog/index.vue index 83945ed..0f647e8 100644 --- a/pages/admin/catalog/index.vue +++ b/pages/admin/catalog/index.vue @@ -104,10 +104,14 @@ export default { } }, layout: 'admin', - async asyncData({$axios}) { - let catalog = await $axios.get('/api/public/catalog') - return { - catalog: catalog.data + async asyncData({$axios, error}) { + try { + let catalog = await $axios.get('/api/public/catalog') + return { + catalog: catalog.data + } + } catch (e) { + error({status: 404, message: 'There is a problem here'}) } } } diff --git a/pages/admin/history/_history.vue b/pages/admin/history/_history.vue index b760590..418a126 100644 --- a/pages/admin/history/_history.vue +++ b/pages/admin/history/_history.vue @@ -1,137 +1,141 @@ diff --git a/pages/admin/history/index.vue b/pages/admin/history/index.vue index c5dd681..cd8f472 100644 --- a/pages/admin/history/index.vue +++ b/pages/admin/history/index.vue @@ -1,119 +1,123 @@ diff --git a/pages/admin/history/new.vue b/pages/admin/history/new.vue index 87462ea..9c6c8ef 100644 --- a/pages/admin/history/new.vue +++ b/pages/admin/history/new.vue @@ -1,137 +1,137 @@ diff --git a/pages/admin/index.vue b/pages/admin/index.vue index c576ebc..6030fbe 100644 --- a/pages/admin/index.vue +++ b/pages/admin/index.vue @@ -1,18 +1,16 @@ diff --git a/pages/admin/login.vue b/pages/admin/login.vue index 59cea6a..5e9d056 100644 --- a/pages/admin/login.vue +++ b/pages/admin/login.vue @@ -61,6 +61,6 @@ export default { .login { width: 100%; max-width: 600px; - margin: 150px auto!important; + margin: 150px auto !important; } diff --git a/pages/admin/messages/_message.vue b/pages/admin/messages/_message.vue index eda2c48..3f05a89 100644 --- a/pages/admin/messages/_message.vue +++ b/pages/admin/messages/_message.vue @@ -1,79 +1,83 @@ diff --git a/pages/admin/messages/index.vue b/pages/admin/messages/index.vue index c4bbc55..014e11d 100644 --- a/pages/admin/messages/index.vue +++ b/pages/admin/messages/index.vue @@ -1,187 +1,191 @@ diff --git a/pages/admin/products/_product.vue b/pages/admin/products/_product.vue index c6fb2e5..a9f071f 100644 --- a/pages/admin/products/_product.vue +++ b/pages/admin/products/_product.vue @@ -589,12 +589,16 @@ export default { } }, layout: 'admin', - async asyncData({$axios, params}) { - let product = await $axios.get(`/api/public/product/${params.product}`) - let productCategories = await $axios.get(`/api/public/productCategories`) - return { - formData: product.data, - productCategories: productCategories.data + async asyncData({$axios, params, error}) { + try { + let product = await $axios.get(`/api/public/product/${params.product}`) + let productCategories = await $axios.get(`/api/public/productCategories`) + return { + formData: product.data, + productCategories: productCategories.data + } + } catch (e) { + error({status: 404, message: 'Page not found'}) } } } diff --git a/pages/admin/products/category/_category.vue b/pages/admin/products/category/_category.vue index 8f7b252..bc1df6f 100644 --- a/pages/admin/products/category/_category.vue +++ b/pages/admin/products/category/_category.vue @@ -1,104 +1,108 @@ diff --git a/pages/admin/products/category/index.vue b/pages/admin/products/category/index.vue index f2334c3..ca9e23d 100644 --- a/pages/admin/products/category/index.vue +++ b/pages/admin/products/category/index.vue @@ -1,98 +1,102 @@ diff --git a/pages/admin/products/category/new.vue b/pages/admin/products/category/new.vue index dfbbf74..d5433fc 100644 --- a/pages/admin/products/category/new.vue +++ b/pages/admin/products/category/new.vue @@ -1,102 +1,101 @@ diff --git a/pages/admin/products/index.vue b/pages/admin/products/index.vue index e18fdf1..4f716a8 100644 --- a/pages/admin/products/index.vue +++ b/pages/admin/products/index.vue @@ -130,12 +130,16 @@ export default { } }, layout: 'admin', - async asyncData({$axios, store}) { - let products = await $axios.get(`/api/public/products`) - let productCategories = await $axios.get(`/api/public/productCategories`) - return { - products: products.data, - productCategories: productCategories.data + async asyncData({$axios, store, error}) { + try { + let products = await $axios.get(`/api/public/products`) + let productCategories = await $axios.get(`/api/public/productCategories`) + return { + products: products.data, + productCategories: productCategories.data + } + } catch (e) { + error({status: 404, message: 'There is a problem here'}) } } } diff --git a/pages/admin/products/new.vue b/pages/admin/products/new.vue index 7f26a96..9cd2ea1 100644 --- a/pages/admin/products/new.vue +++ b/pages/admin/products/new.vue @@ -435,10 +435,14 @@ export default { } }, layout: 'admin', - async asyncData({$axios, store}) { - let productCategories = await $axios.get(`/api/public/productCategories`) - return { - productCategories: productCategories.data + async asyncData({$axios, store, error}) { + try { + let productCategories = await $axios.get(`/api/public/productCategories`) + return { + productCategories: productCategories.data + } + } catch (e) { + error({status: 404, message: 'There is a problem here'}) } } } diff --git a/pages/admin/projects/_project.vue b/pages/admin/projects/_project.vue index c1f78df..6e24e9a 100644 --- a/pages/admin/projects/_project.vue +++ b/pages/admin/projects/_project.vue @@ -1,237 +1,241 @@ diff --git a/pages/admin/projects/index.vue b/pages/admin/projects/index.vue index ac16172..795a76e 100644 --- a/pages/admin/projects/index.vue +++ b/pages/admin/projects/index.vue @@ -1,125 +1,129 @@ diff --git a/pages/admin/projects/new.vue b/pages/admin/projects/new.vue index 1bd547f..dada914 100644 --- a/pages/admin/projects/new.vue +++ b/pages/admin/projects/new.vue @@ -1,137 +1,136 @@ diff --git a/pages/admin/slider/_slide.vue b/pages/admin/slider/_slide.vue index 147249d..646a010 100644 --- a/pages/admin/slider/_slide.vue +++ b/pages/admin/slider/_slide.vue @@ -1,131 +1,133 @@ diff --git a/pages/admin/slider/index.vue b/pages/admin/slider/index.vue index c1f27db..3c6dd22 100644 --- a/pages/admin/slider/index.vue +++ b/pages/admin/slider/index.vue @@ -1,114 +1,118 @@ diff --git a/pages/admin/slider/new.vue b/pages/admin/slider/new.vue index d1801de..7dcfadd 100644 --- a/pages/admin/slider/new.vue +++ b/pages/admin/slider/new.vue @@ -1,129 +1,127 @@