add migration and config for database
This commit is contained in:
parent
a9ca3f59f3
commit
d30e57f006
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue