From b460c4dbfba41d484900fba4ef496aa5b08111a9 Mon Sep 17 00:00:00 2001 From: JuanGustah Date: Thu, 16 May 2024 11:34:25 -0300 Subject: [PATCH 1/4] feat: add enabled column in database --- prisma/dev_dump.sql | 2 +- prisma/migrations/20240516032930_/migration.sql | 2 ++ prisma/schema.prisma | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 prisma/migrations/20240516032930_/migration.sql diff --git a/prisma/dev_dump.sql b/prisma/dev_dump.sql index b530df8a..d69b5536 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, 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'); diff --git a/prisma/migrations/20240516032930_/migration.sql b/prisma/migrations/20240516032930_/migration.sql new file mode 100644 index 00000000..c6dd9133 --- /dev/null +++ b/prisma/migrations/20240516032930_/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "shelters" ADD COLUMN "enabled" BOOLEAN NOT NULL DEFAULT true; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index a43b535a..e7bc6fe8 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -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) From eeaa7ca3fbafdfc398dc88f3b778f64a97628eae Mon Sep 17 00:00:00 2001 From: JuanGustah Date: Thu, 16 May 2024 11:35:13 -0300 Subject: [PATCH 2/4] feat: update index and show service with showDisabled option --- src/shelter/ShelterSearch.ts | 12 +++++++++++- src/shelter/shelter.service.ts | 2 ++ src/shelter/types/search.types.ts | 5 +++++ src/shelter/types/types.ts | 2 ++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/shelter/ShelterSearch.ts b/src/shelter/ShelterSearch.ts index 3d1367e5..fc825f62 100644 --- a/src/shelter/ShelterSearch.ts +++ b/src/shelter/ShelterSearch.ts @@ -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, @@ -160,6 +169,7 @@ class ShelterSearch { { OR: this.shelterStatus }, this.priority(this.formProps.supplyIds), this.supplyCategoryIds(this.formProps.priority), + this.showDisabled, ], }; diff --git a/src/shelter/shelter.service.ts b/src/shelter/shelter.service.ts index f9c853d8..0ce23e72 100644 --- a/src/shelter/shelter.service.ts +++ b/src/shelter/shelter.service.ts @@ -87,6 +87,7 @@ export class ShelterService implements OnModuleInit { latitude: true, longitude: true, verified: true, + enabled: true, shelterSupplies: { select: { priority: true, @@ -155,6 +156,7 @@ export class ShelterService implements OnModuleInit { shelteredPeople: true, prioritySum: true, verified: true, + enabled: true, latitude: true, longitude: true, createdAt: true, diff --git a/src/shelter/types/search.types.ts b/src/shelter/types/search.types.ts index b87e653a..f0764d15 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(), + showDisabled: 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..e1bb5fc3 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(), + enabled: z.boolean(), createdAt: z.string(), updatedAt: z.string().nullable().optional(), }); @@ -33,6 +34,7 @@ const CreateShelterSchema = ShelterSchema.omit({ createdAt: true, updatedAt: true, verified: true, + enabled: true, }); const UpdateShelterSchema = ShelterSchema.pick({ From 889a0df301d394ad9a739efeb469beee867d917c Mon Sep 17 00:00:00 2001 From: JuanGustah Date: Mon, 20 May 2024 10:13:21 -0300 Subject: [PATCH 3/4] fix: remove duplicated flag migration --- prisma/migrations/20240516032930_/migration.sql | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 prisma/migrations/20240516032930_/migration.sql diff --git a/prisma/migrations/20240516032930_/migration.sql b/prisma/migrations/20240516032930_/migration.sql deleted file mode 100644 index c6dd9133..00000000 --- a/prisma/migrations/20240516032930_/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "shelters" ADD COLUMN "enabled" BOOLEAN NOT NULL DEFAULT true; From e5e59ab40673a7417af293085ddf24b59146bbd8 Mon Sep 17 00:00:00 2001 From: JuanGustah Date: Mon, 20 May 2024 10:23:23 -0300 Subject: [PATCH 4/4] fix: change disabled column flag by the already migrated actived column flag --- prisma/dev_dump.sql | 2 +- src/shelter/ShelterSearch.ts | 10 +++++----- src/shelter/types/search.types.ts | 2 +- src/shelter/types/types.ts | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/prisma/dev_dump.sql b/prisma/dev_dump.sql index d69b5536..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, 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.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 59255664..fcdec531 100644 --- a/src/shelter/ShelterSearch.ts +++ b/src/shelter/ShelterSearch.ts @@ -148,17 +148,17 @@ class ShelterSearch { }; } - get showDisabled(): Prisma.ShelterWhereInput { - if (this.formProps.showDisabled) return {}; + get showDeactivated(): Prisma.ShelterWhereInput { + if (this.formProps.showDeactivated) return {}; return { - enabled: true, + actived: true, }; } async getQuery(): Promise { if (Object.keys(this.formProps).length === 0) - return { ...this.showDisabled }; + return { ...this.showDeactivated }; const search = await this.getSearch(); const queryData = { @@ -169,7 +169,7 @@ class ShelterSearch { { OR: this.shelterStatus }, this.priority(this.formProps.supplyIds), this.supplyCategoryIds(this.formProps.priority), - this.showDisabled, + this.showDeactivated, ], }; diff --git a/src/shelter/types/search.types.ts b/src/shelter/types/search.types.ts index f0764d15..32c09769 100644 --- a/src/shelter/types/search.types.ts +++ b/src/shelter/types/search.types.ts @@ -41,7 +41,7 @@ export const ShelterSearchPropsSchema = z.object({ tags: ShelterTagInfoSchema.nullable().optional(), cities: z.array(z.string()).optional(), geolocation: GeolocationFilterSchema.optional(), - showDisabled: z + showDeactivated: z .string() .refine((value) => value === 'true' || value === 'false') .transform((value) => value === 'true') diff --git a/src/shelter/types/types.ts b/src/shelter/types/types.ts index e1bb5fc3..f9ffa9ae 100644 --- a/src/shelter/types/types.ts +++ b/src/shelter/types/types.ts @@ -24,7 +24,7 @@ const ShelterSchema = z.object({ capacity: z.number().min(0).nullable().optional(), contact: z.string().nullable().optional(), verified: z.boolean(), - enabled: z.boolean(), + actived: z.boolean(), createdAt: z.string(), updatedAt: z.string().nullable().optional(), }); @@ -34,7 +34,7 @@ const CreateShelterSchema = ShelterSchema.omit({ createdAt: true, updatedAt: true, verified: true, - enabled: true, + actived: true, }); const UpdateShelterSchema = ShelterSchema.pick({