Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Habilitar a capacidade e a quantidade de pets abrigados #166

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions prisma/migrations/20240523235040_sheltered_pets/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "shelters" ADD COLUMN "pet_capacity" INTEGER,
ADD COLUMN "sheltered_pets" INTEGER;
2 changes: 2 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ model Shelter {
petFriendly Boolean? @map("pet_friendly")
shelteredPeople Int? @map("sheltered_people")
capacity Int?
shelteredPets Int? @map("sheltered_pets")
petCapacity Int? @map("pet_capacity")
contact String?
prioritySum Int @default(value: 0) @map("priority_sum")
latitude Float?
Expand Down
4 changes: 4 additions & 0 deletions src/shelter/shelter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export class ShelterService implements OnModuleInit {
pix: true,
shelteredPeople: true,
capacity: true,
shelteredPets: true,
petCapacity: true,
contact: shouldShowContact,
petFriendly: true,
prioritySum: true,
Expand Down Expand Up @@ -155,8 +157,10 @@ export class ShelterService implements OnModuleInit {
streetNumber: true,
zipCode: true,
capacity: true,
petCapacity: true,
petFriendly: true,
shelteredPeople: true,
shelteredPets: true,
prioritySum: true,
verified: true,
latitude: true,
Expand Down
28 changes: 25 additions & 3 deletions src/shelter/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@
supply: string;
}

const petFriendlyRefinement = function(obj, ctx) {

Check failure on line 11 in src/shelter/types/types.ts

View workflow job for this annotation

GitHub Actions / build

Insert `·`
if(!obj.petFriendly) {

Check failure on line 12 in src/shelter/types/types.ts

View workflow job for this annotation

GitHub Actions / build

Insert `·`
if(obj.petCapacity) ctx.addIssue({

Check failure on line 13 in src/shelter/types/types.ts

View workflow job for this annotation

GitHub Actions / build

Replace `(obj.petCapacity)` with `·(obj.petCapacity)⏎·····`
code: z.ZodIssueCode.custom,

Check failure on line 14 in src/shelter/types/types.ts

View workflow job for this annotation

GitHub Actions / build

Insert `··`
message: 'Shelter is not pet friendly',

Check failure on line 15 in src/shelter/types/types.ts

View workflow job for this annotation

GitHub Actions / build

Insert `··`
path: ['petCapacity']

Check failure on line 16 in src/shelter/types/types.ts

View workflow job for this annotation

GitHub Actions / build

Replace `path:·['petCapacity']` with `··path:·['petCapacity'],`
});

Check failure on line 17 in src/shelter/types/types.ts

View workflow job for this annotation

GitHub Actions / build

Replace `····` with `······`

if(obj.shelteredPets) ctx.addIssue({

Check failure on line 19 in src/shelter/types/types.ts

View workflow job for this annotation

GitHub Actions / build

Replace `(obj.shelteredPets)` with `·(obj.shelteredPets)⏎·····`
code: z.ZodIssueCode.custom,

Check failure on line 20 in src/shelter/types/types.ts

View workflow job for this annotation

GitHub Actions / build

Replace `······` with `········`
message: 'Shelter is not pet friendly',

Check failure on line 21 in src/shelter/types/types.ts

View workflow job for this annotation

GitHub Actions / build

Insert `··`
path: ['shelteredPets']
});
}
};

const ShelterSchema = z.object({
id: z.string(),
name: z.string().transform(capitalize),
Expand All @@ -20,9 +36,11 @@
zipCode: z.string().nullable().optional(),
petFriendly: z.boolean().nullable().optional(),
shelteredPeople: z.number().min(0).nullable().optional(),
shelteredPets: z.number().min(0).nullable().optional(),
latitude: z.number().nullable().optional(),
longitude: z.number().nullable().optional(),
capacity: z.number().min(0).nullable().optional(),
petCapacity: z.number().min(0).nullable().optional(),
contact: z.string().nullable().optional(),
verified: z.boolean(),
createdAt: z.string(),
Expand All @@ -34,20 +52,24 @@
createdAt: true,
updatedAt: true,
verified: true,
});
}).superRefine(petFriendlyRefinement);

const UpdateShelterSchema = ShelterSchema.pick({
petFriendly: true,
shelteredPeople: true,
}).partial();
petCapacity: true,
shelteredPets: true
}).partial()
.superRefine(petFriendlyRefinement);

const FullUpdateShelterSchema = ShelterSchema.omit({
id: true,
createdAt: true,
updatedAt: true,
})
.partial()
.transform((args) => removeEmptyStrings<typeof args>(args));
.transform((args) => removeEmptyStrings<typeof args>(args))
.superRefine(petFriendlyRefinement);

export {
ShelterSchema,
Expand Down