Add API endpoint for purchasing tickets with Supabase integration
This commit is contained in:
parent
0c1a2e3ae8
commit
b846835124
ventaboletos/src/pages/api
|
@ -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" });
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue