|
|
@@ -3,14 +3,19 @@ import { PrismaClient } from '@prisma/client'
|
|
|
|
|
|
const prisma = new PrismaClient()
|
|
|
|
|
|
+type RouteParams = {
|
|
|
+ params: Promise<{ id: string }>
|
|
|
+}
|
|
|
+
|
|
|
// GET - Obtener un cliente por ID
|
|
|
export async function GET(
|
|
|
request: NextRequest,
|
|
|
- { params }: { params: { id: string } }
|
|
|
+ { params }: RouteParams
|
|
|
) {
|
|
|
try {
|
|
|
+ const { id } = await params
|
|
|
const cliente = await prisma.cliente.findUnique({
|
|
|
- where: { id: params.id }
|
|
|
+ where: { id }
|
|
|
})
|
|
|
|
|
|
if (!cliente) {
|
|
|
@@ -33,13 +38,14 @@ export async function GET(
|
|
|
// PUT - Actualizar cliente
|
|
|
export async function PUT(
|
|
|
request: NextRequest,
|
|
|
- { params }: { params: { id: string } }
|
|
|
+ { params }: RouteParams
|
|
|
) {
|
|
|
try {
|
|
|
+ const { id } = await params
|
|
|
const body = await request.json()
|
|
|
|
|
|
const cliente = await prisma.cliente.update({
|
|
|
- where: { id: params.id },
|
|
|
+ where: { id },
|
|
|
data: {
|
|
|
tipoIdentificacion: body.tipoIdentificacion,
|
|
|
identificacion: body.identificacion,
|
|
|
@@ -64,11 +70,12 @@ export async function PUT(
|
|
|
// DELETE - Eliminar cliente
|
|
|
export async function DELETE(
|
|
|
request: NextRequest,
|
|
|
- { params }: { params: { id: string } }
|
|
|
+ { params }: RouteParams
|
|
|
) {
|
|
|
try {
|
|
|
+ const { id } = await params
|
|
|
await prisma.cliente.delete({
|
|
|
- where: { id: params.id }
|
|
|
+ where: { id }
|
|
|
})
|
|
|
|
|
|
return NextResponse.json({ success: true })
|