Fix model & request for gps controller

This commit is contained in:
Mr Swift
2024-08-05 17:00:48 +03:30
parent f708d708d1
commit 1c6a44d718
10 changed files with 339 additions and 175 deletions
+18
View File
@@ -39,6 +39,24 @@ const authentication = {
return res401(res, 'unauthorized')
}
},
// check if admin logged in (middleware)
async isGPS(req, res, next) {
try {
const token = req.headers?.authorization
if (!token) throw new Error('err')
const decoded = jwt.verify(token.replace(/^Bearer\s/, ''), authentication.secretKey)
if (!decoded) throw new Error('err')
const user = await User.findById(decoded._id)
if (!user || !user.scope.includes('gps')) throw new Error('err')
req.user_id = decoded._id
return next()
} catch (err) {
return res401(res, 'unauthorized')
}
},
// check if user logged in (middleware)
async isUser(req, res, next) {
try {