redThread / server /src /validators /search.validator.js
3v324v23's picture
Initial commit of RedThread project
0dd2082
raw
history blame contribute delete
629 Bytes
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 };