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:
richardtekula
2025-12-05 11:03:32 +01:00
parent 03b7a215bb
commit 6f4a31e9de
19 changed files with 186 additions and 191 deletions

View File

@@ -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();

View 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();
};