installed device page

This commit is contained in:
Mr Swift
2024-08-25 16:16:45 +03:30
parent d91bc5beba
commit b0566dd807
7 changed files with 527 additions and 59 deletions
+32 -28
View File
@@ -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")
})
}