Skip to content

Commit 4a08372

Browse files
fagundesjgfilipepacheco
authored andcommitted
feat: update many supplies
1 parent 7bc42d7 commit 4a08372

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

src/shelter-supply/shelter-supply.controller.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ import {
77
Param,
88
Post,
99
Put,
10-
UseGuards,
1110
} from '@nestjs/common';
1211
import { ApiTags } from '@nestjs/swagger';
1312

1413
import { ShelterSupplyService } from './shelter-supply.service';
1514
import { ServerResponse } from '../utils';
16-
import { DistributionCenterGuard } from '@/guards/distribution-center.guard';
1715

1816
@ApiTags('Suprimento de abrigos')
1917
@Controller('shelter/supplies')
@@ -71,7 +69,6 @@ export class ShelterSupplyController {
7169
}
7270

7371
@Put(':shelterId/supplies/many')
74-
@UseGuards(DistributionCenterGuard)
7572
async updateMany(@Body() body, @Param('shelterId') shelterId: string) {
7673
try {
7774
const data = await this.shelterSupplyService.updateMany({

src/shelter/ShelterSearch.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,22 @@ class ShelterSearch {
2727
this.formProps = { ...props };
2828
}
2929

30-
get priority(): Prisma.ShelterWhereInput[] {
30+
priority(supplyIds: string[] = []): Prisma.ShelterWhereInput {
3131
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,
3842
},
3943
},
40-
];
41-
}
42-
return [];
44+
};
45+
} else return {};
4346
}
4447

4548
get shelterStatus(): Prisma.ShelterWhereInput[] {
@@ -66,11 +69,14 @@ class ShelterSearch {
6669
}
6770
}
6871

69-
get supplyCategoryIds(): Prisma.ShelterWhereInput {
72+
supplyCategoryIds(
73+
priority?: SupplyPriority | null,
74+
): Prisma.ShelterWhereInput {
7075
if (!this.formProps.supplyCategoryIds) return {};
7176
return {
7277
shelterSupplies: {
7378
some: {
79+
priority: priority ? +priority : undefined,
7480
supply: {
7581
supplyCategoryId: {
7682
in: this.formProps.supplyCategoryIds,
@@ -116,14 +122,14 @@ class ShelterSearch {
116122
}
117123

118124
get query(): Prisma.ShelterWhereInput {
125+
console.log(this.formProps);
119126
if (Object.keys(this.formProps).length === 0) return {};
120127
const queryData = {
121128
AND: [
122129
{ 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),
127133
],
128134
};
129135

@@ -173,7 +179,10 @@ function parseTagResponse(
173179
}
174180
if (
175181
tags.NeedVolunteers &&
176-
voluntaryIds.includes(shelterSupply.supply.supplyCategoryId)
182+
voluntaryIds.includes(shelterSupply.supply.supplyCategoryId) &&
183+
[SupplyPriority.Urgent, SupplyPriority.Needing].includes(
184+
shelterSupply.priority,
185+
)
177186
) {
178187
if (qtd.NeedVolunteers < tags.NeedVolunteers) {
179188
qtd.NeedVolunteers++;

0 commit comments

Comments
 (0)