File tree Expand file tree Collapse file tree 1 file changed +35
-24
lines changed Expand file tree Collapse file tree 1 file changed +35
-24
lines changed Original file line number Diff line number Diff line change @@ -216,39 +216,50 @@ export class ShelterService {
216
216
}
217
217
218
218
private mountWhereFilter ( payload : z . infer < typeof ComplexSearchSchema > ) {
219
- return {
219
+ const filter : any = {
220
220
AND : [
221
221
{
222
222
OR : [
223
223
{ address : { contains : payload . search } } ,
224
224
{ name : { contains : payload . search } } ,
225
225
] ,
226
226
} ,
227
- {
228
- shelterSupplies : {
229
- some : {
230
- priority : payload . priority
231
- ? parseInt ( payload . priority )
232
- : undefined ,
233
- supply : {
234
- supplyCategoryId : {
235
- in :
236
- payload ?. supplyCategories ?. length !== 0
237
- ? payload . supplyCategories !
238
- : undefined ,
239
- } ,
240
- } ,
241
- supplyId : {
242
- in :
243
- payload ?. supplies ?. length !== 0
244
- ? payload . supplies !
245
- : undefined ,
246
- } ,
247
- } ,
248
- } ,
249
- } ,
250
227
] ,
251
228
} ;
229
+
230
+ const shelterSuppliesFilter = {
231
+ shelterSupplies : {
232
+ some : { } ,
233
+ } ,
234
+ } ;
235
+
236
+ if ( payload . priority ) {
237
+ shelterSuppliesFilter . shelterSupplies . some [ 'priority' ] = parseInt (
238
+ payload . priority ,
239
+ ) ;
240
+ }
241
+
242
+ if ( payload ?. supplyCategories && payload ?. supplyCategories . length !== 0 ) {
243
+ shelterSuppliesFilter . shelterSupplies . some [ 'supply' ] = {
244
+ supplyCategoryId : {
245
+ in : payload . supplyCategories ,
246
+ } ,
247
+ } ;
248
+ }
249
+
250
+ if ( payload ?. supplies && payload ?. supplies . length !== 0 ) {
251
+ shelterSuppliesFilter . shelterSupplies . some [ 'supplyId' ] = {
252
+ supplyId : {
253
+ in : payload . supplies ,
254
+ } ,
255
+ } ;
256
+ }
257
+
258
+ if ( Object . keys ( shelterSuppliesFilter . shelterSupplies . some ) . length !== 0 ) {
259
+ filter [ 'AND' ] . push ( shelterSuppliesFilter ) ;
260
+ }
261
+
262
+ return filter ;
252
263
}
253
264
254
265
private addShelterStatusFilter ( payload : z . infer < typeof ComplexSearchSchema > ) {
You can’t perform that action at this time.
0 commit comments