diff --git a/prisma/dev_dump.sql b/prisma/dev_dump.sql index b530df8a..bb5d87fe 100644 --- a/prisma/dev_dump.sql +++ b/prisma/dev_dump.sql @@ -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'); diff --git a/src/shelter/ShelterSearch.ts b/src/shelter/ShelterSearch.ts index 1b9c76cf..fcdec531 100644 --- a/src/shelter/ShelterSearch.ts +++ b/src/shelter/ShelterSearch.ts @@ -148,8 +148,17 @@ class ShelterSearch { }; } + get showDeactivated(): Prisma.ShelterWhereInput { + if (this.formProps.showDeactivated) return {}; + + return { + actived: true, + }; + } + async getQuery(): Promise { - 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 = { @@ -160,6 +169,7 @@ class ShelterSearch { { OR: this.shelterStatus }, this.priority(this.formProps.supplyIds), this.supplyCategoryIds(this.formProps.priority), + this.showDeactivated, ], }; diff --git a/src/shelter/types/search.types.ts b/src/shelter/types/search.types.ts index b87e653a..32c09769 100644 --- a/src/shelter/types/search.types.ts +++ b/src/shelter/types/search.types.ts @@ -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; diff --git a/src/shelter/types/types.ts b/src/shelter/types/types.ts index 0dc21bac..f9ffa9ae 100644 --- a/src/shelter/types/types.ts +++ b/src/shelter/types/types.ts @@ -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(), }); @@ -33,6 +34,7 @@ const CreateShelterSchema = ShelterSchema.omit({ createdAt: true, updatedAt: true, verified: true, + actived: true, }); const UpdateShelterSchema = ShelterSchema.pick({