Add API endpoint for purchasing tickets with Supabase integration

This commit is contained in:
Benito 2025-03-10 09:12:28 -06:00
parent 0c1a2e3ae8
commit b846835124
1 changed files with 24 additions and 0 deletions
ventaboletos/src/pages/api

View File

@ -0,0 +1,24 @@
import { supabaseClient } from "@/utils/supabase";
export default async function handler(req, res) {
if (req.method === "POST") {
const { boletos } = req.body;
try {
const { data, error } = await supabaseClient
.from("boletos_comprados")
.insert(boletos);
if (error) {
throw error;
}
res.status(200).json({ message: "Compra realizada con éxito", data });
} catch (error) {
console.error("Error al insertar boletos:", error);
res.status(500).json({ message: "Error al procesar la compra", error });
}
} else {
res.status(405).json({ message: "Método no permitido" });
}
}