Skip to content

Commit 890b826

Browse files
Merge pull request #29 from jotahdavid/feat/supply-quantity
Adicionado propriedade de quantidade de suprimentos nos abrigos
2 parents 4268e47 + 3f787a5 commit 890b826

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "shelter_supplies" ADD COLUMN "quantity" INTEGER;

prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ model ShelterSupply {
5858
shelterId String @map("shelter_id")
5959
supplyId String @map("supply_id")
6060
priority Int @default(value: 0)
61+
quantity Int?
6162
createdAt String @map("created_at") @db.VarChar(32)
6263
updatedAt String? @map("updated_at") @db.VarChar(32)
6364

src/shelter-supply/shelter-supply.service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Injectable } from '@nestjs/common';
33

44
import { PrismaService } from '../prisma/prisma.service';
55
import { CreateShelterSupplySchema, UpdateShelterSupplySchema } from './types';
6+
import { SupplyPriority } from '../supply/types';
67

78
@Injectable()
89
export class ShelterSupplyService {
@@ -27,22 +28,23 @@ export class ShelterSupplyService {
2728
}
2829

2930
async store(body: z.infer<typeof CreateShelterSupplySchema>) {
30-
const { shelterId, priority, supplyId } =
31+
const { shelterId, priority, supplyId, quantity } =
3132
CreateShelterSupplySchema.parse(body);
3233
await this.handleUpdateShelterSum(shelterId, 0, priority);
3334
await this.prismaService.shelterSupply.create({
3435
data: {
3536
shelterId,
3637
priority,
3738
supplyId,
39+
quantity: priority !== SupplyPriority.UnderControl ? quantity : null,
3840
createdAt: new Date().toISOString(),
3941
},
4042
});
4143
}
4244

4345
async update(body: z.infer<typeof UpdateShelterSupplySchema>) {
4446
const { data, where } = UpdateShelterSupplySchema.parse(body);
45-
const { priority } = data;
47+
const { priority, quantity } = data;
4648
if (priority !== null && priority !== undefined) {
4749
const shelterSupply = await this.prismaService.shelterSupply.findFirst({
4850
where: {
@@ -67,6 +69,7 @@ export class ShelterSupplyService {
6769
},
6870
data: {
6971
...data,
72+
quantity: priority !== SupplyPriority.UnderControl ? quantity : null,
7073
createdAt: new Date().toISOString(),
7174
},
7275
});
@@ -79,6 +82,7 @@ export class ShelterSupplyService {
7982
},
8083
select: {
8184
priority: true,
85+
quantity: true,
8286
supply: {
8387
select: {
8488
id: true,

src/shelter-supply/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const ShelterSupplySchema = z.object({
1212
z.literal(SupplyPriority.Needing),
1313
z.literal(SupplyPriority.Urgent),
1414
]),
15+
quantity: z.number().gt(0).nullable().optional(),
1516
createdAt: z.string(),
1617
updatedAt: z.string().nullable().optional(),
1718
});
@@ -20,6 +21,7 @@ const CreateShelterSupplySchema = ShelterSupplySchema.pick({
2021
shelterId: true,
2122
supplyId: true,
2223
priority: true,
24+
quantity: true,
2325
});
2426

2527
const UpdateShelterSupplySchema = z.object({
@@ -31,6 +33,7 @@ const UpdateShelterSupplySchema = z.object({
3133
z.literal(SupplyPriority.Needing),
3234
z.literal(SupplyPriority.Urgent),
3335
]),
36+
quantity: z.number().nullable().optional(),
3437
shelterId: z.string(),
3538
supplyId: z.string(),
3639
})

src/shelter/shelter.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export class ShelterService {
7979
},
8080
select: {
8181
priority: true,
82+
quantity: true,
8283
supply: {
8384
select: {
8485
id: true,
@@ -133,6 +134,7 @@ export class ShelterService {
133134
},
134135
select: {
135136
priority: true,
137+
quantity: true,
136138
supply: {
137139
select: {
138140
id: true,
@@ -212,6 +214,7 @@ export class ShelterService {
212214
},
213215
select: {
214216
priority: true,
217+
quantity: true,
215218
supply: {
216219
select: {
217220
id: true,

0 commit comments

Comments
 (0)