This commit is contained in:
morteza-mortezai
2025-12-02 09:42:09 +03:30
parent 0d902aff1a
commit 5b9d14ee44
+6 -2
View File
@@ -216,11 +216,12 @@ module.exports.updateInstalled = [
], ],
checkValidations(validationResult), checkValidations(validationResult),
async (req, res) => { async (req, res) => {
try {
console.log('updateInstalled ******************', req.params.id, req.params.type) console.log('updateInstalled ******************', req.params.id, req.params.type)
const installedDevice = await InstalledDevice.findById(req.params.id) const installedDevice = await InstalledDevice.findById(req.params.id)
if (!installedDevice) { if (!installedDevice) {
return res.status(404).json({ msg: 'این ایدی وجود ندارد' }) return res.status(404).json({ msg: 'این ایدی وجود ندارد' })
} else { }
console.log('installedDevice ******************') console.log('installedDevice ******************')
// const user = await User.findById(installedDevice.userId).select('walletBalance score totalScore') // const user = await User.findById(installedDevice.userId).select('walletBalance score totalScore')
switch (req.params.type) { switch (req.params.type) {
@@ -271,7 +272,7 @@ module.exports.updateInstalled = [
console.log('userGPS updated ******************') console.log('userGPS updated ******************')
} }
await Score.delete({ deviceId: installedDevice.id }) await Score.deleteMany({ deviceId: installedDevice.id })
console.log('Score deleted ******************') console.log('Score deleted ******************')
notifyAdmin('newInstallDeviceRequest', installedDevice.userId) notifyAdmin('newInstallDeviceRequest', installedDevice.userId)
@@ -284,6 +285,9 @@ module.exports.updateInstalled = [
break break
} }
} }
} catch (error) {
console.error('Error in updateInstalled:', error?.message)
return res.status(500).json({ msg: 'خطا در به‌روزرسانی وضعیت دستگاه' })
} }
} }
] ]