installed device page
This commit is contained in:
@@ -171,38 +171,42 @@ module.exports.updateDevice = [
|
||||
|
||||
const creator = (exel) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
for (const row of exel) {
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
if (/^[0-9]{15}$/gm.test(row[0].toString().trim())) {
|
||||
const device = await Device.findOne({ IMEI: row[0] })
|
||||
if (device) {
|
||||
console.info("Repeated IMEI ", row[0])
|
||||
|
||||
device.model = row[1]
|
||||
device.tomanPrice = row[2]
|
||||
device.dollarProfit = row[3] || 1
|
||||
device.profit = row[4] || 1
|
||||
device.score = row[5] || 1
|
||||
device.renewalProfit = row[6] || 1
|
||||
device.save()
|
||||
try {
|
||||
for (const row of exel) {
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
if (/^[0-9]{15}$/gm.test(row[0].toString().trim())) {
|
||||
const device = await Device.findOne({ IMEI: row[0].trim() })
|
||||
if (device) {
|
||||
console.info("Repeated IMEI ", row[0])
|
||||
|
||||
device.model = row[1]
|
||||
device.tomanPrice = row[2]
|
||||
device.dollarProfit = row[3] || 1
|
||||
device.profit = row[4] || 1
|
||||
device.score = row[5] || 1
|
||||
device.renewalProfit = row[6] || 1
|
||||
device.save()
|
||||
} else {
|
||||
await Device.create(
|
||||
{
|
||||
IMEI: row[0].trim(),
|
||||
model: row[1],
|
||||
tomanPrice: row[2],
|
||||
dollarProfit: row[3] || 1,
|
||||
profit: row[4] || 1,
|
||||
score: row[5] || 1,
|
||||
renewalProfit: row[6] || 1
|
||||
}
|
||||
)
|
||||
}
|
||||
} else {
|
||||
await Device.create(
|
||||
{
|
||||
IMEI: row[0],
|
||||
model: row[1],
|
||||
tomanPrice: row[2],
|
||||
dollarProfit: row[3] || 1,
|
||||
profit: row[4] || 1,
|
||||
score: row[5] || 1,
|
||||
renewalProfit: row[6] || 1
|
||||
}
|
||||
)
|
||||
console.warn("Wrong IMEI ", row[0])
|
||||
}
|
||||
} else {
|
||||
console.warn("Wrong IMEI ", row[0])
|
||||
}
|
||||
resolve("end")
|
||||
} catch (error) {
|
||||
reject(error.message)
|
||||
}
|
||||
resolve("end")
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ const User = require('../models/User');
|
||||
const InstalledDevice = require('../models/GPS.InstalledDevice');
|
||||
const Device = require('../models/GPS.Device');
|
||||
const Score = require('../models/GPS.Score');
|
||||
const { _sr } = require('../plugins/serverResponses');
|
||||
|
||||
module.exports.deviceRegistration = [
|
||||
[
|
||||
@@ -72,32 +73,28 @@ module.exports.getAllForUser = async (req, res) => {
|
||||
}
|
||||
|
||||
module.exports.getAllForAdmin = async (req, res) => {
|
||||
let page;
|
||||
let rows;
|
||||
if (!req.query?.rows || req.query?.rows <= 5) {
|
||||
rows = 10
|
||||
} else {
|
||||
rows = parseInt(req.query.rows)
|
||||
}
|
||||
// let page;
|
||||
// let rows;
|
||||
// if (!req.query?.rows || req.query?.rows <= 5) {
|
||||
// rows = 10
|
||||
// } else {
|
||||
// rows = parseInt(req.query.rows)
|
||||
// }
|
||||
|
||||
if (!req.query?.page) {
|
||||
page = 0
|
||||
// eslint-disable-next-line eqeqeq
|
||||
} else if (req.query.page <= 1) {
|
||||
page = 0
|
||||
} else {
|
||||
page = req.query.page
|
||||
page = page * rows - rows
|
||||
}
|
||||
const search = req.query?.search ? req.query.search : ""
|
||||
// if (!req.query?.page) {
|
||||
// page = 0
|
||||
// // eslint-disable-next-line eqeqeq
|
||||
// } else if (req.query.page <= 1) {
|
||||
// page = 0
|
||||
// } else {
|
||||
// page = req.query.page
|
||||
// page = page * rows - rows
|
||||
// }
|
||||
// const search = req.query?.search ? req.query.search : ""
|
||||
|
||||
const data = await InstalledDevice.find({
|
||||
$or: [
|
||||
{ IMEI: { $regex: search } },
|
||||
]
|
||||
}).sort({ status: 1 }).skip(page).limit(rows)
|
||||
const data = await InstalledDevice.find({}).sort({ status: 1 })
|
||||
.populate('deviceId')
|
||||
.populate('userId', 'shopName shopNumber shopAddress birthDate score first_name last_name profilePic')
|
||||
.populate('userId', 'shopName national_code first_name last_name mobile_number city_name province_name')
|
||||
const total = Math.ceil((await InstalledDevice.estimatedDocumentCount()))
|
||||
res.status(200).json({ data, total })
|
||||
}
|
||||
@@ -139,8 +136,8 @@ module.exports.updateInstalled = [
|
||||
user.save()
|
||||
device.save()
|
||||
installedDevice.save()
|
||||
// res.status(201).json({ msg: _sr.fa.response.success_save, data: installedDevice })
|
||||
res.status(200).json(installedDevice)
|
||||
res.status(201).json({ msg: _sr.fa.response.success_save, data: installedDevice })
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -149,8 +146,8 @@ module.exports.updateInstalled = [
|
||||
installedDevice.save()
|
||||
device.status = 0;
|
||||
device.save()
|
||||
// res.status(201).json({ msg: _sr.fa.response.success_save, data: installedDevice })
|
||||
res.status(200).json(installedDevice)
|
||||
res.status(201).json({ msg: _sr.fa.response.success_save, data: installedDevice })
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ const { fullName, national, phoneNumber, email, receptionCode, caption } = req.
|
||||
|
||||
module.exports.getsComplaint = [
|
||||
async(req, res)=>{
|
||||
const complaints = await Complaint.find({type:0}).populate('user', 'first_name last_name personalCode')
|
||||
const complaints = await Complaint.find({type:0}).populate('user', 'first_name last_name personalCode').sort({created_at:-1, read:-1})
|
||||
|
||||
res.status(200).json(complaints)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user