Add brands

This commit is contained in:
Swift
2024-02-09 20:52:09 +03:30
parent f724a4259f
commit 0bb459ea25
5 changed files with 146 additions and 90 deletions
+4 -3
View File
@@ -2,6 +2,7 @@ const Brand = require("../models/Brand");
const { checkValidations } = require("../plugins/controllersHelperFunctions")
const { body, validationResult } = require('express-validator')
const { _sr } = require("../plugins/serverResponses")
const maxAttachmentSize = 2048
//@desc Create a brand
@@ -93,8 +94,8 @@ const updatebrand = [
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]))
@@ -103,7 +104,7 @@ const updatebrand = [
return res
.status(422)
.json({ validation: { image: { msg: `حجم تصویر نباید بیشتر از ${maxAttachmentSize} KB باشد.` } } })
data.image = fileName
data.logo = fileName
await image.mv(`./static/uploads/images/brands/${fileName}`)
}