From d30e57f006715e6f212496a16b32d85d5379bb67 Mon Sep 17 00:00:00 2001 From: esteban Date: Thu, 6 Aug 2026 19:54:50 -0500 Subject: [PATCH] add migration and config for database --- .gitignore | 4 ++++ package.json | 5 ++++- src/pages/api/emailPostulacion/send.ts | 17 +++++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 1bf6fd4..dd06050 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,7 @@ prisma/dev.db opencode/ .opencode/ docs/ + +# scripts de migración (locales, no en producción) +scripts/migrate-sheets-to-db.ts +scripts/seed-form-config.ts diff --git a/package.json b/package.json index 9d34b4c..ebab4fd 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,10 @@ "build": "astro build", "postbuild": "node scripts/send-to-n8n.js", "preview": "astro preview", - "astro": "astro" + "astro": "astro", + "db:migrate-sheets": "npx tsx scripts/migrate-sheets-to-db.ts", + "db:seed-form-config": "npx tsx scripts/seed-form-config.ts", + "db:setup": "npx tsx scripts/seed-form-config.ts && npx tsx scripts/migrate-sheets-to-db.ts" }, "dependencies": { "@astrojs/markdoc": "^2.0.3", diff --git a/src/pages/api/emailPostulacion/send.ts b/src/pages/api/emailPostulacion/send.ts index 0e3d154..d89e270 100644 --- a/src/pages/api/emailPostulacion/send.ts +++ b/src/pages/api/emailPostulacion/send.ts @@ -1,6 +1,7 @@ import type { APIRoute } from "astro"; import { appendToSheet, emailExists } from "../lib/googleSheets"; import { sendEmailCf } from "../lib/email"; +import { prisma } from "../lib/prisma"; export const prerender = false; export const POST: APIRoute = async ({ request }) => { @@ -41,10 +42,22 @@ export const POST: APIRoute = async ({ request }) => { new Date().toLocaleString() ]; - // 🔹 Enviar correo (Cloudflare) y guardar en Google Sheets + // 🔹 Enviar correo (Cloudflare), guardar en Google Sheets y en PostgreSQL await Promise.all([ sendEmailCf({ nombres, apellidos }, email, "CENTRO_DEL_REINO_PAZ_Y_JUSTICIA_POSTULACION"), - appendToSheet(valuesForSheets) + appendToSheet(valuesForSheets), + prisma.formulario.create({ + data: { + nombre: nombres!, + apellido: apellidos!, + pais: pais || null, + ciudad: lugar || null, + direccion: direccion || null, + telefono: telefono || null, + correo: email!, + status: "legacy", + }, + }), ]); // 🔹 Redirección elegante después de enviar