handle all not found errors

This commit is contained in:
Amir Mohamadi
2021-12-31 17:01:17 +03:30
parent 5c07791225
commit 064d642b7e
47 changed files with 3386 additions and 3238 deletions
+3 -3
View File
@@ -86,7 +86,7 @@ module.exports.login = [
if (!errors.isEmpty()) return res.status(422).json({validation: errors.mapped()}) if (!errors.isEmpty()) return res.status(422).json({validation: errors.mapped()})
Admin.findOne({username: req.body.username}, (err, user) => { Admin.findOne({username: req.body.username}, (err, user) => {
if (err) console.log(err) if (err) return res.status(404).json({message: err})
bcrypt.compare(req.body.password, user.password, (err, isMatch) => { bcrypt.compare(req.body.password, user.password, (err, isMatch) => {
if (err) console.log(err) if (err) console.log(err)
if (!isMatch) return res.status(422).json({validation: {password: {msg: v_m['fa'].not_found.password}}}) if (!isMatch) return res.status(422).json({validation: {password: {msg: v_m['fa'].not_found.password}}})
@@ -111,7 +111,7 @@ module.exports.logout = [
const token = req.headers.authorization const token = req.headers.authorization
if (token) { if (token) {
Admin.findOneAndUpdate({token: token}, {token: null}, (err, oldData) => { Admin.findOneAndUpdate({token: token}, {token: null}, (err, oldData) => {
if (err) console.log(err) if (err) return res.status(404).json({message: err})
if (oldData) return res.json({message: v_m['fa'].response.logged_out}) 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}) return res.status(401).json({message: v_m['fa'].response.not_logged_in})
}) })
@@ -130,7 +130,7 @@ module.exports.getUser = [
jwt.verify(token, config.secretKey, (err, decoded) => { jwt.verify(token, config.secretKey, (err, decoded) => {
if (err) return res.status(401).json({message: 'unauthenticated'}) if (err) return res.status(401).json({message: 'unauthenticated'})
Admin.findById(decoded._id, (err, data) => { Admin.findById(decoded._id, (err, data) => {
if (err) console.log(err) if (err) return res.status(404).json({message: err})
return res.json({user: data}) return res.json({user: data})
}) })
}) })
+4 -4
View File
@@ -105,7 +105,7 @@ module.exports.update = [
updated_at: dateformat(Date.now(), 'yyyy-mm-dd HH:MM:ss') updated_at: dateformat(Date.now(), 'yyyy-mm-dd HH:MM:ss')
} }
BlogCategory.findByIdAndUpdate(req.params.id, data, (err, oldData) => { 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}) return res.json({message: v_m['fa'].response.success_save})
}) })
} }
@@ -115,10 +115,10 @@ module.exports.update = [
module.exports.delete = [ module.exports.delete = [
(req, res) => { (req, res) => {
BlogPost.find({category: req.params.id}, (err, posts) => { BlogPost.find({category: req.params.id}, (err, posts) => {
if (err) console.log(err)
if (!posts.length) {
BlogCategory.findByIdAndDelete(req.params.id, (err) => {
if (err) return res.status(404).json({message: err}) if (err) return res.status(404).json({message: err})
if (!posts.length) {
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}) return res.json({message: v_m['fa'].response.success_save})
}) })
} else { } else {
+15 -9
View File
@@ -80,6 +80,9 @@ module.exports.create = [
.cover(thumbWith, thumbHeight) .cover(thumbWith, thumbHeight)
.write(`./static/uploads/images/blog/thumb_${coverName}`) .write(`./static/uploads/images/blog/thumb_${coverName}`)
}) })
.catch(err => {
console.log(err)
})
const data = { const data = {
post_details: { post_details: {
@@ -112,7 +115,7 @@ module.exports.create = [
module.exports.getAll = [ module.exports.getAll = [
(req, res) => { (req, res) => {
BlogPost.find({}).sort({_id: -1}).exec((err, posts) => { 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) return res.json(posts)
}) })
} }
@@ -122,7 +125,7 @@ module.exports.getAll = [
module.exports.getOne = [ module.exports.getOne = [
(req, res) => { (req, res) => {
BlogPost.findById(req.params.id, (err, post) => { 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) return res.json(post)
}) })
} }
@@ -213,10 +216,13 @@ module.exports.update = [
.cover(thumbWith, thumbHeight) .cover(thumbWith, thumbHeight)
.write(`./static/uploads/images/blog/thumb_${coverName}`) .write(`./static/uploads/images/blog/thumb_${coverName}`)
}) })
.catch(err => {
console.log(err)
})
} }
BlogPost.findByIdAndUpdate(req.params.id, data, (err, oldData) => { 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) { if (cover && cover.data) {
fs.unlink(`./static/${oldData.cover}`, err => { fs.unlink(`./static/${oldData.cover}`, err => {
if (err) console.log(err) if (err) console.log(err)
@@ -225,8 +231,8 @@ module.exports.update = [
if (err) console.log(err) if (err) console.log(err)
}) })
} }
BlogPost.findById(oldData._id, (err, newData) => { BlogPost.findById(oldData._id, (err1, newData) => {
if (err) console.log(err) if (err1) return res.status(404).json({message: err1})
return res.json(newData) return res.json(newData)
}) })
}) })
@@ -238,11 +244,11 @@ module.exports.delete = [
(req, res) => { (req, res) => {
BlogPost.findByIdAndDelete(req.params.id, (err, post) => { BlogPost.findByIdAndDelete(req.params.id, (err, post) => {
if (err) return res.status(404).json({message: err}) if (err) return res.status(404).json({message: err})
fs.unlink(`./static/${post.cover}`, err => { fs.unlink(`./static/${post.cover}`, err1 => {
if (err) console.log(err) if (err1) console.log(err1)
}) })
fs.unlink(`./static/${post.thumb}`, err => { fs.unlink(`./static/${post.thumb}`, err2 => {
if (err) console.log(err) if (err2) console.log(err2)
}) })
return res.json({message: v_m['fa'].response.success_remove}) return res.json({message: v_m['fa'].response.success_remove})
}) })
+2 -2
View File
@@ -92,7 +92,7 @@ module.exports.getAll = [
}) })
.catch(err => { .catch(err => {
console.log(err) console.log(err)
return res.status(500).json(err) return res.status(500).json({message: err})
}) })
} }
] ]
@@ -107,7 +107,7 @@ module.exports.getOne = [
return res.json(message) return res.json(message)
}) })
.catch(err => { .catch(err => {
return res.status(404).json(err) return res.status(404).json({message: err})
}) })
} }
] ]
+1 -1
View File
@@ -51,7 +51,7 @@ module.exports.getAll = [
module.exports.delete = [ module.exports.delete = [
(req, res) => { (req, res) => {
Reason.findByIdAndDelete(req.params.id, (err, reason) => { Reason.findByIdAndDelete(req.params.id, (err, reason) => {
if (err) console.log(err) if (err) return res.status(404).json({message: err})
return res.json({message: v_m['fa'].response.success_remove}) return res.json({message: v_m['fa'].response.success_remove})
}) })
} }
+3 -3
View File
@@ -84,7 +84,7 @@ module.exports.getAll = [
module.exports.getOne = [ module.exports.getOne = [
(req, res) => { (req, res) => {
History.findById(req.params.id, (err, data) => { 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) return res.json(data)
}) })
} }
@@ -151,7 +151,7 @@ module.exports.update = [
}) })
} else { } else {
History.findByIdAndUpdate(req.params.id, data, (err, oldData) => { 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) return res.json(v_m['fa'].response.success_save)
}) })
} }
@@ -162,7 +162,7 @@ module.exports.update = [
module.exports.delete = [ module.exports.delete = [
(req, res) => { (req, res) => {
History.findByIdAndDelete(req.params.id, (err, data) => { 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 => { fs.unlink(`./static/${data.image}`, err => {
if (err) console.log(err) if (err) console.log(err)
return res.json(v_m['fa'].response.success_remove) return res.json(v_m['fa'].response.success_remove)
+1 -4
View File
@@ -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 || !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}}}) 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) => { MainCatalog.find({}, (err, catalogs) => {
if (err) console.log(err)
if (catalogs.length) { if (catalogs.length) {
let firstFile = catalogs[0] let firstFile = catalogs[0]
if (firstFile.file[req.body.locale]) fs.unlink(`./static/${firstFile.file[req.body.locale]}`, err => { if (firstFile.file[req.body.locale]) fs.unlink(`./static/${firstFile.file[req.body.locale]}`, err => {
if (err) console.log(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}`) req.files.pdf.mv(`./static/uploads/pdf/${req.body.locale}_${req.files.pdf.name}`)
return res.json(firstFile) return res.json(firstFile)
}) })
} else { } else {
const data = {created_at: dateformat(Date.now(), 'yyyy-mm-dd HH:MM:ss'), file: {}} 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 data.file[req.body.locale] = req.body.locale + '_' + req.files.pdf.name
+41 -2
View File
@@ -168,6 +168,9 @@ module.exports.createProduct = [
.quality(thumbQuality) .quality(thumbQuality)
.write(`./static/uploads/images/products/${thumb}`) .write(`./static/uploads/images/products/${thumb}`)
}) })
.catch(err => {
console.log(err)
})
} }
if (req.files.more_section_image1) { if (req.files.more_section_image1) {
await jimp.read(req.files.more_section_image1.data) await jimp.read(req.files.more_section_image1.data)
@@ -178,6 +181,9 @@ module.exports.createProduct = [
.quality(moreSectionQuality) .quality(moreSectionQuality)
.write(`./static/uploads/images/products/${more_section_image1}`) .write(`./static/uploads/images/products/${more_section_image1}`)
}) })
.catch(err => {
console.log(err)
})
} }
if (req.files.more_section_image2) { if (req.files.more_section_image2) {
await jimp.read(req.files.more_section_image2.data) await jimp.read(req.files.more_section_image2.data)
@@ -188,6 +194,9 @@ module.exports.createProduct = [
.quality(moreSectionQuality) .quality(moreSectionQuality)
.write(`./static/uploads/images/products/${more_section_image2}`) .write(`./static/uploads/images/products/${more_section_image2}`)
}) })
.catch(err => {
console.log(err)
})
} }
if (req.files.render_image1) { if (req.files.render_image1) {
await jimp.read(req.files.render_image1.data) await jimp.read(req.files.render_image1.data)
@@ -198,6 +207,9 @@ module.exports.createProduct = [
.quality(renderImageQuality) .quality(renderImageQuality)
.write(`./static/uploads/images/products/${render_image1}`) .write(`./static/uploads/images/products/${render_image1}`)
}) })
.catch(err => {
console.log(err)
})
} }
if (req.files.render_image2) { if (req.files.render_image2) {
await jimp.read(req.files.render_image2.data) await jimp.read(req.files.render_image2.data)
@@ -208,6 +220,9 @@ module.exports.createProduct = [
.quality(renderImageQuality) .quality(renderImageQuality)
.write(`./static/uploads/images/products/${render_image2}`) .write(`./static/uploads/images/products/${render_image2}`)
}) })
.catch(err => {
console.log(err)
})
} }
if (req.files.chart_image) { if (req.files.chart_image) {
await jimp.read(req.files.chart_image.data) await jimp.read(req.files.chart_image.data)
@@ -216,6 +231,9 @@ module.exports.createProduct = [
.quality(chartImageQuality) .quality(chartImageQuality)
.write(`./static/uploads/images/products/${chart_image}`) .write(`./static/uploads/images/products/${chart_image}`)
}) })
.catch(err => {
console.log(err)
})
} }
} }
@@ -249,8 +267,8 @@ module.exports.getAllProducts = [
] ]
module.exports.getOneProduct = [ module.exports.getOneProduct = [
async (req, res) => { (req, res) => {
await Product.findById(req.params.id, async (err, product) => { Product.findById(req.params.id, (err, product) => {
if (err) return res.status(404).json({message: err}) if (err) return res.status(404).json({message: err})
return res.json(product) return res.json(product)
}) })
@@ -394,6 +412,9 @@ module.exports.updateProduct = [
.quality(thumbQuality) .quality(thumbQuality)
.write(`./static/uploads/images/products/${thumb}`) .write(`./static/uploads/images/products/${thumb}`)
}) })
.catch(err => {
console.log(err)
})
} }
if (req.files.more_section_image1) { if (req.files.more_section_image1) {
@@ -406,6 +427,9 @@ module.exports.updateProduct = [
.quality(moreSectionQuality) .quality(moreSectionQuality)
.write(`./static/uploads/images/products/${more_section_image1}`) .write(`./static/uploads/images/products/${more_section_image1}`)
}) })
.catch(err => {
console.log(err)
})
} }
if (req.files.more_section_image2) { if (req.files.more_section_image2) {
@@ -418,6 +442,9 @@ module.exports.updateProduct = [
.quality(moreSectionQuality) .quality(moreSectionQuality)
.write(`./static/uploads/images/products/${more_section_image2}`) .write(`./static/uploads/images/products/${more_section_image2}`)
}) })
.catch(err => {
console.log(err)
})
} }
if (req.files.render_image1) { if (req.files.render_image1) {
@@ -430,6 +457,9 @@ module.exports.updateProduct = [
.quality(renderImageQuality) .quality(renderImageQuality)
.write(`./static/uploads/images/products/${render_image1}`) .write(`./static/uploads/images/products/${render_image1}`)
}) })
.catch(err => {
console.log(err)
})
} }
if (req.files.render_image2) { if (req.files.render_image2) {
@@ -442,6 +472,9 @@ module.exports.updateProduct = [
.quality(renderImageQuality) .quality(renderImageQuality)
.write(`./static/uploads/images/products/${render_image2}`) .write(`./static/uploads/images/products/${render_image2}`)
}) })
.catch(err => {
console.log(err)
})
} }
if (req.files.chart_image) { if (req.files.chart_image) {
@@ -452,6 +485,9 @@ module.exports.updateProduct = [
.quality(chartImageQuality) .quality(chartImageQuality)
.write(`./static/uploads/images/products/${chart_image}`) .write(`./static/uploads/images/products/${chart_image}`)
}) })
.catch(err => {
console.log(err)
})
} }
} }
@@ -584,6 +620,9 @@ module.exports.createProductImage = [
return res.json(product) return res.json(product)
}) })
}) })
.catch(err => {
console.log(err)
})
} else { } else {
return res.status(422).json({validation: {images: {image: {msg: v_m['fa'].required.image}}}}) return res.status(422).json({validation: {images: {image: {msg: v_m['fa'].required.image}}}})
+7 -3
View File
@@ -74,7 +74,7 @@ module.exports.getAll = [
module.exports.getOne = [ module.exports.getOne = [
(req, res) => { (req, res) => {
Project.findById(req.params.id, (err, project) => { Project.findById(req.params.id, (err, project) => {
if (err) return res.json({errors: err}) if (err) return res.status(404).json({errors: err})
return res.json(project) return res.json(project)
}) })
} }
@@ -128,7 +128,7 @@ module.exports.update = [
} }
Project.findByIdAndUpdate(req.params.id, data, (err, oldData) => { Project.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}) return res.json({message: v_m['fa'].response.success_save})
}) })
} }
@@ -138,11 +138,15 @@ module.exports.update = [
module.exports.delete = [ module.exports.delete = [
(req, res) => { (req, res) => {
Project.findByIdAndRemove(req.params.id, (err, data) => { Project.findByIdAndRemove(req.params.id, (err, data) => {
if (err) return res.json({error: err}) if (err) return res.status(404).json({message: err})
data.images.forEach(async item => { data.images.forEach(async item => {
try {
await fs.unlink(`./static/${item.image}`, err => { await fs.unlink(`./static/${item.image}`, err => {
if (err) console.log(err) if (err) console.log(err)
}) })
} catch (e) {
console.log(e)
}
}) })
return res.json({message: v_m['fa'].response.success_remove}) return res.json({message: v_m['fa'].response.success_remove})
}) })
+5 -1
View File
@@ -37,7 +37,7 @@
<nuxt-link :to="{name: 'lang',params: {lang: $route.params.lang}}" tag="li" exact class=""> <nuxt-link :to="{name: 'lang',params: {lang: $route.params.lang}}" tag="li" exact class="">
<a>{{ staticData.home }}</a> <a>{{ staticData.home }}</a>
</nuxt-link> </nuxt-link>
<nuxt-link :to="{name: 'lang-about',params: {lang: $route.params.lang}}" tag="li" exact class=""> <nuxt-link :to="{name: 'lang-about',params: {lang: $route.params.lang}}" tag="li" class="">
<a>{{ staticData.about }}</a> <a>{{ staticData.about }}</a>
</nuxt-link> </nuxt-link>
<nuxt-link :to="{name: 'lang-services',params: {lang: $route.params.lang}}" tag="li" exact class=""> <nuxt-link :to="{name: 'lang-services',params: {lang: $route.params.lang}}" tag="li" exact class="">
@@ -114,8 +114,12 @@ export default {
} }
}, },
async fetch() { async fetch() {
try {
let catalog = await this.$axios.get('/api/public/catalog') let catalog = await this.$axios.get('/api/public/catalog')
this.catalog = catalog.data this.catalog = catalog.data
} catch (e) {
this.$nuxt.context.error({status: 404, message: 'Catalog file not found'})
}
}, },
computed: { computed: {
staticData() { staticData() {
+6 -2
View File
@@ -44,7 +44,7 @@
</div> </div>
</section> </section>
<section class="s2" v-if="history.length"> <section class="s2" v-if="history.length" id="history_timeline">
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
@@ -157,11 +157,15 @@ export default {
title: this.staticData.hero title: this.staticData.hero
} }
}, },
async asyncData({$axios}) { async asyncData({$axios, error}) {
try {
const history = await $axios.get(`/api/public/history`) const history = await $axios.get(`/api/public/history`)
return { return {
history: history.data history: history.data
} }
} catch (e) {
error({status: 404, message: 'There is problem here'})
}
} }
} }
</script> </script>
+5 -1
View File
@@ -84,13 +84,17 @@ export default {
title: this.post.post_details[this.$route.params.lang].title title: this.post.post_details[this.$route.params.lang].title
} }
}, },
async asyncData({$axios, params}) { async asyncData({$axios, params, error}) {
try {
const post = await $axios.get(`/api/public/blog/${params.post}`) const post = await $axios.get(`/api/public/blog/${params.post}`)
const blogCategories = await $axios.get(`/api/public/blogCategories`) const blogCategories = await $axios.get(`/api/public/blogCategories`)
return { return {
post: post.data, post: post.data,
blogCategories: blogCategories.data blogCategories: blogCategories.data
} }
} catch (e) {
error({status: 404, message: 'Page not found'})
}
} }
} }
</script> </script>
+5 -1
View File
@@ -119,13 +119,17 @@ export default {
title: this.staticData.hero title: this.staticData.hero
} }
}, },
async asyncData({$axios, store}) { async asyncData({$axios, store, error}) {
try {
let posts = await $axios.get(`/api/public/blog`) let posts = await $axios.get(`/api/public/blog`)
const blogCategories = await $axios.get(`/api/public/blogCategories`) const blogCategories = await $axios.get(`/api/public/blogCategories`)
return { return {
posts: posts.data, posts: posts.data,
blogCategories: blogCategories.data blogCategories: blogCategories.data
} }
} catch (e) {
error({status: 404, message: 'There is a problem here'})
}
} }
} }
</script> </script>
+5 -1
View File
@@ -179,11 +179,15 @@ export default {
title: this.staticData.hero title: this.staticData.hero
} }
}, },
async asyncData({$axios}) { async asyncData({$axios, error}) {
try {
const reasons = await $axios.get(`/api/public/contact/reason`) const reasons = await $axios.get(`/api/public/contact/reason`)
return { return {
reasons: reasons.data reasons: reasons.data
} }
} catch (e) {
error({status: 404, message: 'There is a problem here'})
}
} }
} }
</script> </script>
+6 -2
View File
@@ -42,7 +42,7 @@
<div class="col-12"> <div class="col-12">
<p>{{ staticData.s1_2.t2 }}</p> <p>{{ staticData.s1_2.t2 }}</p>
<p>{{ staticData.s1_2.t3 }}</p> <p>{{ staticData.s1_2.t3 }}</p>
<nuxt-link :to="{name: 'lang-about',params: {lang: $route.params.lang}}" class="btn btn-primary">{{ staticData.s1_2.link }}</nuxt-link> <nuxt-link :to="{name: 'lang-about',params: {lang: $route.params.lang},hash: '#history_timeline'}" class="btn btn-primary">{{ staticData.s1_2.link }}</nuxt-link>
</div> </div>
</div> </div>
</div> </div>
@@ -247,7 +247,8 @@ export default {
title: this.staticData.title title: this.staticData.title
} }
}, },
async asyncData({$axios}) { async asyncData({$axios, error}) {
try {
const slider = await $axios.get('/api/public/slider') const slider = await $axios.get('/api/public/slider')
const favoriteProducts = await $axios.get(`/api/public/favoriteProducts`) const favoriteProducts = await $axios.get(`/api/public/favoriteProducts`)
const catalog = await $axios.get('/api/public/catalog') const catalog = await $axios.get('/api/public/catalog')
@@ -257,6 +258,9 @@ export default {
favoriteProducts: favoriteProducts.data, favoriteProducts: favoriteProducts.data,
catalog: catalog.data catalog: catalog.data
} }
} catch (e) {
error({status: 404, message: 'There is a problem here'})
}
} }
} }
</script> </script>
+5 -1
View File
@@ -177,13 +177,17 @@ export default {
title: this.product.product_details[this.$route.params.lang].name title: this.product.product_details[this.$route.params.lang].name
} }
}, },
async asyncData({$axios, params}) { async asyncData({$axios, params, error}) {
try {
let product = await $axios.get(`/api/public/product/${params.product}`) let product = await $axios.get(`/api/public/product/${params.product}`)
let productCategories = await $axios.get(`/api/public/productCategories`) let productCategories = await $axios.get(`/api/public/productCategories`)
return { return {
product: product.data, product: product.data,
productCategories: productCategories.data productCategories: productCategories.data
} }
} catch (e) {
error({status: 404, message: 'Page not found'})
}
} }
} }
</script> </script>
+5 -1
View File
@@ -106,7 +106,8 @@ export default {
title: this.staticData.hero title: this.staticData.hero
} }
}, },
async asyncData({$axios, store}) { async asyncData({$axios, store, error}) {
try {
const products = await $axios.get(`/api/public/products`) const products = await $axios.get(`/api/public/products`)
const productCategories = await $axios.get(`/api/public/productCategories`) const productCategories = await $axios.get(`/api/public/productCategories`)
const catalog = await $axios.get('/api/public/catalog') const catalog = await $axios.get('/api/public/catalog')
@@ -116,6 +117,9 @@ export default {
productCategories: productCategories.data, productCategories: productCategories.data,
catalog: catalog.data catalog: catalog.data
} }
} catch (e) {
error({status: 404, message: 'There is a problem here'})
}
} }
} }
</script> </script>
+5 -1
View File
@@ -107,11 +107,15 @@ export default {
title: this.staticData.hero title: this.staticData.hero
} }
}, },
async asyncData({$axios}) { async asyncData({$axios, error}) {
try {
const projects = await $axios.get(`/api/public/projects`) const projects = await $axios.get(`/api/public/projects`)
return { return {
projects: projects.data projects: projects.data
} }
} catch (e) {
error({status: 404, message: 'There is a problem here'})
}
} }
} }
</script> </script>
+5 -1
View File
@@ -180,13 +180,17 @@ export default {
} }
}, },
layout: 'admin', layout: 'admin',
async asyncData({$axios, params}) { async asyncData({$axios, params, error}) {
try {
const post = await $axios.get(`/api/public/blog/${params.post}`) const post = await $axios.get(`/api/public/blog/${params.post}`)
const blogCategories = await $axios.get(`/api/public/blogCategories`) const blogCategories = await $axios.get(`/api/public/blogCategories`)
return { return {
post: post.data, post: post.data,
blogCategories: blogCategories.data blogCategories: blogCategories.data
} }
} catch (e) {
error({status: 404, message: 'Page not found'})
}
} }
} }
</script> </script>
+5 -1
View File
@@ -92,11 +92,15 @@
} }
}, },
layout: 'admin', layout: 'admin',
async asyncData({$axios, params}) { async asyncData({$axios, params, error}) {
try {
const category = await $axios.get(`/api/public/blogCategories/${params.category}`) const category = await $axios.get(`/api/public/blogCategories/${params.category}`)
return { return {
formData: category.data formData: category.data
} }
} catch (e) {
error({status: 404, message: 'Page not found'})
}
} }
} }
</script> </script>
+5 -1
View File
@@ -87,11 +87,15 @@
} }
}, },
layout: 'admin', layout: 'admin',
async asyncData({$axios}) { async asyncData({$axios, error}) {
try {
let blogCategories = await $axios.get(`/api/public/blogCategories`) let blogCategories = await $axios.get(`/api/public/blogCategories`)
return { return {
blogCategories: blogCategories.data blogCategories: blogCategories.data
} }
} catch (e) {
error({status: 404, message: 'There is a problem here'})
}
} }
} }
</script> </script>
+1 -3
View File
@@ -89,11 +89,9 @@
}) })
} else { } else {
this.$alert(error.response.data.message, 'خطا', { this.$alert(error.response.data.message, 'خطا', {
confirmButtonText: 'باشه', confirmButtonText: 'باشه'
}) })
} }
}) })
} }
}, },
+5 -1
View File
@@ -120,13 +120,17 @@
} }
}, },
layout: 'admin', layout: 'admin',
async asyncData({$axios, store}) { async asyncData({$axios, store, error}) {
try {
let posts = await $axios.get(`/api/public/blog`) let posts = await $axios.get(`/api/public/blog`)
const blogCategories = await $axios.get(`/api/public/blogCategories`) const blogCategories = await $axios.get(`/api/public/blogCategories`)
return { return {
posts: posts.data, posts: posts.data,
blogCategories: blogCategories.data blogCategories: blogCategories.data
} }
} catch (e) {
error({status: 404, message: 'There is a problem here'})
}
} }
} }
</script> </script>
+6 -2
View File
@@ -188,7 +188,7 @@
}) })
}, },
preview(event) { preview(event) {
this.post.cover = URL.createObjectURL(event.target.files[0]); this.post.cover = URL.createObjectURL(event.target.files[0])
} }
}, },
head() { head() {
@@ -197,11 +197,15 @@
} }
}, },
layout: 'admin', layout: 'admin',
async asyncData({$axios, store}) { async asyncData({$axios, store, error}) {
try {
const blogCategories = await $axios.get(`/api/public/blogCategories`) const blogCategories = await $axios.get(`/api/public/blogCategories`)
return { return {
blogCategories: blogCategories.data blogCategories: blogCategories.data
} }
} catch (e) {
error({status: 404, message: 'There is a problem here'})
}
} }
} }
</script> </script>
+5 -1
View File
@@ -104,11 +104,15 @@ export default {
} }
}, },
layout: 'admin', layout: 'admin',
async asyncData({$axios}) { async asyncData({$axios, error}) {
try {
let catalog = await $axios.get('/api/public/catalog') let catalog = await $axios.get('/api/public/catalog')
return { return {
catalog: catalog.data catalog: catalog.data
} }
} catch (e) {
error({status: 404, message: 'There is a problem here'})
}
} }
} }
</script> </script>
+5 -1
View File
@@ -127,11 +127,15 @@
} }
}, },
layout: 'admin', layout: 'admin',
async asyncData({$axios, route}) { async asyncData({$axios, route, error}) {
try {
const history = await $axios.get(`/api/public/history/${route.params.history}`) const history = await $axios.get(`/api/public/history/${route.params.history}`)
return { return {
formData: history.data formData: history.data
} }
} catch (e) {
error({status: 404, message: 'Page not found'})
}
} }
} }
</script> </script>
+5 -1
View File
@@ -102,11 +102,15 @@
} }
}, },
layout: 'admin', layout: 'admin',
async asyncData({$axios, store}) { async asyncData({$axios, store, error}) {
try {
let history = await $axios.get(`/api/public/history`) let history = await $axios.get(`/api/public/history`)
return { return {
history: history.data history: history.data
} }
} catch (e) {
error({status: 404, message: 'There is a problem here'})
}
} }
} }
</script> </script>
+1 -1
View File
@@ -124,7 +124,7 @@
}) })
}, },
preview(event) { preview(event) {
this.formData.image = URL.createObjectURL(event.target.files[0]); this.formData.image = URL.createObjectURL(event.target.files[0])
} }
}, },
head() { head() {
-2
View File
@@ -11,8 +11,6 @@
<script> <script>
export default { export default {
mounted() {
},
layout: 'admin' layout: 'admin'
} }
</script> </script>
+5 -1
View File
@@ -62,11 +62,15 @@
} }
}, },
layout: 'admin', layout: 'admin',
async asyncData({$axios, params}) { async asyncData({$axios, params, error}) {
try {
const message = await $axios.get(`/api/private/contact/${params.message}`) const message = await $axios.get(`/api/private/contact/${params.message}`)
return { return {
message: message.data message: message.data
} }
} catch (e) {
error({status: 404, message: 'Page not found'})
}
} }
} }
</script> </script>
+5 -1
View File
@@ -163,13 +163,17 @@
} }
}, },
layout: 'admin', layout: 'admin',
async asyncData({$axios}) { async asyncData({$axios, error}) {
try {
let messages = await $axios.get('/api/private/contact') let messages = await $axios.get('/api/private/contact')
let reasons = await $axios.get('/api/public/contact/reason') let reasons = await $axios.get('/api/public/contact/reason')
return { return {
messages: messages.data, messages: messages.data,
reasons: reasons.data reasons: reasons.data
} }
} catch (e) {
error({status: 404, message: 'there is a problem here'})
}
} }
} }
</script> </script>
+5 -1
View File
@@ -589,13 +589,17 @@ export default {
} }
}, },
layout: 'admin', layout: 'admin',
async asyncData({$axios, params}) { async asyncData({$axios, params, error}) {
try {
let product = await $axios.get(`/api/public/product/${params.product}`) let product = await $axios.get(`/api/public/product/${params.product}`)
let productCategories = await $axios.get(`/api/public/productCategories`) let productCategories = await $axios.get(`/api/public/productCategories`)
return { return {
formData: product.data, formData: product.data,
productCategories: productCategories.data productCategories: productCategories.data
} }
} catch (e) {
error({status: 404, message: 'Page not found'})
}
} }
} }
</script> </script>
+5 -1
View File
@@ -94,11 +94,15 @@
} }
}, },
layout: 'admin', layout: 'admin',
async asyncData({$axios, params}) { async asyncData({$axios, params, error}) {
try {
const category = await $axios.get(`/api/public/productCategories/${params.category}`) const category = await $axios.get(`/api/public/productCategories/${params.category}`)
return { return {
formData: category.data formData: category.data
} }
} catch (e) {
error({status: 404, message: 'Page not found'})
}
} }
} }
</script> </script>
+5 -1
View File
@@ -88,11 +88,15 @@
} }
}, },
layout: 'admin', layout: 'admin',
async asyncData({$axios}) { async asyncData({$axios, error}) {
try {
let categories = await $axios.get(`/api/public/productCategories`); let categories = await $axios.get(`/api/public/productCategories`);
return { return {
categories: categories.data categories: categories.data
} }
} catch (e) {
error({status: 404, message: 'There is a problem here'})
}
} }
} }
</script> </script>
+1 -2
View File
@@ -85,8 +85,7 @@
}) })
} else { } else {
this.$alert(error.response.data.message, 'خطا', { this.$alert(error.response.data.message, 'خطا', {
confirmButtonText: 'باشه', confirmButtonText: 'باشه'
}) })
} }
}) })
+5 -1
View File
@@ -130,13 +130,17 @@ export default {
} }
}, },
layout: 'admin', layout: 'admin',
async asyncData({$axios, store}) { async asyncData({$axios, store, error}) {
try {
let products = await $axios.get(`/api/public/products`) let products = await $axios.get(`/api/public/products`)
let productCategories = await $axios.get(`/api/public/productCategories`) let productCategories = await $axios.get(`/api/public/productCategories`)
return { return {
products: products.data, products: products.data,
productCategories: productCategories.data productCategories: productCategories.data
} }
} catch (e) {
error({status: 404, message: 'There is a problem here'})
}
} }
} }
</script> </script>
+5 -1
View File
@@ -435,11 +435,15 @@ export default {
} }
}, },
layout: 'admin', layout: 'admin',
async asyncData({$axios, store}) { async asyncData({$axios, store, error}) {
try {
let productCategories = await $axios.get(`/api/public/productCategories`) let productCategories = await $axios.get(`/api/public/productCategories`)
return { return {
productCategories: productCategories.data productCategories: productCategories.data
} }
} catch (e) {
error({status: 404, message: 'There is a problem here'})
}
} }
} }
</script> </script>
+5 -1
View File
@@ -195,11 +195,15 @@
} }
}, },
layout: 'admin', layout: 'admin',
async asyncData({$axios, params}) { async asyncData({$axios, params, error}) {
try {
let project = await $axios.get(`/api/public/projects/${params.project}`) let project = await $axios.get(`/api/public/projects/${params.project}`)
return { return {
formData: project.data formData: project.data
} }
} catch (e) {
error({status: 404, message: 'Page not found'})
}
} }
} }
</script> </script>
+5 -1
View File
@@ -115,11 +115,15 @@
} }
}, },
layout: 'admin', layout: 'admin',
async asyncData({$axios, store}) { async asyncData({$axios, store, error}) {
try {
let projects = await $axios.get(`/api/public/projects`) let projects = await $axios.get(`/api/public/projects`)
return { return {
projects: projects.data projects: projects.data
} }
} catch (e) {
error({status: 404, message: 'There is a problem here'})
}
} }
} }
</script> </script>
+1 -2
View File
@@ -120,8 +120,7 @@
}) })
} else { } else {
this.$alert(error.response.data.message, 'خطا', { this.$alert(error.response.data.message, 'خطا', {
confirmButtonText: 'باشه', confirmButtonText: 'باشه'
}) })
} }
}) })
+7 -5
View File
@@ -104,15 +104,13 @@
}) })
} else { } else {
this.$alert(error.response.data.error.message, 'خطا', { this.$alert(error.response.data.error.message, 'خطا', {
confirmButtonText: 'باشه', confirmButtonText: 'باشه'
}) })
} }
}) })
}, },
preview(event) { preview(event) {
this.formData.image = URL.createObjectURL(event.target.files[0]); this.formData.image = URL.createObjectURL(event.target.files[0])
} }
}, },
head() { head() {
@@ -121,11 +119,15 @@
} }
}, },
layout: 'admin', layout: 'admin',
async asyncData({$axios, route}) { async asyncData({$axios, route, error}) {
try {
const slide = await $axios.get(`/api/public/slider/${route.params.slide}`) const slide = await $axios.get(`/api/public/slider/${route.params.slide}`)
return { return {
formData: slide.data formData: slide.data
} }
} catch (e) {
error({status: 404, message: 'Page not found'})
}
} }
} }
</script> </script>
+5 -1
View File
@@ -97,11 +97,15 @@
} }
}, },
layout: 'admin', layout: 'admin',
async asyncData({$axios, store}) { async asyncData({$axios, store, error}) {
try {
let slides = await $axios.get(`/api/public/slider`) let slides = await $axios.get(`/api/public/slider`)
return { return {
slides: slides.data slides: slides.data
} }
} catch (e) {
error({status: 404, message: 'There is a problem here'})
}
} }
} }
</script> </script>
+2 -4
View File
@@ -108,15 +108,13 @@
}) })
} else { } else {
this.$alert(error.response.data.error.message, 'خطا', { this.$alert(error.response.data.error.message, 'خطا', {
confirmButtonText: 'باشه', confirmButtonText: 'باشه'
}) })
} }
}) })
}, },
preview(event) { preview(event) {
this.formData.image = URL.createObjectURL(event.target.files[0]); this.formData.image = URL.createObjectURL(event.target.files[0])
} }
}, },
head() { head() {