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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user