@@ -11,11 +11,17 @@ import {
11
11
} from './types' ;
12
12
import { SearchSchema } from '../types' ;
13
13
import { ShelterSearch } from './ShelterSearch' ;
14
+ import { Prisma } from '@prisma/client' ;
15
+ import { DefaultArgs } from '@prisma/client/runtime/library' ;
14
16
import { SupplyPriority } from 'src/supply/types' ;
15
17
16
18
@Injectable ( )
17
19
export class ShelterService {
18
- constructor ( private readonly prismaService : PrismaService ) { }
20
+ private voluntaryIds : string [ ] = [ ] ;
21
+
22
+ constructor ( private readonly prismaService : PrismaService ) {
23
+ this . loadVoluntaryIds ( ) ;
24
+ }
19
25
20
26
async store ( body : z . infer < typeof CreateShelterSchema > ) {
21
27
const payload = CreateShelterSchema . parse ( body ) ;
@@ -120,7 +126,7 @@ export class ShelterService {
120
126
const take = perPage ;
121
127
const skip = perPage * ( page - 1 ) ;
122
128
123
- const whereData = {
129
+ const whereData : Prisma . ShelterFindManyArgs < DefaultArgs > = {
124
130
take,
125
131
skip,
126
132
orderBy : { [ orderBy ] : order } ,
@@ -147,31 +153,42 @@ export class ShelterService {
147
153
shelterSupplies : {
148
154
where : {
149
155
priority : {
150
- gt : SupplyPriority . UnderControl ,
156
+ notIn : [ SupplyPriority . UnderControl ] ,
151
157
} ,
152
158
} ,
159
+ take : 10 ,
160
+ orderBy : {
161
+ updatedAt : 'desc' ,
162
+ } ,
153
163
select : {
154
- priority : true ,
155
- quantity : true ,
156
164
supply : {
157
165
select : {
158
166
id : true ,
159
167
name : true ,
160
- supplyCategory : {
161
- select : {
162
- id : true ,
163
- name : true ,
164
- } ,
165
- } ,
166
- createdAt : true ,
167
- updatedAt : true ,
168
168
} ,
169
169
} ,
170
+ priority : true ,
171
+ createdAt : true ,
172
+ updatedAt : true ,
170
173
} ,
171
174
} ,
172
175
} ,
173
176
} ) ;
174
177
175
178
return { page, perPage, count, results } ;
176
179
}
180
+
181
+ loadVoluntaryIds ( ) {
182
+ this . prismaService . supplyCategory
183
+ . findMany ( {
184
+ where : {
185
+ name : {
186
+ in : [ 'Especialistas e Profissionais' , 'Voluntariado' ] ,
187
+ } ,
188
+ } ,
189
+ } )
190
+ . then ( ( resp ) => {
191
+ this . voluntaryIds . push ( ...resp . map ( ( s ) => s . id ) ) ;
192
+ } ) ;
193
+ }
177
194
}
0 commit comments