Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion prisma/dev_dump.sql
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ INSERT INTO public.category_supplies (id, name, created_at, updated_at) VALUES (
INSERT INTO public.shelter_supplies (shelter_id, supply_id, priority, created_at, updated_at) VALUES ('7f21ccc7-d1de-4a23-b710-260761213000', 'ceebd729-eecc-420e-8e90-f764a487b202', 100, '2024-05-09T16:20:28.294Z', null);
INSERT INTO public.shelter_supplies (shelter_id, supply_id, priority, created_at, updated_at) VALUES ('7f21ccc7-d1de-4a23-b710-260761213000', '3a2d5542-e160-4192-974e-c0b0938b6b98', 10, '2024-05-09T16:20:35.057Z', null);
INSERT INTO public.shelter_supplies (shelter_id, supply_id, priority, created_at, updated_at) VALUES ('7f21ccc7-d1de-4a23-b710-260761213000', '73a8e20b-2973-42a4-943f-ea96a8c5e773', 1, '2024-05-09T16:20:48.077Z', null);
INSERT INTO public.shelters (id, pix, address, pet_friendly, sheltered_people, capacity, contact, created_at, updated_at, name, priority_sum, latitude, longitude, verified) VALUES ('7f21ccc7-d1de-4a23-b710-260761213000', null, 'Rua Coronel Corte Real, 975 - Petrópolis, Porto Alegre', null, null, null, null, '2024-05-07T01:04:29.240Z', '2024-05-09T16:20:48.068Z', 'Simers', 861, null, null, true);
INSERT INTO public.shelters (id, pix, address, pet_friendly, sheltered_people, capacity, contact, created_at, updated_at, name, priority_sum, latitude, longitude, verified, enabled ) VALUES ('7f21ccc7-d1de-4a23-b710-260761213000', null, 'Rua Coronel Corte Real, 975 - Petrópolis, Porto Alegre', null, null, null, null, '2024-05-07T01:04:29.240Z', '2024-05-09T16:20:48.068Z', 'Simers', 861, null, null, true, true);
INSERT INTO public.supplies (id, supply_category_id, name, created_at, updated_at) VALUES ('377fdec9-9b17-4086-8986-3e04508c4917', '03fdb0f2-6b50-4895-b970-5793cad80c86', 'Banana', '2024-05-08T16:23:26.186Z', null);
INSERT INTO public.supplies (id, supply_category_id, name, created_at, updated_at) VALUES ('43a27a70-3ed5-4a3d-8428-623810c3f717', 'bf8b5e09-544f-4eff-9bb7-6220aaa34a85', 'Roupas para adultos', '2024-05-06T03:04:40.468Z', null);
INSERT INTO public.supplies (id, supply_category_id, name, created_at, updated_at) VALUES ('ceebd729-eecc-420e-8e90-f764a487b202', '5c9b6767-5310-461b-977b-906fe16370ae', 'Fraldas Geriatricas', '2024-05-07T10:51:23.876Z', '2024-05-08T05:07:57.203Z');
Expand Down
2 changes: 2 additions & 0 deletions prisma/migrations/20240516032930_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "shelters" ADD COLUMN "enabled" BOOLEAN NOT NULL DEFAULT true;
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ model Shelter {
latitude Float?
longitude Float?
verified Boolean @default(value: false)
enabled Boolean @default(value: true)
createdAt String @map("created_at") @db.VarChar(32)
updatedAt String? @map("updated_at") @db.VarChar(32)

Expand Down
12 changes: 11 additions & 1 deletion src/shelter/ShelterSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,17 @@ class ShelterSearch {
};
}

get showDisabled(): Prisma.ShelterWhereInput {
if (this.formProps.showDisabled) return {};

return {
enabled: true,
};
}

get query(): Prisma.ShelterWhereInput {
if (Object.keys(this.formProps).length === 0) return {};
if (Object.keys(this.formProps).length === 0)
return { ...this.showDisabled };
const queryData = {
AND: [
this.cities,
Expand All @@ -160,6 +169,7 @@ class ShelterSearch {
{ OR: this.shelterStatus },
this.priority(this.formProps.supplyIds),
this.supplyCategoryIds(this.formProps.priority),
this.showDisabled,
],
};

Expand Down
2 changes: 2 additions & 0 deletions src/shelter/shelter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class ShelterService implements OnModuleInit {
latitude: true,
longitude: true,
verified: true,
enabled: true,
shelterSupplies: {
select: {
priority: true,
Expand Down Expand Up @@ -155,6 +156,7 @@ export class ShelterService implements OnModuleInit {
shelteredPeople: true,
prioritySum: true,
verified: true,
enabled: true,
latitude: true,
longitude: true,
createdAt: true,
Expand Down
5 changes: 5 additions & 0 deletions src/shelter/types/search.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export const ShelterSearchPropsSchema = z.object({
tags: ShelterTagInfoSchema.nullable().optional(),
cities: z.array(z.string()).optional(),
geolocation: GeolocationFilterSchema.optional(),
showDisabled: z
.string()
.refine((value) => value === 'true' || value === 'false')
.transform((value) => value === 'true')
.optional(),
});

export type ShelterSearchProps = z.infer<typeof ShelterSearchPropsSchema>;
Expand Down
2 changes: 2 additions & 0 deletions src/shelter/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const ShelterSchema = z.object({
capacity: z.number().min(0).nullable().optional(),
contact: z.string().nullable().optional(),
verified: z.boolean(),
enabled: z.boolean(),
createdAt: z.string(),
updatedAt: z.string().nullable().optional(),
});
Expand All @@ -33,6 +34,7 @@ const CreateShelterSchema = ShelterSchema.omit({
createdAt: true,
updatedAt: true,
verified: true,
enabled: true,
});

const UpdateShelterSchema = ShelterSchema.pick({
Expand Down