Skip to content

Commit

Permalink
Merge pull request #189 from pedrolivaresanchez/fix/filter-non-assign…
Browse files Browse the repository at this point in the history
…ed-v2

Arreglar filtro por solicitudes no atendidas
  • Loading branch information
Pinx0 authored Nov 11, 2024
2 parents 8c15910 + c4d6edd commit 6d13e32
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/app/casos-activos/solicitudes/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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');
Expand Down Expand Up @@ -190,13 +193,13 @@ function Solicitudes() {
))}
</select>
</div>
{/*<div className="flex flex-row flex-1 justify-end">
<Toggle
handleChange={handleToggleChange}
checked={isStringTrue(filtroData.soloSinAsignar)}
label="Sólo ofertas sin voluntarios"
/>
</div>*/}
<div className="flex flex-row flex-1 justify-end">
<Toggle
handleChange={handleToggleChange}
checked={isStringTrue(filtroData.soloSinAsignar)}
label="Sólo ofertas sin voluntarios"
/>
</div>
</div>
</div>
<div className="grid gap-4">
Expand Down
42 changes: 42 additions & 0 deletions src/types/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 6d13e32

Please sign in to comment.