diff --git a/.env.example b/.env.example
index 1ad7baa7..56db3dea 100644
--- a/.env.example
+++ b/.env.example
@@ -2,6 +2,7 @@ NEXT_PUBLIC_BASE_URL=https://ajudadana.es
NEXT_PUBLIC_NODE_ENV=production
NEXT_PUBLIC_SUPABASE_URL=
NEXT_PUBLIC_SUPABASE_ANON_KEY=
+SUPABASE_SERVICE_ROLE=
SUPABASE_GOOGLE_AUTH_ID=
SUPABASE_GOOGLE_AUTH_SECRET=
API_KEY=
\ No newline at end of file
diff --git a/src/app/api/mapa/route.ts b/src/app/api/mapa/route.ts
new file mode 100644
index 00000000..81ec4e10
--- /dev/null
+++ b/src/app/api/mapa/route.ts
@@ -0,0 +1,44 @@
+import { NextRequest } from 'next/server';
+import { createServerRoleClient } from '@/lib/supabase/server_role';
+
+export async function GET(req: NextRequest) {
+ const url = new URL(req.url);
+ const searchParams: any = url.searchParams;
+
+ const help_type = searchParams.get('type') || null;
+ const urgency = searchParams.get('urgency') || null;
+ const acepta = searchParams.get('acepta') || null;
+
+ const supabase = await createServerRoleClient();
+ // const { data: dataUser, error: errorUser } = await supabase.auth.getUser();
+ // if (errorUser || !dataUser?.user) {
+ // return Response.json({ message: 'Not logged.', errorUser });
+ // }
+
+ const query = supabase
+ .from('help_requests')
+ .select('id, user_id, latitude, longitude, urgency')
+ .eq('type', 'necesita');
+
+ if (help_type !== null) {
+ query.contains('help_type', [help_type]);
+ }
+ if (urgency !== null) {
+ query.eq('urgency', urgency);
+ }
+
+ query.neq('status', 'finished');
+
+ const { data, error } = await query.order('created_at', { ascending: false });
+
+ if (acepta !== 'todos') {
+ query.contains('accepted_items', [acepta]);
+ }
+
+ if (error) {
+ return Response.json({ error });
+ } else {
+ return Response.json({ data });
+ }
+ return Response.json({ message: 'Error' });
+}
diff --git a/src/app/api/ofertas/route.ts b/src/app/api/ofertas/route.ts
index 3c9b7251..8f3c60dc 100644
--- a/src/app/api/ofertas/route.ts
+++ b/src/app/api/ofertas/route.ts
@@ -1,16 +1,42 @@
-import { createClient } from '@/lib/supabase/server';
+import { NextRequest } from 'next/server';
+import { createServerRoleClient } from '@/lib/supabase/server_role';
-export async function GET() {
- const supabase = await createClient();
- const { data, error } = await supabase.auth.getUser();
- if (error || !data?.user) {
- return Response.json({ message: 'Not logged.', error });
- }
- const email = data.user.email;
- const registeredPost = await supabase
+export async function GET(req: NextRequest) {
+ // Acceder a los parámetros de búsqueda
+ const url = new URL(req.url);
+ const searchParams: any = url.searchParams;
+
+ const help_type = searchParams.get('type');
+ const currentPage = searchParams.get('page') ?? 1;
+ const itemsPerPage = 10;
+
+ const supabase = await createServerRoleClient();
+ // const { data: dataUser, error: errorUser } = await supabase.auth.getUser();
+ // if (errorUser || !dataUser?.user) {
+ // return Response.json({ message: 'Not logged.', errorUser });
+ // }
+
+ const query = supabase
.from('help_requests')
- .select('id')
- .eq('type', 'ofrece')
- .or(`contact_info.ilike.%${email}%,additional_info.cs.${JSON.stringify({ email: email })}`);
- return Response.json({ registeredPost });
+ .select(
+ 'id, created_at,name,location,description,contact_info,additional_info->experience,status,resources,help_type,town_id,other_help',
+ { count: 'exact' },
+ )
+ .eq('type', 'ofrece');
+
+ if (help_type !== null) {
+ query.contains('help_type', [help_type]);
+ }
+
+ query.neq('status', 'finished');
+
+ const { data, count, error } = await query
+ .range((currentPage - 1) * itemsPerPage, currentPage * itemsPerPage - 1)
+ .order('created_at', { ascending: false });
+
+ if (error) {
+ return Response.json({ error });
+ }
+ const countResponse = count ?? 0;
+ return Response.json({ data, count: countResponse });
}
diff --git a/src/app/api/solicitudes/[id]/route.ts b/src/app/api/solicitudes/[id]/route.ts
new file mode 100644
index 00000000..037cb5ef
--- /dev/null
+++ b/src/app/api/solicitudes/[id]/route.ts
@@ -0,0 +1,27 @@
+import { createServerRoleClient } from '@/lib/supabase/server_role';
+import { NextRequest } from 'next/server';
+
+export async function GET(request: NextRequest, { params }: { params: { id: string } }) {
+ const id = params.id;
+
+ const supabase = await createServerRoleClient();
+ // const { data: dataUser, error: errorUser } = await supabase.auth.getUser();
+ // if (errorUser || !dataUser?.user) {
+ // return Response.json({ message: 'Not logged.', errorUser });
+ // }
+
+ const { data, error } = await supabase
+ .from('help_requests')
+ .select(
+ 'id, created_at, name, location, description, urgency, number_of_people, contact_info, additional_info->special_situations, status, resources, latitude, longitude, coordinates, help_type, people_needed, other_help,town_id',
+ { count: 'exact' },
+ )
+ .eq('id', id)
+ .limit(1)
+ .select();
+
+ if (error) {
+ return Response.json({ error });
+ }
+ return Response.json({ data });
+}
diff --git a/src/app/api/solicitudes/route.ts b/src/app/api/solicitudes/route.ts
index 9946c292..92b759d3 100644
--- a/src/app/api/solicitudes/route.ts
+++ b/src/app/api/solicitudes/route.ts
@@ -1,48 +1,52 @@
import { NextRequest } from 'next/server';
import { createServerRoleClient } from '@/lib/supabase/server_role';
- export async function GET(req: NextRequest) {
- // Acceder a los parámetros de búsqueda
- const url = new URL(req.url);
- const searchParams: any = url.searchParams;
-
- const help_type = searchParams.get('type');
- const town_id = searchParams.get('town');
- const urgency = searchParams.get('urgency');
- const currentPage = searchParams.get('page') ?? 1 ;
- const itemsPerPage = 10;
-
- const supabase = await createServerRoleClient();
+export async function GET(req: NextRequest) {
+ // Acceder a los parámetros de búsqueda
+ const url = new URL(req.url);
+ const searchParams: any = url.searchParams;
+
+ const help_type = searchParams.get('type') || null;
+ const town_id = searchParams.get('town') || null;
+ const urgency = searchParams.get('urgency') || null;
+ const currentPage = searchParams.get('page') ?? 1;
+ const itemsPerPage = 10;
+
+ const supabase = await createServerRoleClient();
// const { data: dataUser, error: errorUser } = await supabase.auth.getUser();
// if (errorUser || !dataUser?.user) {
// return Response.json({ message: 'Not logged.', errorUser });
// }
- const query = supabase.from('help_requests').select('id, created_at, name, location, description, urgency, number_of_people, contact_info, additional_info->special_situations, status, resources, help_type, people_needed, other_help', { count: 'exact' }).eq('type', 'necesita');
-
- if (help_type !== null) {
- query.contains('help_type', [help_type]);
- }
-
- if (town_id !== null) {
- query.eq('town_id', town_id);
- }
-
- if (urgency !== null) {
- query.eq('urgency', urgency);
- }
-
- query.neq('status', 'finished');
-
- const { data, count, error } = await query
- .range((currentPage - 1) * itemsPerPage, currentPage * itemsPerPage - 1)
- .order('created_at', { ascending: false });
-
- if (error) {
- return Response.json({error})
- } else {
- const countResponse = count ?? 0;
- return Response.json({data, count: countResponse });
- }
- return Response.json({message: 'Error'});
-}
\ No newline at end of file
+ const query = supabase
+ .from('help_requests')
+ .select(
+ 'id, created_at, name, location, description, urgency, number_of_people, contact_info, additional_info->special_situations, status, resources, latitude, longitude, coordinates, help_type, people_needed, other_help,town_id',
+ { count: 'exact' },
+ )
+ .eq('type', 'necesita');
+
+ if (help_type !== null) {
+ query.contains('help_type', [help_type]);
+ }
+
+ if (town_id !== null) {
+ query.eq('town_id', town_id);
+ }
+
+ if (urgency !== null) {
+ query.eq('urgency', urgency);
+ }
+
+ query.neq('status', 'finished');
+
+ const { data, count, error } = await query
+ .range((currentPage - 1) * itemsPerPage, currentPage * itemsPerPage - 1)
+ .order('created_at', { ascending: false });
+
+ if (error) {
+ return Response.json({ error });
+ }
+ const countResponse = count ?? 0;
+ return Response.json({ data, count: countResponse });
+}
diff --git a/src/app/casos-activos/mapa/page.tsx b/src/app/casos-activos/mapa/page.tsx
index 23822f74..c982913d 100644
--- a/src/app/casos-activos/mapa/page.tsx
+++ b/src/app/casos-activos/mapa/page.tsx
@@ -1,14 +1,11 @@
'use client';
import { useState, useEffect, Suspense } from 'react';
-import { supabase } from '@/lib/supabase/client';
-import SolicitudCard from '@/components/SolicitudCard';
import { useRouter, useSearchParams } from 'next/navigation';
import { tiposAyudaOptions } from '@/helpers/constants';
import Map, { PinMapa } from '@/components/map/map';
import PickupPoint from '@/components/PickupPoint';
-
-export const dynamic = 'force-dynamic';
+import SolicitudCardMap from '@/components/SolicitudCardMap';
export default function MapaPage() {
return (
@@ -55,7 +52,7 @@ function Mapa() {
latitude: request.latitude ?? 0,
longitude: request.longitude ?? 0,
id: request.id,
- popup:
{error}
+