Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arreglar filtro por solicitudes no atendidas #189

Merged
merged 2 commits into from
Nov 11, 2024
Merged
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
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 @@ -364,6 +371,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;