improvcement in device registration
This commit is contained in:
@@ -16,10 +16,13 @@ module.exports.deviceRegistration = [
|
||||
const IMEI = req.body.IMEI
|
||||
console.log('IMEI ******************', IMEI)
|
||||
|
||||
const existingInstalledDevice = await InstalledDevice.findOne({ IMEI, status: 1 }).catch(err => {
|
||||
let existingInstalledDevice
|
||||
try{
|
||||
existingInstalledDevice = await InstalledDevice.findOne({ IMEI, status: 1 })
|
||||
}catch(err){
|
||||
console.log('err in findOne InstalledDevice', err?.message)
|
||||
return res.status(500).json({ msg: 'خطا در دریافت اطلاعات از دیتابیس ثبت دستگاه' })
|
||||
})
|
||||
}
|
||||
if (existingInstalledDevice) {
|
||||
return res.status(400).json({ msg: 'این IMEI قبلا ثبت شده ' })
|
||||
}
|
||||
@@ -40,13 +43,15 @@ module.exports.deviceRegistration = [
|
||||
let scoreData = null
|
||||
let walletUpdated = false
|
||||
try {
|
||||
const fee = await Settings.findOne({ title: 'install_fee' })
|
||||
if (!fee) {
|
||||
return res.status(400).json({ msg: 'هزینه نصب یافت نشد' })
|
||||
}
|
||||
const score = await Settings.findOne({ title: 'install_score' })
|
||||
if (!score) {
|
||||
return res.status(400).json({ msg: 'امتیاز نصب یافت نشد' })
|
||||
const settings = await Settings.find({
|
||||
title: { $in: ['install_fee', 'install_score'] }
|
||||
});
|
||||
|
||||
const fee = settings.find(s => s.title === 'install_fee');
|
||||
const score = settings.find(s => s.title === 'install_score');
|
||||
|
||||
if (!fee || !score) {
|
||||
return res.status(400).json({ msg: 'هزینه نصب یا امتیاز نصب یافت نشد' })
|
||||
}
|
||||
const data = {
|
||||
// deviceId: RegisteredDevice.deviceId,
|
||||
|
||||
Reference in New Issue
Block a user