Skip to content

Commit 38c41ac

Browse files
committed
wip
1 parent d9e6ed9 commit 38c41ac

File tree

5 files changed

+30
-13
lines changed

5 files changed

+30
-13
lines changed

src/prisma/hooks/shelter/index.ts

Whitespace-only changes.

src/prisma/hooks/shelter/shelter-hooks.ts

Whitespace-only changes.

src/prisma/hooks/user/index.ts

Whitespace-only changes.

src/prisma/hooks/user/user-hooks.ts

Whitespace-only changes.

src/shelter/shelter.service.ts

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ import {
1111
} from './types';
1212
import { SearchSchema } from '../types';
1313
import { ShelterSearch } from './ShelterSearch';
14+
import { Prisma } from '@prisma/client';
15+
import { DefaultArgs } from '@prisma/client/runtime/library';
1416
import { SupplyPriority } from 'src/supply/types';
1517

1618
@Injectable()
1719
export class ShelterService {
18-
constructor(private readonly prismaService: PrismaService) {}
20+
private voluntaryIds: string[] = [];
21+
22+
constructor(private readonly prismaService: PrismaService) {
23+
this.loadVoluntaryIds();
24+
}
1925

2026
async store(body: z.infer<typeof CreateShelterSchema>) {
2127
const payload = CreateShelterSchema.parse(body);
@@ -120,7 +126,7 @@ export class ShelterService {
120126
const take = perPage;
121127
const skip = perPage * (page - 1);
122128

123-
const whereData = {
129+
const whereData: Prisma.ShelterFindManyArgs<DefaultArgs> = {
124130
take,
125131
skip,
126132
orderBy: { [orderBy]: order },
@@ -147,31 +153,42 @@ export class ShelterService {
147153
shelterSupplies: {
148154
where: {
149155
priority: {
150-
gt: SupplyPriority.UnderControl,
156+
notIn: [SupplyPriority.UnderControl],
151157
},
152158
},
159+
take: 10,
160+
orderBy: {
161+
updatedAt: 'desc',
162+
},
153163
select: {
154-
priority: true,
155-
quantity: true,
156164
supply: {
157165
select: {
158166
id: true,
159167
name: true,
160-
supplyCategory: {
161-
select: {
162-
id: true,
163-
name: true,
164-
},
165-
},
166-
createdAt: true,
167-
updatedAt: true,
168168
},
169169
},
170+
priority: true,
171+
createdAt: true,
172+
updatedAt: true,
170173
},
171174
},
172175
},
173176
});
174177

175178
return { page, perPage, count, results };
176179
}
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+
}
177194
}

0 commit comments

Comments
 (0)