feat: search test case (#277)

This commit is contained in:
Eliezer Castro
2025-08-30 11:26:46 -03:00
committed by GitHub
parent afe569a79c
commit f76a3cdaf5
12 changed files with 266 additions and 102 deletions

View File

@@ -9,7 +9,7 @@ module.exports = function (sequelize) {
const { verifyProjectVisibleFromFolderId } = require('../../middleware/verifyVisible')(sequelize);
router.get('/', verifySignedIn, verifyProjectVisibleFromFolderId, async (req, res) => {
const { folderId, priority, type } = req.query;
const { folderId, priority, type, q } = req.query;
if (!folderId) {
return res.status(400).json({ error: 'folderId is required' });
@@ -20,6 +20,18 @@ module.exports = function (sequelize) {
folderId: folderId,
};
if (q) {
const searchTerm = q.trim();
if (searchTerm.length > 100) {
return res.status(400).json({ error: 'Search term too long' });
}
if (searchTerm.length >= 2) {
whereClause[Op.or] = [{ title: { [Op.like]: `%${q}%` } }];
}
}
if (priority) {
const priorityValues = priority
.split(',')