Skip to content
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
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, actived ) 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
12 changes: 11 additions & 1 deletion src/shelter/ShelterSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,17 @@ class ShelterSearch {
};
}

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

return {
actived: true,
};
}

async getQuery(): Promise<Prisma.ShelterWhereInput> {
if (Object.keys(this.formProps).length === 0) return {};
if (Object.keys(this.formProps).length === 0)
return { ...this.showDeactivated };

const search = await this.getSearch();
const queryData = {
Expand All @@ -160,6 +169,7 @@ class ShelterSearch {
{ OR: this.shelterStatus },
this.priority(this.formProps.supplyIds),
this.supplyCategoryIds(this.formProps.priority),
this.showDeactivated,
],
};

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(),
showDeactivated: 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(),
actived: 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,
actived: true,
});

const UpdateShelterSchema = ShelterSchema.pick({
Expand Down