Filter post by a tag

This commit is contained in:
Rykkel
2024-08-12 17:46:04 +08:00
parent 2fe13fd724
commit fd0bd85219
2 changed files with 66 additions and 2 deletions

View File

@@ -114,12 +114,19 @@ router.get("/", async (req, res) => {
};
let search = req.query.search;
let tag = req.query.tag;
if (search) {
condition.where[Op.or] = [
{ title: { [Op.like]: `%${search}%` } },
{ content: { [Op.like]: `%${search}%` } },
];
}
if (tag) {
condition.include[0].where = { tag: tag };
}
// You can add condition for other columns here
// e.g. condition.columnName = value;