@@ -43,11 +43,7 @@ export class InquiryAdvancedSearchService {
43
43
fileNumbers = new Set < string > ( cachedNumbers ) ;
44
44
} else {
45
45
fileNumbers = await this . searchForFileNumbers ( searchDto ) ;
46
- await client . setEx (
47
- searchKey ,
48
- SEARCH_CACHE_TIME ,
49
- JSON . stringify ( [ ...fileNumbers . values ( ) ] ) ,
50
- ) ;
46
+ await client . setEx ( searchKey , SEARCH_CACHE_TIME , JSON . stringify ( [ ...fileNumbers . values ( ) ] ) ) ;
51
47
}
52
48
53
49
if ( fileNumbers . size === 0 ) {
@@ -59,23 +55,15 @@ export class InquiryAdvancedSearchService {
59
55
60
56
let query = this . inquirySearchViewRepository
61
57
. createQueryBuilder ( 'inquirySearch' , queryRunner )
62
- . innerJoinAndMapOne (
63
- 'inquirySearch.inquiryType' ,
64
- 'inquirySearch.inquiryType' ,
65
- 'inquiryType' ,
66
- )
58
+ . innerJoinAndMapOne ( 'inquirySearch.inquiryType' , 'inquirySearch.inquiryType' , 'inquiryType' )
67
59
. andWhere ( 'inquirySearch.fileNumber IN(:...fileNumbers)' , {
68
60
fileNumbers : [ ...fileNumbers . values ( ) ] ,
69
61
} ) ;
70
62
71
63
const sortQuery = this . compileSortQuery ( searchDto ) ;
72
64
73
65
query = query
74
- . orderBy (
75
- sortQuery ,
76
- searchDto . sortDirection ,
77
- searchDto . sortDirection === 'ASC' ? 'NULLS FIRST' : 'NULLS LAST' ,
78
- )
66
+ . orderBy ( sortQuery , searchDto . sortDirection , searchDto . sortDirection === 'ASC' ? 'NULLS FIRST' : 'NULLS LAST' )
79
67
. offset ( ( searchDto . page - 1 ) * searchDto . pageSize )
80
68
. limit ( searchDto . pageSize ) ;
81
69
@@ -148,19 +136,22 @@ export class InquiryAdvancedSearchService {
148
136
this . addLegacyIDResults ( searchDto , promises ) ;
149
137
}
150
138
139
+ if ( searchDto . tagIds && searchDto . tagIds . length > 0 ) {
140
+ this . addTagsResults ( promises ) ;
141
+ }
142
+
143
+ if ( searchDto . tagCategoryId ) {
144
+ this . addTagCategoryResults ( promises ) ;
145
+ }
146
+
151
147
const t0 = performance . now ( ) ;
152
148
const finalResult = await processSearchPromises ( promises ) ;
153
149
const t1 = performance . now ( ) ;
154
- this . logger . debug (
155
- `ALCS Inquiry pre-search search took ${ t1 - t0 } milliseconds.` ,
156
- ) ;
150
+ this . logger . debug ( `ALCS Inquiry pre-search search took ${ t1 - t0 } milliseconds.` ) ;
157
151
return finalResult ;
158
152
}
159
153
160
- private addFileNumberResults (
161
- searchDto : SearchRequestDto ,
162
- promises : Promise < { fileNumber : string } [ ] > [ ] ,
163
- ) {
154
+ private addFileNumberResults ( searchDto : SearchRequestDto , promises : Promise < { fileNumber : string } [ ] > [ ] ) {
164
155
const promise = this . inquiryRepository . find ( {
165
156
where : {
166
157
fileNumber : searchDto . fileNumber ,
@@ -172,10 +163,7 @@ export class InquiryAdvancedSearchService {
172
163
promises . push ( promise ) ;
173
164
}
174
165
175
- private async addGovernmentResults (
176
- searchDto : SearchRequestDto ,
177
- promises : Promise < { fileNumber : string } [ ] > [ ] ,
178
- ) {
166
+ private async addGovernmentResults ( searchDto : SearchRequestDto , promises : Promise < { fileNumber : string } [ ] > [ ] ) {
179
167
const government = await this . governmentRepository . findOneByOrFail ( {
180
168
name : searchDto . governmentName ,
181
169
} ) ;
@@ -191,10 +179,7 @@ export class InquiryAdvancedSearchService {
191
179
promises . push ( promise ) ;
192
180
}
193
181
194
- private addRegionResults (
195
- searchDto : SearchRequestDto ,
196
- promises : Promise < { fileNumber : string } [ ] > [ ] ,
197
- ) {
182
+ private addRegionResults ( searchDto : SearchRequestDto , promises : Promise < { fileNumber : string } [ ] > [ ] ) {
198
183
const promise = this . inquiryRepository . find ( {
199
184
where : {
200
185
regionCode : searchDto . regionCode ,
@@ -206,21 +191,14 @@ export class InquiryAdvancedSearchService {
206
191
promises . push ( promise ) ;
207
192
}
208
193
209
- private addNameResults (
210
- searchDto : SearchRequestDto ,
211
- promises : Promise < { fileNumber : string } [ ] > [ ] ,
212
- ) {
213
- const formattedSearchString =
214
- formatStringToPostgresSearchStringArrayWithWildCard ( searchDto . name ! ) ;
194
+ private addNameResults ( searchDto : SearchRequestDto , promises : Promise < { fileNumber : string } [ ] > [ ] ) {
195
+ const formattedSearchString = formatStringToPostgresSearchStringArrayWithWildCard ( searchDto . name ! ) ;
215
196
const promise = this . inquiryRepository
216
197
. createQueryBuilder ( 'inquiry' )
217
198
. select ( 'inquiry.fileNumber' )
218
- . where (
219
- "LOWER(inquiry.inquirer_first_name || ' ' || inquiry.inquirer_last_name) LIKE ANY (:names)" ,
220
- {
221
- names : formattedSearchString ,
222
- } ,
223
- )
199
+ . where ( "LOWER(inquiry.inquirer_first_name || ' ' || inquiry.inquirer_last_name) LIKE ANY (:names)" , {
200
+ names : formattedSearchString ,
201
+ } )
224
202
. orWhere ( 'LOWER(inquiry.inquirer_first_name) LIKE ANY (:names)' , {
225
203
names : formattedSearchString ,
226
204
} )
@@ -234,10 +212,7 @@ export class InquiryAdvancedSearchService {
234
212
promises . push ( promise ) ;
235
213
}
236
214
237
- private addParcelResults (
238
- searchDto : SearchRequestDto ,
239
- promises : Promise < { fileNumber : string } [ ] > [ ] ,
240
- ) {
215
+ private addParcelResults ( searchDto : SearchRequestDto , promises : Promise < { fileNumber : string } [ ] > [ ] ) {
241
216
let query = this . inquiryRepository
242
217
. createQueryBuilder ( 'inquiry' )
243
218
. select ( 'inquiry.fileNumber' )
@@ -248,21 +223,15 @@ export class InquiryAdvancedSearchService {
248
223
}
249
224
250
225
if ( searchDto . civicAddress ) {
251
- query = query . andWhere (
252
- 'LOWER(parcel.civic_address) like LOWER(:civic_address)' ,
253
- {
254
- civic_address : `%${ searchDto . civicAddress } %` . toLowerCase ( ) ,
255
- } ,
256
- ) ;
226
+ query = query . andWhere ( 'LOWER(parcel.civic_address) like LOWER(:civic_address)' , {
227
+ civic_address : `%${ searchDto . civicAddress } %` . toLowerCase ( ) ,
228
+ } ) ;
257
229
}
258
230
259
231
promises . push ( query . getMany ( ) ) ;
260
232
}
261
233
262
- private addFileTypeResults (
263
- searchDto : SearchRequestDto ,
264
- promises : Promise < { fileNumber : string } [ ] > [ ] ,
265
- ) {
234
+ private addFileTypeResults ( searchDto : SearchRequestDto , promises : Promise < { fileNumber : string } [ ] > [ ] ) {
266
235
const query = this . inquiryRepository
267
236
. createQueryBuilder ( 'inquiry' )
268
237
. select ( 'inquiry.fileNumber' )
@@ -273,42 +242,24 @@ export class InquiryAdvancedSearchService {
273
242
promises . push ( query . getMany ( ) ) ;
274
243
}
275
244
276
- private addSubmittedDateResults (
277
- searchDto : SearchRequestDto ,
278
- promises : Promise < { fileNumber : string } [ ] > [ ] ,
279
- ) {
280
- let query = this . inquiryRepository
281
- . createQueryBuilder ( 'inquiry' )
282
- . select ( 'inquiry.fileNumber' ) ;
245
+ private addSubmittedDateResults ( searchDto : SearchRequestDto , promises : Promise < { fileNumber : string } [ ] > [ ] ) {
246
+ let query = this . inquiryRepository . createQueryBuilder ( 'inquiry' ) . select ( 'inquiry.fileNumber' ) ;
283
247
284
248
if ( searchDto . dateSubmittedFrom !== undefined ) {
285
- query = query . andWhere (
286
- 'inquiry.date_submitted_to_alc >= :date_submitted_from' ,
287
- {
288
- date_submitted_from : getStartOfDayToPacific (
289
- searchDto . dateSubmittedFrom
290
- ) . toISOString ( ) ,
291
- } ,
292
- ) ;
249
+ query = query . andWhere ( 'inquiry.date_submitted_to_alc >= :date_submitted_from' , {
250
+ date_submitted_from : getStartOfDayToPacific ( searchDto . dateSubmittedFrom ) . toISOString ( ) ,
251
+ } ) ;
293
252
}
294
253
295
254
if ( searchDto . dateSubmittedTo !== undefined ) {
296
- query = query . andWhere (
297
- 'inquiry.date_submitted_to_alc < :date_submitted_to' ,
298
- {
299
- date_submitted_to : getNextDayToPacific (
300
- searchDto . dateSubmittedTo
301
- ) . toISOString ( ) ,
302
- } ,
303
- ) ;
255
+ query = query . andWhere ( 'inquiry.date_submitted_to_alc < :date_submitted_to' , {
256
+ date_submitted_to : getNextDayToPacific ( searchDto . dateSubmittedTo ) . toISOString ( ) ,
257
+ } ) ;
304
258
}
305
259
promises . push ( query . getMany ( ) ) ;
306
260
}
307
261
308
- private addLegacyIDResults (
309
- searchDto : SearchRequestDto ,
310
- promises : Promise < { fileNumber : string } [ ] > [ ] ,
311
- ) {
262
+ private addLegacyIDResults ( searchDto : SearchRequestDto , promises : Promise < { fileNumber : string } [ ] > [ ] ) {
312
263
const promise = this . inquiryRepository . find ( {
313
264
where : {
314
265
legacyId : searchDto . legacyId ,
@@ -319,4 +270,16 @@ export class InquiryAdvancedSearchService {
319
270
} ) ;
320
271
promises . push ( promise ) ;
321
272
}
273
+
274
+ private addTagsResults ( promises : Promise < { fileNumber : string } [ ] > [ ] ) {
275
+ // add tags filter when it's implemented
276
+ const emptyPromise = Promise . all ( [ ] ) ;
277
+ promises . push ( emptyPromise ) ;
278
+ }
279
+
280
+ private addTagCategoryResults ( promises : Promise < { fileNumber : string } [ ] > [ ] ) {
281
+ // add tag category filter when it's implemented
282
+ const emptyPromise = Promise . all ( [ ] ) ;
283
+ promises . push ( emptyPromise ) ;
284
+ }
322
285
}
0 commit comments