This commit is contained in:
@@ -127,6 +127,8 @@ exports.getAllSentences = async (req, res) => {
|
||||
topic,
|
||||
text,
|
||||
search,
|
||||
status,
|
||||
sort,
|
||||
is_active = true
|
||||
} = req.query;
|
||||
|
||||
@@ -137,6 +139,11 @@ exports.getAllSentences = async (req, res) => {
|
||||
where.is_active = is_active === 'true' || is_active === true;
|
||||
}
|
||||
|
||||
// Status filter (0 = chưa duyệt, 1 = đã duyệt, undefined = all)
|
||||
if (status !== undefined && status !== '' && status !== 'all') {
|
||||
where.status = parseInt(status);
|
||||
}
|
||||
|
||||
if (category) {
|
||||
where.category = category;
|
||||
}
|
||||
@@ -156,11 +163,19 @@ exports.getAllSentences = async (req, res) => {
|
||||
];
|
||||
}
|
||||
|
||||
// Sort order
|
||||
let order = [['created_at', 'DESC']]; // default
|
||||
if (sort === 'updated_at') {
|
||||
order = [['updated_at', 'DESC']];
|
||||
} else if (sort === 'alphabet') {
|
||||
order = [['text', 'ASC']];
|
||||
}
|
||||
|
||||
const { count, rows } = await Sentences.findAndCountAll({
|
||||
where,
|
||||
limit: parseInt(limit),
|
||||
offset: parseInt(offset),
|
||||
order: [['created_at', 'DESC']]
|
||||
order
|
||||
});
|
||||
|
||||
res.json({
|
||||
|
||||
Reference in New Issue
Block a user