@@ -27,19 +27,22 @@ class ShelterSearch {
27
27
this . formProps = { ...props } ;
28
28
}
29
29
30
- get priority ( ) : Prisma . ShelterWhereInput [ ] {
30
+ priority ( supplyIds : string [ ] = [ ] ) : Prisma . ShelterWhereInput {
31
31
if ( this . formProps . priority ) {
32
- return [
33
- {
34
- shelterSupplies : {
35
- some : {
36
- priority : + this . formProps . priority ,
37
- } ,
32
+ return {
33
+ shelterSupplies : {
34
+ some : {
35
+ priority : + this . formProps . priority ,
36
+ supplyId :
37
+ supplyIds . length > 0
38
+ ? {
39
+ in : supplyIds ,
40
+ }
41
+ : undefined ,
38
42
} ,
39
43
} ,
40
- ] ;
41
- }
42
- return [ ] ;
44
+ } ;
45
+ } else return { } ;
43
46
}
44
47
45
48
get shelterStatus ( ) : Prisma . ShelterWhereInput [ ] {
@@ -66,11 +69,14 @@ class ShelterSearch {
66
69
}
67
70
}
68
71
69
- get supplyCategoryIds ( ) : Prisma . ShelterWhereInput {
72
+ supplyCategoryIds (
73
+ priority ?: SupplyPriority | null ,
74
+ ) : Prisma . ShelterWhereInput {
70
75
if ( ! this . formProps . supplyCategoryIds ) return { } ;
71
76
return {
72
77
shelterSupplies : {
73
78
some : {
79
+ priority : priority ? + priority : undefined ,
74
80
supply : {
75
81
supplyCategoryId : {
76
82
in : this . formProps . supplyCategoryIds ,
@@ -116,14 +122,14 @@ class ShelterSearch {
116
122
}
117
123
118
124
get query ( ) : Prisma . ShelterWhereInput {
125
+ console . log ( this . formProps ) ;
119
126
if ( Object . keys ( this . formProps ) . length === 0 ) return { } ;
120
127
const queryData = {
121
128
AND : [
122
129
{ OR : this . search } ,
123
- ...this . priority ,
124
- ...this . shelterStatus ,
125
- this . supplyCategoryIds ,
126
- this . supplyIds ,
130
+ { OR : this . shelterStatus } ,
131
+ this . priority ( this . formProps . supplyIds ) ,
132
+ this . supplyCategoryIds ( this . formProps . priority ) ,
127
133
] ,
128
134
} ;
129
135
@@ -173,7 +179,10 @@ function parseTagResponse(
173
179
}
174
180
if (
175
181
tags . NeedVolunteers &&
176
- voluntaryIds . includes ( shelterSupply . supply . supplyCategoryId )
182
+ voluntaryIds . includes ( shelterSupply . supply . supplyCategoryId ) &&
183
+ [ SupplyPriority . Urgent , SupplyPriority . Needing ] . includes (
184
+ shelterSupply . priority ,
185
+ )
177
186
) {
178
187
if ( qtd . NeedVolunteers < tags . NeedVolunteers ) {
179
188
qtd . NeedVolunteers ++ ;
0 commit comments