Add custom serials
This commit is contained in:
@@ -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 = 'شماره سریال گارانتی معتبر میباشد.'
|
||||
|
||||
@@ -4,10 +4,10 @@ const readXlsxFile = require('read-excel-file/node')
|
||||
const guaranteeSerialsPath = './static/uploads/serials'
|
||||
const productSerialsPath = './static/uploads/serials_products'
|
||||
|
||||
const serialChecker = async (serial, type = 'guaranteeSerial') => {
|
||||
const serialChecker = async (serial, type = 'guaranteeSerial', g = 1) => {
|
||||
let exelsPath
|
||||
if (type === 'guaranteeSerial') exelsPath = guaranteeSerialsPath
|
||||
if (type === 'orginality') exelsPath = productSerialsPath
|
||||
if (type === 'guaranteeSerial') exelsPath = guaranteeSerialsPath + g
|
||||
if (type === 'orginality') exelsPath = productSerialsPath + g
|
||||
|
||||
const lowerSerial = serial.toLowerCase()
|
||||
// a promise to lowercase items and filter null or DateObjects
|
||||
|
||||
Reference in New Issue
Block a user