feat: translate API error messages to English
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -10,11 +10,11 @@ interface RouteContext {
|
||||
|
||||
// Validation schema for updating client
|
||||
const updateClientSchema = z.object({
|
||||
firstName: z.string().min(1, 'El nombre es requerido').optional(),
|
||||
lastName: z.string().min(1, 'El apellido es requerido').optional(),
|
||||
email: z.string().email('Email invalido').nullable().optional(),
|
||||
firstName: z.string().min(1, 'First name is required').optional(),
|
||||
lastName: z.string().min(1, 'Last name is required').optional(),
|
||||
email: z.string().email('Invalid email').nullable().optional(),
|
||||
phone: z.string().nullable().optional(),
|
||||
avatar: z.string().url('URL invalida').nullable().optional(),
|
||||
avatar: z.string().url('Invalid URL').nullable().optional(),
|
||||
dateOfBirth: z.string().nullable().optional(),
|
||||
address: z.string().nullable().optional(),
|
||||
notes: z.string().nullable().optional(),
|
||||
@@ -32,7 +32,7 @@ export async function GET(
|
||||
|
||||
if (!session?.user) {
|
||||
return NextResponse.json(
|
||||
{ error: 'No autorizado' },
|
||||
{ error: 'Unauthorized' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
@@ -79,7 +79,7 @@ export async function GET(
|
||||
|
||||
if (!client) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Cliente no encontrado' },
|
||||
{ error: 'Client not found' },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
@@ -122,7 +122,7 @@ export async function GET(
|
||||
} catch (error) {
|
||||
console.error('Error fetching client:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Error al obtener el cliente' },
|
||||
{ error: 'Error fetching client' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
@@ -138,7 +138,7 @@ export async function PUT(
|
||||
|
||||
if (!session?.user) {
|
||||
return NextResponse.json(
|
||||
{ error: 'No autorizado' },
|
||||
{ error: 'Unauthorized' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
@@ -155,7 +155,7 @@ export async function PUT(
|
||||
|
||||
if (!existingClient) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Cliente no encontrado' },
|
||||
{ error: 'Client not found' },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
@@ -167,7 +167,7 @@ export async function PUT(
|
||||
if (!validationResult.success) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: 'Datos de actualizacion invalidos',
|
||||
error: 'Invalid update data',
|
||||
details: validationResult.error.flatten().fieldErrors,
|
||||
},
|
||||
{ status: 400 }
|
||||
@@ -201,7 +201,7 @@ export async function PUT(
|
||||
|
||||
if (emailExists) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Ya existe un cliente con este email' },
|
||||
{ error: 'A client with this email already exists' },
|
||||
{ status: 409 }
|
||||
);
|
||||
}
|
||||
@@ -262,13 +262,13 @@ export async function PUT(
|
||||
// Check for unique constraint violation
|
||||
if (error instanceof Error && error.message.includes('Unique constraint')) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Ya existe un cliente con este email o DNI' },
|
||||
{ error: 'A client with this email or ID number already exists' },
|
||||
{ status: 409 }
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: 'Error al actualizar el cliente' },
|
||||
{ error: 'Error updating client' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
@@ -284,7 +284,7 @@ export async function DELETE(
|
||||
|
||||
if (!session?.user) {
|
||||
return NextResponse.json(
|
||||
{ error: 'No autorizado' },
|
||||
{ error: 'Unauthorized' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
@@ -318,7 +318,7 @@ export async function DELETE(
|
||||
|
||||
if (!existingClient) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Cliente no encontrado' },
|
||||
{ error: 'Client not found' },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
@@ -327,7 +327,7 @@ export async function DELETE(
|
||||
if (existingClient.memberships.length > 0) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: 'No se puede desactivar un cliente con membresia activa',
|
||||
error: 'Cannot deactivate a client with an active membership',
|
||||
details: {
|
||||
activeMemberships: existingClient.memberships.length,
|
||||
},
|
||||
@@ -340,7 +340,7 @@ export async function DELETE(
|
||||
if (existingClient.bookings.length > 0) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: 'No se puede desactivar un cliente con reservas pendientes',
|
||||
error: 'Cannot deactivate a client with pending bookings',
|
||||
details: {
|
||||
pendingBookings: existingClient.bookings.length,
|
||||
},
|
||||
@@ -364,13 +364,13 @@ export async function DELETE(
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
message: 'Cliente desactivado exitosamente',
|
||||
message: 'Client deactivated successfully',
|
||||
client,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error deleting client:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Error al desactivar el cliente' },
|
||||
{ error: 'Error deactivating client' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ export async function GET(request: NextRequest) {
|
||||
|
||||
if (!session?.user) {
|
||||
return NextResponse.json(
|
||||
{ error: 'No autorizado' },
|
||||
{ error: 'Unauthorized' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
@@ -123,7 +123,7 @@ export async function GET(request: NextRequest) {
|
||||
} catch (error) {
|
||||
console.error('Error fetching clients:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Error al obtener los clientes' },
|
||||
{ error: 'Error fetching clients' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
@@ -136,7 +136,7 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
if (!session?.user) {
|
||||
return NextResponse.json(
|
||||
{ error: 'No autorizado' },
|
||||
{ error: 'Unauthorized' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
@@ -148,7 +148,7 @@ export async function POST(request: NextRequest) {
|
||||
if (!validationResult.success) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: 'Datos del cliente inválidos',
|
||||
error: 'Invalid client data',
|
||||
details: validationResult.error.flatten().fieldErrors,
|
||||
},
|
||||
{ status: 400 }
|
||||
@@ -181,7 +181,7 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
if (existingClient) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Ya existe un cliente con este correo electrónico en su organización' },
|
||||
{ error: 'A client with this email already exists in your organization' },
|
||||
{ status: 409 }
|
||||
);
|
||||
}
|
||||
@@ -224,13 +224,13 @@ export async function POST(request: NextRequest) {
|
||||
// Check for unique constraint violation
|
||||
if (error instanceof Error && error.message.includes('Unique constraint')) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Ya existe un cliente con este correo electrónico o DNI' },
|
||||
{ error: 'A client with this email or ID number already exists' },
|
||||
{ status: 409 }
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: 'Error al crear el cliente' },
|
||||
{ error: 'Error creating client' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user