Spaces:
Running
Running
File size: 629 Bytes
0dd2082 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | const AppError = require('../utils/AppError');
function validateSearchBody(req, res, next) {
const { query } = req.body;
if (!query || typeof query !== 'string') {
return next(new AppError('Field "query" is required and must be a string.', 400));
}
const trimmed = query.trim();
if (trimmed.length < 3) {
return next(new AppError('Query must be at least 3 characters.', 400));
}
if (trimmed.length > 500) {
return next(new AppError('Query must not exceed 500 characters.', 400));
}
req.body.query = trimmed;
next();
}
module.exports = { validateSearchBody };
|