improvcement in device registration

This commit is contained in:
morteza-mortezai
2025-12-14 14:41:15 +03:30
parent beda704e8d
commit b3f0ec905d
+14 -9
View File
@@ -16,10 +16,13 @@ module.exports.deviceRegistration = [
const IMEI = req.body.IMEI const IMEI = req.body.IMEI
console.log('IMEI ******************', 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) console.log('err in findOne InstalledDevice', err?.message)
return res.status(500).json({ msg: 'خطا در دریافت اطلاعات از دیتابیس ثبت دستگاه' }) return res.status(500).json({ msg: 'خطا در دریافت اطلاعات از دیتابیس ثبت دستگاه' })
}) }
if (existingInstalledDevice) { if (existingInstalledDevice) {
return res.status(400).json({ msg: 'این IMEI قبلا ثبت شده ' }) return res.status(400).json({ msg: 'این IMEI قبلا ثبت شده ' })
} }
@@ -40,13 +43,15 @@ module.exports.deviceRegistration = [
let scoreData = null let scoreData = null
let walletUpdated = false let walletUpdated = false
try { try {
const fee = await Settings.findOne({ title: 'install_fee' }) const settings = await Settings.find({
if (!fee) { title: { $in: ['install_fee', 'install_score'] }
return res.status(400).json({ msg: 'هزینه نصب یافت نشد' }) });
}
const score = await Settings.findOne({ title: 'install_score' }) const fee = settings.find(s => s.title === 'install_fee');
if (!score) { const score = settings.find(s => s.title === 'install_score');
return res.status(400).json({ msg: 'امتیاز نصب یافت نشد' })
if (!fee || !score) {
return res.status(400).json({ msg: 'هزینه نصب یا امتیاز نصب یافت نشد' })
} }
const data = { const data = {
// deviceId: RegisteredDevice.deviceId, // deviceId: RegisteredDevice.deviceId,