feat: integración Google Sheets al completar turno
Deploy / deploy (push) Failing after 11m51s

Cuando el admin marca un turno como COMPLETADO escribe una fila
en el sheet con patente, km, auto, cliente, fecha y trabajo.
Auth via service account con JWT nativo (sin googleapis).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Beldor
2026-06-22 17:38:14 -03:00
parent 4d259558c6
commit e556e2f16b
4 changed files with 442 additions and 52 deletions
+22
View File
@@ -1,6 +1,7 @@
import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
import { verificarSesion } from "@/lib/auth-admin";
import { agregarFilaSheet } from "@/lib/google-sheets";
export async function PATCH(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
const sesion = await verificarSesion("admin_session");
@@ -15,5 +16,26 @@ export async function PATCH(req: NextRequest, { params }: { params: Promise<{ id
include: { auto: true, tipoServicio: true, cliente: true },
});
if (estado === "COMPLETADO") {
try {
await agregarFilaSheet({
patente: turno.auto.patente,
kilometros: turno.kilometros,
marca: turno.auto.marca,
modelo: turno.auto.modelo,
anio: turno.auto.anio,
nroChasis: turno.auto.nroChasis,
nombre: turno.cliente.nombre,
apellido: turno.cliente.apellido,
email: turno.cliente.email,
telefono: turno.cliente.telefono,
fecha: turno.fechaInicio,
trabajo: turno.tipoServicio.nombre,
});
} catch (err) {
console.error("Error escribiendo en Google Sheet:", err);
}
}
return NextResponse.json(turno);
}