-
Notifications
You must be signed in to change notification settings - Fork 18
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
feature: now only get request from api #171
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,48 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import { createClient } from '@/lib/supabase/server'; | ||
|
||
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 | ||
.from('help_requests') | ||
.select('*') | ||
.eq('type', 'necesita') | ||
.or(`contact_info.ilike.%${email}%,additional_info.cs.${JSON.stringify({ email: email })}`); | ||
return Response.json({ registeredPost }); | ||
} | ||
|
||
export async function POST(request: NextRequest) { | ||
try { | ||
// Obtener los datos del formulario (multipart/form-data) | ||
const formData = await request.formData(); | ||
|
||
// Obtener el ID desde el form-data | ||
const id = formData.get('id'); // Asumiendo que el campo 'id' se llama 'id' | ||
|
||
// Verificar que el ID esté presente | ||
if (!id) { | ||
return NextResponse.json({ error: 'El campo "id" es requerido' }, { status: 400 }); | ||
} | ||
|
||
return NextResponse.json({ | ||
message: 'Datos recibidos correctamente', | ||
id: id, | ||
}); | ||
} catch (error) { | ||
console.error('Error procesando la solicitud:', error); | ||
return NextResponse.json({ error: 'Error al procesar la solicitud' }, { status: 500 }); | ||
} | ||
} | ||
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(); | ||
// 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'}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use server'; | ||
|
||
import { createServerClient } from '@supabase/ssr'; | ||
import { cookies } from 'next/headers'; | ||
import { Database } from '@/types/database'; | ||
|
||
export async function createServerRoleClient() { | ||
const cookieStore = await cookies(); | ||
|
||
return createServerClient<Database>( | ||
process.env.NEXT_PUBLIC_SUPABASE_URL!, | ||
process.env.SUPABASE_SERVICE_ROLE!, | ||
{ | ||
cookies: { | ||
getAll() { | ||
return cookieStore.getAll(); | ||
}, | ||
setAll(cookiesToSet) { | ||
try { | ||
cookiesToSet.forEach(({ name, value, options }) => cookieStore.set(name, value, options)); | ||
} catch { | ||
// The `setAll` method was called from a Server Component. | ||
// This can be ignored if you have middleware refreshing | ||
// user sessions. | ||
} | ||
}, | ||
}, | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,7 @@ export type HelpRequestAdditionalInfo = { | |
special_situations?: string; | ||
email?: string; | ||
}; | ||
|
||
export type CollectionPointType = 'permanente' | 'temporal'; | ||
export type CollectionPointStatus = 'active' | 'inactive'; | ||
export type CollectionPointData = Database['public']['Tables']['collection_points']['Row']; | ||
Comment on lines
+15
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Esto ni siquiera lo puse yo |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Esto esta por si queremos hacer que solo puedan obtener las solicitudes los user auth