Debug: change auth and fix a few small mistakes

This commit is contained in:
Mr Swift
2024-10-27 17:21:04 +03:30
parent 03f9c164db
commit a83e84a441
3 changed files with 10 additions and 15 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ module.exports.deviceRegistration = [
if (!device) {
throw res.status(404).json({ msg: 'این IMEI وجود ندارد' })
// eslint-disable-next-line eqeqeq
} else if (device.status == 1) {
} else if (device.status == 1 || device.status == 0) {
throw res.status(404).json({ msg: 'این IMEI قبلا ثبت شده' })
} else {
+7 -12
View File
@@ -6,8 +6,6 @@ const User = require('../models/GPS.User');
const Score = require('../models/GPS.Score');
const InstalledDevice = require('../models/GPS.InstalledDevice');
const token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzBmY2NhNmFmOWE3ODMzNDgxZWIzODkiLCJpYXQiOjE3MzAwMjk4ODUsImV4cCI6MTczMDYzNDY4NX0.2qGgmlcllXr240rJ56ID9P01Kib-74enlEUY4Ifi-f2"
module.exports.create = [
[
@@ -21,12 +19,11 @@ module.exports.create = [
async (req, res) => {
try {
// eslint-disable-next-line eqeqeq
if(token == req.headers["apic-token-secret"]){
const { IMEI, renewDate, renewType, price } = req.body
const device = await InstalledDevice.findOne({IMEI}).populate('deviceId')
if(!device){
req.status(200)
throw new Error(_sr.fa.response.success_save)
res.status(200)
throw new Error(_sr.fa.response.success_save+1)
}
// eslint-disable-next-line eqeqeq
if(device.status == 1 ){
@@ -51,17 +48,15 @@ module.exports.create = [
user.walletBalance += data.profit
user.score += device.deviceId.score
user.save()
res.status(201).json({msg:_sr.fa.response.success_save})
}else{
req.status(200)
throw new Error(_sr.fa.response.success_save)
res.status(200)
throw new Error(_sr.fa.response.success_save+2)
}
}else{
req.status(401)
throw new Error('unauthenticated')
}
} catch (error) {
req.json({msg:error.message})
res.json({msg:error.message})
}
}