final
This commit is contained in:
@@ -55,7 +55,7 @@ module.exports.getAllExels = [
|
|||||||
const validValues = ['guaranteeSerial', 'orginality']
|
const validValues = ['guaranteeSerial', 'orginality']
|
||||||
if (!validValues.includes(type)) return res500(res, 'choose type')
|
if (!validValues.includes(type)) return res500(res, 'choose type')
|
||||||
const path = (type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath) + `/${g}`
|
const path = (type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath) + `/${g}`
|
||||||
const downloadAblePath = type === 'guaranteeSerial' ? '/uploads/serials/' : '/uploads/serials_products/'
|
const downloadAblePath = (type === 'guaranteeSerial' ? '/uploads/serials' : '/uploads/serials_products') + `/${g}`
|
||||||
fs.readdir(path, (err, files) => {
|
fs.readdir(path, (err, files) => {
|
||||||
if (err) return res500(res, err)
|
if (err) return res500(res, err)
|
||||||
const filesWithURL = files.map(item => {
|
const filesWithURL = files.map(item => {
|
||||||
@@ -113,6 +113,7 @@ module.exports.checkSerial = [
|
|||||||
if (serialStatus) return res.json({ message: okMsg })
|
if (serialStatus) return res.json({ message: okMsg })
|
||||||
else return res404(res, errMsg)
|
else return res404(res, errMsg)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
return res500(res, `there is an error here --- ${e}`)
|
return res500(res, `there is an error here --- ${e}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const readXlsxFile = require('read-excel-file/node')
|
const readXlsxFile = require('read-excel-file/node')
|
||||||
|
|
||||||
const guaranteeSerialsPath = './static/uploads/serials/'
|
const guaranteeSerialsPath = './static/uploads/serials'
|
||||||
const productSerialsPath = './static/uploads/serials_products/'
|
const productSerialsPath = './static/uploads/serials_products'
|
||||||
|
|
||||||
const serialChecker = async (serial, type = 'guaranteeSerial', g = 1) => {
|
const serialChecker = async (serial, type = 'guaranteeSerial', g = 1) => {
|
||||||
let exelsPath
|
let exelsPath
|
||||||
if (type === 'guaranteeSerial') exelsPath = guaranteeSerialsPath + g
|
if (type === 'guaranteeSerial') exelsPath = guaranteeSerialsPath + `/${g}`
|
||||||
if (type === 'orginality') exelsPath = productSerialsPath + g
|
if (type === 'orginality') exelsPath = productSerialsPath + `/${g}`
|
||||||
|
|
||||||
const lowerSerial = serial.toLowerCase()
|
const lowerSerial = serial.toLowerCase()
|
||||||
// a promise to lowercase items and filter null or DateObjects
|
// a promise to lowercase items and filter null or DateObjects
|
||||||
@@ -31,6 +31,8 @@ const serialChecker = async (serial, type = 'guaranteeSerial', g = 1) => {
|
|||||||
// push each exel file data to exelFilesData array
|
// push each exel file data to exelFilesData array
|
||||||
let n0 = 0
|
let n0 = 0
|
||||||
for await (const file of serialFiles) {
|
for await (const file of serialFiles) {
|
||||||
|
|
||||||
|
|
||||||
// reading all exel files one by one
|
// reading all exel files one by one
|
||||||
const exelFile = await readXlsxFile(`${exelsPath}/${file}`)
|
const exelFile = await readXlsxFile(`${exelsPath}/${file}`)
|
||||||
exelFilesData.push(exelFile)
|
exelFilesData.push(exelFile)
|
||||||
@@ -48,9 +50,12 @@ const serialChecker = async (serial, type = 'guaranteeSerial', g = 1) => {
|
|||||||
n1++
|
n1++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
n0++
|
n0++
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
throw new Error(e)
|
throw new Error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user