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