diff --git a/src/app/casos-activos/solicitudes/page.tsx b/src/app/casos-activos/solicitudes/page.tsx
index 9981f6d..10e9b3e 100644
--- a/src/app/casos-activos/solicitudes/page.tsx
+++ b/src/app/casos-activos/solicitudes/page.tsx
@@ -84,7 +84,10 @@ function Solicitudes() {
setError(null);
// Comenzamos la consulta
- const query = supabase.from('help_requests').select('*', { count: 'exact' }).eq('type', 'necesita');
+ const query = supabase
+ .from('help_requests_with_assignment_count')
+ .select('*', { count: 'exact' })
+ .eq('type', 'necesita');
// Solo agregar filtro si no es "todos"
if (filtroData.tipoAyuda !== 'todas') {
@@ -103,7 +106,7 @@ function Solicitudes() {
// Solo agregar filtro si es true
if (isStringTrue(filtroData.soloSinAsignar)) {
- query.eq('asignees_count', 0);
+ query.eq('assignments_count', 0);
}
query.neq('status', 'finished');
@@ -190,13 +193,13 @@ function Solicitudes() {
))}
- {/*
-
-
*/}
+
+
+
diff --git a/src/types/database.ts b/src/types/database.ts
index 0e8c342..a863b04 100644
--- a/src/types/database.ts
+++ b/src/types/database.ts
@@ -166,6 +166,13 @@ export type Database = {
referencedRelation: 'help_requests';
referencedColumns: ['id'];
},
+ {
+ foreignKeyName: 'fk_help_request';
+ columns: ['help_request_id'];
+ isOneToOne: false;
+ referencedRelation: 'help_requests_with_assignment_count';
+ referencedColumns: ['id'];
+ },
];
};
help_requests: {
@@ -365,6 +372,41 @@ export type Database = {
};
Relationships: [];
};
+ help_requests_with_assignment_count: {
+ Row: {
+ additional_info: Json | null;
+ asignees_count: number | null;
+ assignments_count: number | null;
+ contact_info: string | null;
+ coordinates: unknown | null;
+ created_at: string | null;
+ description: string | null;
+ help_type: Database['public']['Enums']['help_type_enum'][] | null;
+ id: number | null;
+ latitude: number | null;
+ location: string | null;
+ longitude: number | null;
+ name: string | null;
+ number_of_people: number | null;
+ other_help: string | null;
+ people_needed: number | null;
+ resources: Json | null;
+ status: string | null;
+ town_id: number | null;
+ type: string | null;
+ urgency: string | null;
+ user_id: string | null;
+ };
+ Relationships: [
+ {
+ foreignKeyName: 'help_requests_town_id_fkey';
+ columns: ['town_id'];
+ isOneToOne: false;
+ referencedRelation: 'towns';
+ referencedColumns: ['id'];
+ },
+ ];
+ };
};
Functions: {
[_ in never]: never;
diff --git a/supabase/migrations/20241110202222_Add view with assignments count.sql b/supabase/migrations/20241110202222_Add view with assignments count.sql
new file mode 100644
index 0000000..a5a627e
--- /dev/null
+++ b/supabase/migrations/20241110202222_Add view with assignments count.sql
@@ -0,0 +1,10 @@
+create view help_requests_with_assignment_count as
+select
+ hr.*,
+ coalesce(count(hra.id), 0) as assignments_count
+from
+ help_requests hr
+left join
+ help_request_assignments hra on hr.id = hra.help_request_id
+group by
+ hr.id;
\ No newline at end of file