crypto-commons-gather.ing-w.../app/api/register/route.ts

55 lines
1.5 KiB
TypeScript

import { type NextRequest, NextResponse } from "next/server"
import { addRegistration, initializeSheetHeaders } from "@/lib/google-sheets"
export async function POST(request: NextRequest) {
try {
const body = await request.json()
const { name, email, contact, contributions, expectations, howHeard, dietary, crewConsent } = body
// Validate required fields
if (!name || !email || !contact || !contributions || !expectations || !crewConsent) {
return NextResponse.json(
{ error: "Missing required fields" },
{ status: 400 }
)
}
// Initialize headers if needed (first registration)
await initializeSheetHeaders()
// Add registration to Google Sheet
const rowNumber = await addRegistration({
name,
email,
contact,
contributions,
expectations,
howHeard: howHeard || "",
dietary: Array.isArray(dietary) ? dietary.join(", ") : dietary || "",
crewConsent,
})
console.log(`[Register API] Registration added for ${name} at row ${rowNumber}`)
return NextResponse.json({
success: true,
message: "Registration recorded",
rowNumber,
})
} catch (error) {
console.error("[Register API] Error:", error)
return NextResponse.json(
{ error: "Failed to record registration" },
{ status: 500 }
)
}
}
export async function GET() {
return NextResponse.json(
{ message: "Use POST to submit registration" },
{ status: 405 }
)
}