diff --git a/src/app/api/applications/route.ts b/src/app/api/applications/route.ts index 51f0dcc4..7c5d2ef7 100644 --- a/src/app/api/applications/route.ts +++ b/src/app/api/applications/route.ts @@ -46,7 +46,7 @@ export async function POST(request: NextRequest) { .from("gigs") .select("poster_id, status, title, poster:profiles!poster_id(full_name, username)") .eq("id", gig_id) - .single(); + .maybeSingle(); if (!gig) { return NextResponse.json({ error: "Gig not found" }, { status: 404 }); @@ -76,7 +76,7 @@ export async function POST(request: NextRequest) { .select("id") .eq("gig_id", gig_id) .eq("applicant_id", user.id) - .single(); + .maybeSingle(); if (existingApplication) { return NextResponse.json( @@ -94,7 +94,7 @@ export async function POST(request: NextRequest) { ...applicationData, }) .select() - .single(); + .maybeSingle(); if (error) { return NextResponse.json({ error: error.message }, { status: 400 }); @@ -121,7 +121,7 @@ export async function POST(request: NextRequest) { .from("profiles") .select("full_name, username") .eq("id", user.id) - .single(); + .maybeSingle(); const applicantName = applicantProfile?.full_name || applicantProfile?.username || "A candidate"; const posterName = poster?.full_name || poster?.username || "there"; diff --git a/src/app/api/conversations/route.ts b/src/app/api/conversations/route.ts index d1c8d2bf..e45099df 100644 --- a/src/app/api/conversations/route.ts +++ b/src/app/api/conversations/route.ts @@ -140,7 +140,7 @@ export async function POST(request: NextRequest) { .from("profiles") .select("id") .eq("id", recipient_id) - .single(); + .maybeSingle(); if (!recipient) { return NextResponse.json( @@ -159,7 +159,7 @@ export async function POST(request: NextRequest) { .from("gigs") .select("id, poster_id") .eq("id", gig_id) - .single(); + .maybeSingle(); if (!gig) { return NextResponse.json({ error: "Gig not found" }, { status: 404 }); @@ -175,7 +175,7 @@ export async function POST(request: NextRequest) { .select("id") .eq("gig_id", gig_id) .eq("applicant_id", user.id) - .single(); + .maybeSingle(); isApplicant = !!application; } @@ -193,7 +193,7 @@ export async function POST(request: NextRequest) { .select("*") .eq("gig_id", gig_id) .contains("participant_ids", participantIds) - .single(); + .maybeSingle(); if (existingConv) { return NextResponse.json({ data: existingConv }); @@ -207,7 +207,7 @@ export async function POST(request: NextRequest) { gig_id, }) .select() - .single(); + .maybeSingle(); if (error) { return NextResponse.json({ error: error.message }, { status: 400 }); @@ -236,7 +236,7 @@ export async function POST(request: NextRequest) { gig_id: null, }) .select() - .single(); + .maybeSingle(); if (error) { return NextResponse.json({ error: error.message }, { status: 400 }); @@ -277,7 +277,7 @@ export async function PATCH(request: NextRequest) { .select("id, participant_ids") .eq("id", conversation_id) .contains("participant_ids", [user.id]) - .single(); + .maybeSingle(); if (!conv) { return NextResponse.json( @@ -293,7 +293,7 @@ export async function PATCH(request: NextRequest) { }) .eq("id", conversation_id) .select() - .single(); + .maybeSingle(); if (error) { return NextResponse.json({ error: error.message }, { status: 400 }); diff --git a/src/app/api/gigs/route.ts b/src/app/api/gigs/route.ts index cd218842..17e782e9 100644 --- a/src/app/api/gigs/route.ts +++ b/src/app/api/gigs/route.ts @@ -73,7 +73,7 @@ export async function GET(request: NextRequest) { ) .eq("status", "active"); - // Apply filters — use textSearch or individual filters to prevent PostgREST filter injection (#71) + // Apply filters �use textSearch or individual filters to prevent PostgREST filter injection (#71) if (search) { // Sanitize: escape PostgREST special chars and SQL wildcards const safeSearch = search @@ -113,7 +113,7 @@ export async function GET(request: NextRequest) { // Default to 'hiring' unless explicitly requesting for_hire or 'all' if (listing_type === "all") { - // No filter — return both types + // No filter �return both types } else if (listing_type) { query = query.eq("listing_type", listing_type); } else { @@ -139,7 +139,7 @@ export async function GET(request: NextRequest) { query = query.order("created_at", { ascending: false }); } - // Apply pagination — ensure non-negative offset (#69) + // Apply pagination �ensure non-negative offset (#69) const offset = Math.max(0, (page - 1) * limit); query = query.range(offset, offset + limit - 1); @@ -222,7 +222,7 @@ export async function POST(request: NextRequest) { .from("subscriptions") .select("plan") .eq("user_id", user.id) - .single(); + .maybeSingle(); if (!subscription || subscription.plan === "free") { const { data: usage } = await supabase @@ -231,7 +231,7 @@ export async function POST(request: NextRequest) { .eq("user_id", user.id) .eq("month", month) .eq("year", year) - .single(); + .maybeSingle(); if (usage && usage.posts_count >= 10) { return NextResponse.json( @@ -254,7 +254,7 @@ export async function POST(request: NextRequest) { ...validationResult.data, }) .select() - .single(); + .maybeSingle(); if (error) { return NextResponse.json({ error: error.message }, { status: 400 }); diff --git a/src/app/api/messages/send/route.ts b/src/app/api/messages/send/route.ts index 5bb068fa..52ced6bf 100644 --- a/src/app/api/messages/send/route.ts +++ b/src/app/api/messages/send/route.ts @@ -43,7 +43,7 @@ export async function POST(request: NextRequest) { .from("profiles") .select("id, full_name, username, last_active_at") .eq("username", recipient) - .single(); + .maybeSingle(); if (recipientError || !recipientProfile) { return NextResponse.json( @@ -67,7 +67,7 @@ export async function POST(request: NextRequest) { .select("id, participant_ids") .is("gig_id", null) .contains("participant_ids", participantIds) - .single(); + .maybeSingle(); let conversationId: string; @@ -82,7 +82,7 @@ export async function POST(request: NextRequest) { gig_id: null, }) .select("id") - .single(); + .maybeSingle(); if (createError || !newConversation) { return NextResponse.json( @@ -114,7 +114,7 @@ export async function POST(request: NextRequest) { ) ` ) - .single(); + .maybeSingle(); if (messageError || !message) { return NextResponse.json( @@ -134,7 +134,7 @@ export async function POST(request: NextRequest) { .from("profiles") .select("full_name, username") .eq("id", user.id) - .single(); + .maybeSingle(); const senderName = senderProfile?.full_name || senderProfile?.username || "Someone"; diff --git a/src/app/api/profile/route.ts b/src/app/api/profile/route.ts index e7b030c4..253f71ea 100644 --- a/src/app/api/profile/route.ts +++ b/src/app/api/profile/route.ts @@ -18,9 +18,9 @@ export async function GET(request: NextRequest) { .from("profiles") .select("*") .eq("id", user.id) - .single(); + .maybeSingle(); - if (error) { + if (error || !profile) { return NextResponse.json({ error: error.message }, { status: 400 }); } @@ -100,7 +100,7 @@ export async function PUT(request: NextRequest) { .from("profiles") .select("did, resume_url") .eq("id", user.id) - .single(); + .maybeSingle(); // Check if profile is complete const isComplete = Boolean( @@ -120,9 +120,9 @@ export async function PUT(request: NextRequest) { .update(updateData) .eq("id", user.id) .select() - .single(); + .maybeSingle(); - if (error) { + if (error || !profile) { console.error("Profile update error:", error); console.error("Error details:", JSON.stringify(error, null, 2)); return NextResponse.json({ error: error.message }, { status: 400 });