Skip to content

Commit 064c2f8

Browse files
committed
1 parent df041a5 commit 064c2f8

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/Controller/RecordController.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,16 @@ async function getRecordsByPage(req, res) {
149149
'reason'
150150
]
151151

152-
const { exact = {}, history, ..._where } = where || {};
152+
const tagFields = [
153+
'name',
154+
'color'
155+
]
156+
157+
const { history, tag, ..._where } = where || {};
153158

154159
let filters = {};
155160
const historyFilters = [];
161+
const tagFilters = [];
156162

157163
Object.entries(_where).forEach(([key, value]) => {
158164
filters[key] = {
@@ -168,11 +174,18 @@ async function getRecordsByPage(req, res) {
168174
});
169175
}
170176

171-
filters = { ...exact, ...filters };
177+
if(tag) {
178+
tagFields.forEach((item) => {
179+
tagFilters.push({[item]: {
180+
[Op.iLike]: "%" + tag + "%"
181+
}})
182+
});
183+
}
172184

173185
const { rows, count } = await Record.findAndCountAll({
174186
include: [{ model: History, as: 'histories', ...(history && { where: { [Op.or]: historyFilters }})},
175-
{ model: Department, as: 'departments', ...(department_id && { where: { id: department_id}})}],
187+
{ model: Tag, as: 'tags', ...(tag && { where: { [Op.or]: tagFilters }})},
188+
{ model: Department, as: 'departments', ...(department_id && { where: { id: department_id}})}],
176189
where: filters,
177190
limit: itemsPerPage,
178191
order: [['register_number', 'ASC']],

0 commit comments

Comments
 (0)