Add custom serials

This commit is contained in:
Swift
2024-02-09 22:04:14 +03:30
parent ddb290241d
commit 7438a95166
9 changed files with 48 additions and 22 deletions
+12 -8
View File
@@ -27,9 +27,9 @@ module.exports.addExel = [
if (!req.files?.file.name.split('.').some(item => ['xlsx', 'xltx', 'xlsm', 'xlsb'].includes(item)))
return res.status(422).json({ validation: { file: { msg: 'فرمت فایل درست نمیباشد' } } })
const file = req.files.file
const { type } = req.body
const { type, g } = req.body
try {
const path = type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath
const path = (type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath) + `/${g}`
const files = await fs.readdirSync(path)
for await (const item of files) {
if (file.name === item) return res.status(422).json({ validation: { file: { msg: 'نام فایل تکراریست' } } })
@@ -47,12 +47,14 @@ module.exports.addExel = [
module.exports.getAllExels = [
(req, res) => {
const type = req.query?.type
if (!type) {
const g = req.query?.g
if (!type || !g) {
res500(res, 'choose type')
}
const validValues = ['guaranteeSerial', 'orginality']
if (!validValues.includes(type)) return res500(res, 'choose type')
const path = type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath
const path = (type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath) + `/${g}`
const downloadAblePath = type === 'guaranteeSerial' ? '/uploads/serials/' : '/uploads/serials_products/'
fs.readdir(path, (err, files) => {
if (err) return res500(res, err)
@@ -67,10 +69,12 @@ module.exports.getAllExels = [
module.exports.removeExel = [
(req, res) => {
const type = req.query?.type
if (!type) return res500(res, 'choose type')
const g = req.query?.g
if (!type || !g) return res500(res, 'choose type')
const validValues = ['guaranteeSerial', 'orginality']
if (!validValues.includes(type)) return res500(res, 'choose type')
const path = type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath
const path = (type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath) + `/${g}`
fs.unlink(`${path}/${req.params.name}`, err => {
if (err) return res404(res, _faSr.not_found.item_id)
else return res.json({ message: _faSr.response.success_remove })
@@ -95,8 +99,8 @@ module.exports.checkSerial = [
checkValidations(validationResult),
async (req, res) => {
try {
const { serial, type } = req.body
const serialStatus = await serialChecker(serial, type)
const { serial, type, g } = req.body
const serialStatus = await serialChecker(serial, type, g)
let okMsg
if (type === 'guaranteeSerial') okMsg = 'شماره سریال گارانتی معتبر میباشد.'