Skip to content

Commit

Permalink
Merge pull request #83 from ELEVATE-Project/sonar-fix
Browse files Browse the repository at this point in the history
updated validator to check path existence
  • Loading branch information
rakeshSgr authored Dec 14, 2022
2 parents 899d16d + a3603ef commit 276e0ac
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/middlewares/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,29 @@ const fs = require('fs')

module.exports = (req, res, next) => {
try {
require(`@validators/${req.params.version}/${req.params.controller}`)[req.params.method](req)
//Checks path existence
let reqPath =
fs.existsSync(
PROJECT_ROOT_DIRECTORY +
'/controllers/' +
req.params.version +
'/' +
req.params.controller +
'/' +
req.params.file +
'.js'
) ||
fs.existsSync(
PROJECT_ROOT_DIRECTORY + '/controllers/' + req.params.version + '/' + req.params.controller + '.js'
)
if (reqPath) {
require(`@validators/${req.params.version}/${req.params.controller}`)[req.params.method](req)
} else {
const error = new Error('Requested resource not found!!!')
error.status = 404
error.responseCode = 'RESOURCE_ERROR'
next(error)
}
} catch (error) {}
next()
}

0 comments on commit 276e0ac

Please sign in to comment.