feat: translate API error messages to English
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -12,7 +12,7 @@ interface RouteContext {
|
||||
// Validation schema for payment
|
||||
const paymentSchema = z.object({
|
||||
paymentType: z.enum(['CASH', 'CARD', 'TRANSFER', 'MEMBERSHIP', 'FREE']),
|
||||
amount: z.number().positive('El monto debe ser mayor a 0').optional(),
|
||||
amount: z.number().positive('Amount must be greater than 0').optional(),
|
||||
reference: z.string().max(100).optional(),
|
||||
notes: z.string().max(500).optional(),
|
||||
cashRegisterId: z.string().uuid().optional(),
|
||||
@@ -28,7 +28,7 @@ export async function POST(
|
||||
|
||||
if (!session?.user) {
|
||||
return NextResponse.json(
|
||||
{ error: 'No autorizado' },
|
||||
{ error: 'Unauthorized' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
@@ -51,7 +51,7 @@ export async function POST(
|
||||
|
||||
if (!existingBooking) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Reserva no encontrada' },
|
||||
{ error: 'Booking not found' },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
@@ -59,7 +59,7 @@ export async function POST(
|
||||
// If user is SITE_ADMIN, verify they have access to this site
|
||||
if (session.user.role === 'SITE_ADMIN' && session.user.siteId !== existingBooking.siteId) {
|
||||
return NextResponse.json(
|
||||
{ error: 'No tiene permiso para procesar pagos en esta reserva' },
|
||||
{ error: 'You do not have permission to process payments for this booking' },
|
||||
{ status: 403 }
|
||||
);
|
||||
}
|
||||
@@ -67,7 +67,7 @@ export async function POST(
|
||||
// Check if booking is already cancelled
|
||||
if (existingBooking.status === 'CANCELLED') {
|
||||
return NextResponse.json(
|
||||
{ error: 'No se puede procesar el pago de una reserva cancelada' },
|
||||
{ error: 'Cannot process payment for a cancelled booking' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
@@ -81,7 +81,7 @@ export async function POST(
|
||||
|
||||
if (totalPaid >= totalPrice) {
|
||||
return NextResponse.json(
|
||||
{ error: 'La reserva ya está completamente pagada' },
|
||||
{ error: 'The booking is already fully paid' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
@@ -93,7 +93,7 @@ export async function POST(
|
||||
if (!validationResult.success) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: 'Datos de pago inválidos',
|
||||
error: 'Invalid payment data',
|
||||
details: validationResult.error.flatten().fieldErrors,
|
||||
},
|
||||
{ status: 400 }
|
||||
@@ -108,7 +108,7 @@ export async function POST(
|
||||
|
||||
if (paymentAmount <= 0) {
|
||||
return NextResponse.json(
|
||||
{ error: 'El monto del pago debe ser mayor a 0' },
|
||||
{ error: 'Payment amount must be greater than 0' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
@@ -125,7 +125,7 @@ export async function POST(
|
||||
|
||||
if (!cashRegister) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Caja registradora no encontrada o no está abierta' },
|
||||
{ error: 'Cash register not found or is not open' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
@@ -211,8 +211,8 @@ export async function POST(
|
||||
|
||||
return NextResponse.json({
|
||||
message: result.isFullyPaid
|
||||
? 'Pago completado. La reserva ha sido confirmada.'
|
||||
: 'Pago parcial registrado exitosamente.',
|
||||
? 'Payment completed. The booking has been confirmed.'
|
||||
: 'Partial payment recorded successfully.',
|
||||
booking: result.booking,
|
||||
payment: result.payment,
|
||||
remainingAmount: Math.max(0, totalPrice - (totalPaid + paymentAmount)),
|
||||
@@ -220,7 +220,7 @@ export async function POST(
|
||||
} catch (error) {
|
||||
console.error('Error processing payment:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Error al procesar el pago' },
|
||||
{ error: 'Error processing payment' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ export async function GET(
|
||||
|
||||
if (!session?.user) {
|
||||
return NextResponse.json(
|
||||
{ error: 'No autorizado' },
|
||||
{ error: 'Unauthorized' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
@@ -99,7 +99,7 @@ export async function GET(
|
||||
|
||||
if (!booking) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Reserva no encontrada' },
|
||||
{ error: 'Booking not found' },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
@@ -108,7 +108,7 @@ export async function GET(
|
||||
} catch (error) {
|
||||
console.error('Error fetching booking:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Error al obtener la reserva' },
|
||||
{ error: 'Error fetching booking' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
@@ -124,7 +124,7 @@ export async function PUT(
|
||||
|
||||
if (!session?.user) {
|
||||
return NextResponse.json(
|
||||
{ error: 'No autorizado' },
|
||||
{ error: 'Unauthorized' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
@@ -146,7 +146,7 @@ export async function PUT(
|
||||
|
||||
if (!existingBooking) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Reserva no encontrada' },
|
||||
{ error: 'Booking not found' },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
@@ -154,7 +154,7 @@ export async function PUT(
|
||||
// If user is SITE_ADMIN, verify they have access to this site
|
||||
if (session.user.role === 'SITE_ADMIN' && session.user.siteId !== existingBooking.siteId) {
|
||||
return NextResponse.json(
|
||||
{ error: 'No tiene permiso para modificar esta reserva' },
|
||||
{ error: 'You do not have permission to modify this booking' },
|
||||
{ status: 403 }
|
||||
);
|
||||
}
|
||||
@@ -166,7 +166,7 @@ export async function PUT(
|
||||
if (!validationResult.success) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: 'Datos de actualización inválidos',
|
||||
error: 'Invalid update data',
|
||||
details: validationResult.error.flatten().fieldErrors,
|
||||
},
|
||||
{ status: 400 }
|
||||
@@ -239,7 +239,7 @@ export async function PUT(
|
||||
} catch (error) {
|
||||
console.error('Error updating booking:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Error al actualizar la reserva' },
|
||||
{ error: 'Error updating booking' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
@@ -255,7 +255,7 @@ export async function DELETE(
|
||||
|
||||
if (!session?.user) {
|
||||
return NextResponse.json(
|
||||
{ error: 'No autorizado' },
|
||||
{ error: 'Unauthorized' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
@@ -277,7 +277,7 @@ export async function DELETE(
|
||||
|
||||
if (!existingBooking) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Reserva no encontrada' },
|
||||
{ error: 'Booking not found' },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
@@ -285,7 +285,7 @@ export async function DELETE(
|
||||
// If user is SITE_ADMIN, verify they have access to this site
|
||||
if (session.user.role === 'SITE_ADMIN' && session.user.siteId !== existingBooking.siteId) {
|
||||
return NextResponse.json(
|
||||
{ error: 'No tiene permiso para cancelar esta reserva' },
|
||||
{ error: 'You do not have permission to cancel this booking' },
|
||||
{ status: 403 }
|
||||
);
|
||||
}
|
||||
@@ -294,7 +294,7 @@ export async function DELETE(
|
||||
const hasPayments = existingBooking.payments.length > 0;
|
||||
|
||||
// Parse optional cancel reason from query params or body
|
||||
let cancelReason = 'Cancelada por el administrador';
|
||||
let cancelReason = 'Cancelled by administrator';
|
||||
try {
|
||||
const body = await request.json();
|
||||
if (body.cancelReason) {
|
||||
@@ -316,9 +316,9 @@ export async function DELETE(
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
message: 'Reserva cancelada exitosamente',
|
||||
message: 'Booking cancelled successfully',
|
||||
booking,
|
||||
note: 'La reserva tiene pagos asociados, por lo que fue cancelada en lugar de eliminada',
|
||||
note: 'The booking has associated payments, so it was cancelled instead of deleted',
|
||||
});
|
||||
} else {
|
||||
// If no payments, allow hard delete for pending bookings only
|
||||
@@ -328,7 +328,7 @@ export async function DELETE(
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
message: 'Reserva eliminada exitosamente',
|
||||
message: 'Booking deleted successfully',
|
||||
});
|
||||
} else {
|
||||
// For non-pending bookings, soft delete
|
||||
@@ -342,7 +342,7 @@ export async function DELETE(
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
message: 'Reserva cancelada exitosamente',
|
||||
message: 'Booking cancelled successfully',
|
||||
booking,
|
||||
});
|
||||
}
|
||||
@@ -350,7 +350,7 @@ export async function DELETE(
|
||||
} catch (error) {
|
||||
console.error('Error deleting booking:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Error al cancelar la reserva' },
|
||||
{ error: 'Error cancelling booking' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user