Fix serial checker bug
This commit is contained in:
@@ -3,15 +3,15 @@ const readXlsxFile = require('read-excel-file/node')
|
||||
const guaranteeSerialsPath = './static/uploads/serials'
|
||||
const productSerialsPath = './static/uploads/serials_products'
|
||||
|
||||
const serialChecker = (serial, type = 'guaranteeSerial', g = 1) => {
|
||||
const serialChecker = (serial, type = 'guaranteeSerial', g = 1) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let exelsPath;
|
||||
if (type === 'guaranteeSerial') exelsPath = guaranteeSerialsPath + `/${g}`;
|
||||
if (type === 'orginality') exelsPath = productSerialsPath + `/${g}`;
|
||||
|
||||
console.log("s");
|
||||
|
||||
const lowerSerial = serial.toString().toLowerCase().trim().replace("-","")
|
||||
|
||||
|
||||
const lowerSerial = serial.toString().toLowerCase().trim().replace("-", "")
|
||||
|
||||
try {
|
||||
const serialFiles = await fs.readdirSync(exelsPath);
|
||||
@@ -19,20 +19,20 @@ console.log("s");
|
||||
// eslint-disable-next-line prefer-promise-reject-errors
|
||||
reject("این کد در سامانه موجود نیست")
|
||||
}
|
||||
|
||||
|
||||
serialFiles.forEach(async (file, i) => {
|
||||
if(file.split('.').some(item => ['xlsx', 'xltx', 'xlsm', 'xlsb'].includes(item))){
|
||||
if (file.split('.').some(item => ['xlsx', 'xltx', 'xlsm', 'xlsb'].includes(item))) {
|
||||
const exelFile = await readXlsxFile(`${exelsPath}/${file}`);
|
||||
console.log(file);
|
||||
console.log(file);
|
||||
|
||||
for (const row of exelFile) {
|
||||
console.log(row);
|
||||
|
||||
// eslint-disable-next-line eqeqeq
|
||||
if ((row[1].toString()).toLowerCase().trim() == lowerSerial) {
|
||||
resolve(row[2]);
|
||||
return; // Serial found, exit loop
|
||||
}
|
||||
|
||||
// eslint-disable-next-line eqeqeq
|
||||
if ((row[1].toString()).toLowerCase().trim() == lowerSerial) {
|
||||
resolve(row[2]);
|
||||
return; // Serial found, exit loop
|
||||
}
|
||||
|
||||
}
|
||||
if ((serialFiles.length - 1) <= i) {
|
||||
// eslint-disable-next-line prefer-promise-reject-errors
|
||||
|
||||
Reference in New Issue
Block a user