diff --git a/pages/admin/brands/_item.vue b/pages/admin/brands/_item.vue
index 97acd0f..55c5acc 100644
--- a/pages/admin/brands/_item.vue
+++ b/pages/admin/brands/_item.vue
@@ -3,13 +3,59 @@
برند ها
برگشت به صفحه قبل
- افزودن
بروزرسانی
+
+
+
+
+
+
+
+
+
+
+
+
+
+ کاور
+
+
+
+
+
+
+
+ {{ validation.logo.msg }}
+
+
+
+
+
@@ -33,7 +79,10 @@
data() {
return {
brand: {
-
+ title:'',
+ link:'',
+ description:'',
+ logo:''
},
validation: {},
@@ -45,8 +94,40 @@
}
},
methods: {
-
+ imagePreview(event) {
+ this.brand.logo = URL.createObjectURL(event.target.files[0])
+ },
+ post(){
+ this.validation = {}
+ const data = new FormData()
+ data.append('title', this.brand.title)
+ data.append('link', this.brand.link)
+ data.append('description', this.brand.description)
+ data.append('logo', this.$refs.myFiles.files[0])
+ this.$axios
+ .post('/api/admin/brand', data, this.axiosConfig)
+ .then(res => {
+ this.$message({
+ type: 'success',
+ message: 'پیام با موفقیت برای کاربران ارسال شد'
+ })
+ this.$router.push({ name: 'admin-announcements', query: { ...this.$route.query } })
+ })
+ .catch(err => {
+ if (err.response.status === 422) {
+ this.$message({
+ type: 'warning',
+ message: 'پارامتر ها رو بررسی کنید'
+ })
+ this.validation = err.response.data.validation
+ }
+ if (err.response.status === 401)
+ this.$message({
+ type: 'error',
+ message: 'دوباره وارد سیستم شوید'
+ })
+ })
+ }
}
}
-
\ No newline at end of file
diff --git a/server/controllers/brandController.js b/server/controllers/brandController.js
index 2b650c9..7af329e 100644
--- a/server/controllers/brandController.js
+++ b/server/controllers/brandController.js
@@ -21,18 +21,20 @@ const createbrand = [
title, link, description,
}
- if (req.files?.image) {
- const image = req.files.image
+ if (req.files?.logo) {
+ const image = req.files.logo
const fileName = 'brands' + Date.now() + '.' + image.name
const acceptableFormats = ['png', 'jpg', 'jpeg', 'webp']
if (!acceptableFormats.includes(image.mimetype.split('/')[1]))
- return res.status(422).json({ validation: { image: { msg: _faSr.format.image } } })
+ return res.status(422).json({ validation: { logo: { msg: _faSr.format.image } } })
if (image.size / 1024 > maxAttachmentSize)
return res
.status(422)
- .json({ validation: { image: { msg: `حجم تصویر نباید بیشتر از ${maxAttachmentSize} KB باشد.` } } })
- data.image = fileName
+ .json({ validation: { logo: { msg: `حجم تصویر نباید بیشتر از ${maxAttachmentSize} KB باشد.` } } })
+ data.logo = fileName
await image.mv(`./static/uploads/images/brands/${fileName}`)
+ }else{
+ res.status(422).json({ validation: { logo: { msg: `تصویر را ارسال کنید` } } })
}