add
This commit is contained in:
+1
-2
@@ -1,5 +1,4 @@
|
|||||||
|
*.xlsx
|
||||||
/static/uploads/
|
|
||||||
# Created by .ignore support plugin (hsz.mobi)
|
# Created by .ignore support plugin (hsz.mobi)
|
||||||
### Node template
|
### Node template
|
||||||
# Logs
|
# Logs
|
||||||
|
|||||||
@@ -12,13 +12,26 @@ const createbrand = [
|
|||||||
body('title').notEmpty().withMessage(_sr.fa.required.title),
|
body('title').notEmpty().withMessage(_sr.fa.required.title),
|
||||||
body('description').notEmpty().withMessage(_sr.fa.required.description),
|
body('description').notEmpty().withMessage(_sr.fa.required.description),
|
||||||
body('link').notEmpty().trim().isLowercase().withMessage(_sr.fa.required.field),
|
body('link').notEmpty().trim().isLowercase().withMessage(_sr.fa.required.field),
|
||||||
body('logo').notEmpty().withMessage(_sr.fa.required.image),
|
|
||||||
|
|
||||||
],
|
],
|
||||||
checkValidations(validationResult),
|
checkValidations(validationResult),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
|
|
||||||
const { title, link, description, logo } = req.body;
|
if (req.files?.image) {
|
||||||
|
const image = req.files.image
|
||||||
|
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 } } })
|
||||||
|
if (image.size / 1024 > maxAttachmentSize)
|
||||||
|
return res
|
||||||
|
.status(422)
|
||||||
|
.json({ validation: { image: { msg: `حجم تصویر نباید بیشتر از ${maxAttachmentSize} KB باشد.` } } })
|
||||||
|
data.image = fileName
|
||||||
|
await image.mv(`./static/uploads/images/brands/${fileName}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const { title, link, description } = req.body;
|
||||||
|
|
||||||
|
|
||||||
const linkAvailable = await Brand.findOne({ link });
|
const linkAvailable = await Brand.findOne({ link });
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
#
|
||||||
Reference in New Issue
Block a user