@@ -149,10 +149,16 @@ async function getRecordsByPage(req, res) {
149
149
'reason'
150
150
]
151
151
152
- const { exact = { } , history, ..._where } = where || { } ;
152
+ const tagFields = [
153
+ 'name' ,
154
+ 'color'
155
+ ]
156
+
157
+ const { history, tag, ..._where } = where || { } ;
153
158
154
159
let filters = { } ;
155
160
const historyFilters = [ ] ;
161
+ const tagFilters = [ ] ;
156
162
157
163
Object . entries ( _where ) . forEach ( ( [ key , value ] ) => {
158
164
filters [ key ] = {
@@ -168,11 +174,18 @@ async function getRecordsByPage(req, res) {
168
174
} ) ;
169
175
}
170
176
171
- filters = { ...exact , ...filters } ;
177
+ if ( tag ) {
178
+ tagFields . forEach ( ( item ) => {
179
+ tagFilters . push ( { [ item ] : {
180
+ [ Op . iLike ] : "%" + tag + "%"
181
+ } } )
182
+ } ) ;
183
+ }
172
184
173
185
const { rows, count } = await Record . findAndCountAll ( {
174
186
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 } } ) } ] ,
176
189
where : filters ,
177
190
limit : itemsPerPage ,
178
191
order : [ [ 'register_number' , 'ASC' ] ] ,
0 commit comments