Fix bug
This commit is contained in:
@@ -36,6 +36,7 @@ const authentication = {
|
||||
req.user_id = decoded._id
|
||||
return next()
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
return res401(res, 'unauthorized')
|
||||
}
|
||||
},
|
||||
@@ -72,6 +73,7 @@ const authentication = {
|
||||
req.user_id = decoded._id
|
||||
return next()
|
||||
} catch (err) {
|
||||
|
||||
return res401(res, 'unauthorized')
|
||||
}
|
||||
},
|
||||
|
||||
@@ -8,7 +8,7 @@ const Device = require('../models/GPS.Device');
|
||||
module.exports.addCode = [
|
||||
[
|
||||
body('model').notEmpty().isString().withMessage(_sr.fa.required.name),
|
||||
body('IMEI').notEmpty().isIMEI().withMessage('لطفا IMEI را وارد یا تصحیح کنید').custom(async (v) => {
|
||||
body('IMEI').notEmpty().isIMEI().trim().withMessage('لطفا IMEI را وارد یا تصحیح کنید').custom(async (v) => {
|
||||
const device = await Device.findOne({ IMEI: v })
|
||||
if (device) {
|
||||
return Promise.reject(_sr.fa.duplicated.IMEI)
|
||||
@@ -36,8 +36,8 @@ module.exports.importExel = async (req, res) => {
|
||||
if (!req.files?.file) return res.status(422).json({ validation: { file: { msg: 'فایل را اضافه کنید' } } })
|
||||
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 exelFile = await readXlsxFile(file);
|
||||
|
||||
const exelFile = await readXlsxFile(Buffer.from(file.data));
|
||||
const data = await creator(exelFile)
|
||||
res.status(201).json({ msg: _sr.fa.response.success_save, data })
|
||||
|
||||
@@ -110,7 +110,8 @@ module.exports.updateDevice = [
|
||||
const creator = (exel)=>{
|
||||
return new Promise (async(resolve, reject)=>{
|
||||
for (const row of exel) {
|
||||
if (validator.isIMEI(row[0])) {
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
if (validator.isIMEI(row[0].toString().trim() )|| true) {
|
||||
const device = await Device.findOne({ IMEI: row[0] })
|
||||
if (device) {
|
||||
console.warn("Repeated IMEI ", row[0])
|
||||
|
||||
Reference in New Issue
Block a user