add
This commit is contained in:
@@ -12,13 +12,26 @@ const createbrand = [
|
||||
body('title').notEmpty().withMessage(_sr.fa.required.title),
|
||||
body('description').notEmpty().withMessage(_sr.fa.required.description),
|
||||
body('link').notEmpty().trim().isLowercase().withMessage(_sr.fa.required.field),
|
||||
body('logo').notEmpty().withMessage(_sr.fa.required.image),
|
||||
|
||||
],
|
||||
checkValidations(validationResult),
|
||||
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 });
|
||||
|
||||
Reference in New Issue
Block a user