Code quality improvements from code review
- Add admin-only authorization for company and projects CRUD operations - Create requireAccountId middleware to eliminate code duplication - Standardize error handling (use next(error) consistently) - Change error messages to Slovak language 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,7 @@ export function validateBody(req, res, next) {
|
||||
for (const pattern of dangerousPatterns) {
|
||||
if (pattern.test(data)) {
|
||||
logger.warn('Suspicious input detected', { data: data.substring(0, 100) });
|
||||
return res.status(400).json({ message: 'Malicious content detected in request data' });
|
||||
return res.status(400).json({ message: 'Detegovaný škodlivý obsah v požiadavke' });
|
||||
}
|
||||
}
|
||||
next();
|
||||
|
||||
20
src/middlewares/security/requireAccountId.js
Normal file
20
src/middlewares/security/requireAccountId.js
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Middleware na validáciu accountId parametra
|
||||
* Kontroluje query alebo body a nastaví req.accountId
|
||||
*/
|
||||
export const requireAccountId = (req, res, next) => {
|
||||
const accountId = req.query.accountId || req.body.accountId;
|
||||
|
||||
if (!accountId) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
error: {
|
||||
message: 'accountId je povinný parameter',
|
||||
statusCode: 400,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
req.accountId = accountId;
|
||||
next();
|
||||
};
|
||||
Reference in New Issue
Block a user