feat: test case filtering (#276)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const { DataTypes } = require('sequelize');
|
||||
const { DataTypes, Op } = require('sequelize');
|
||||
const defineCase = require('../../models/cases');
|
||||
|
||||
module.exports = function (sequelize) {
|
||||
@@ -9,17 +9,39 @@ module.exports = function (sequelize) {
|
||||
const { verifyProjectVisibleFromFolderId } = require('../../middleware/verifyVisible')(sequelize);
|
||||
|
||||
router.get('/', verifySignedIn, verifyProjectVisibleFromFolderId, async (req, res) => {
|
||||
const { folderId } = req.query;
|
||||
const { folderId, priority, type } = req.query;
|
||||
|
||||
if (!folderId) {
|
||||
return res.status(400).json({ error: 'folderId is required' });
|
||||
}
|
||||
|
||||
try {
|
||||
const whereClause = {
|
||||
folderId: folderId,
|
||||
};
|
||||
|
||||
if (priority) {
|
||||
const priorityValues = priority
|
||||
.split(',')
|
||||
.map((p) => parseInt(p.trim(), 10))
|
||||
.filter((p) => !isNaN(p));
|
||||
if (priorityValues.length > 0) {
|
||||
whereClause.priority = { [Op.in]: priorityValues };
|
||||
}
|
||||
}
|
||||
|
||||
if (type) {
|
||||
const typeValues = type
|
||||
.split(',')
|
||||
.map((t) => parseInt(t.trim(), 10))
|
||||
.filter((t) => !isNaN(t));
|
||||
if (typeValues.length > 0) {
|
||||
whereClause.type = { [Op.in]: typeValues };
|
||||
}
|
||||
}
|
||||
|
||||
const cases = await Case.findAll({
|
||||
where: {
|
||||
folderId: folderId,
|
||||
},
|
||||
where: whereClause,
|
||||
});
|
||||
res.json(cases);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user