fix: improve error handling in API routes and update date handling for OKR and Key Result submissions
Some checks failed
Deploy with Docker Compose / deploy (push) Failing after 3m38s
Some checks failed
Deploy with Docker Compose / deploy (push) Failing after 3m38s
This commit is contained in:
@@ -49,10 +49,11 @@ export async function PATCH(
|
||||
const updated = await updateKeyResult(krId, Number(currentValue), notes || null);
|
||||
|
||||
return NextResponse.json(updated);
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
console.error('Error updating key result:', error);
|
||||
const errorMessage = error instanceof Error ? error.message : 'Erreur lors de la mise à jour du Key Result';
|
||||
return NextResponse.json(
|
||||
{ error: error.message || 'Erreur lors de la mise à jour du Key Result' },
|
||||
{ error: errorMessage },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -90,20 +90,21 @@ export async function PATCH(request: Request, { params }: { params: Promise<{ id
|
||||
// Remove keyResultsUpdates from updateData as it's not part of UpdateOKRInput
|
||||
const { keyResultsUpdates, ...okrUpdateData } = body;
|
||||
const finalUpdateData: UpdateOKRInput = { ...okrUpdateData };
|
||||
if (finalUpdateData.startDate) {
|
||||
finalUpdateData.startDate = new Date(finalUpdateData.startDate as any);
|
||||
if (finalUpdateData.startDate && typeof finalUpdateData.startDate === 'string') {
|
||||
finalUpdateData.startDate = new Date(finalUpdateData.startDate);
|
||||
}
|
||||
if (finalUpdateData.endDate) {
|
||||
finalUpdateData.endDate = new Date(finalUpdateData.endDate as any);
|
||||
if (finalUpdateData.endDate && typeof finalUpdateData.endDate === 'string') {
|
||||
finalUpdateData.endDate = new Date(finalUpdateData.endDate);
|
||||
}
|
||||
|
||||
const updated = await updateOKR(id, finalUpdateData, keyResultsUpdates);
|
||||
|
||||
return NextResponse.json(updated);
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
console.error('Error updating OKR:', error);
|
||||
const errorMessage = error instanceof Error ? error.message : 'Erreur lors de la mise à jour de l\'OKR';
|
||||
return NextResponse.json(
|
||||
{ error: error.message || 'Erreur lors de la mise à jour de l\'OKR' },
|
||||
{ error: errorMessage },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
@@ -132,10 +133,11 @@ export async function DELETE(request: Request, { params }: { params: Promise<{ i
|
||||
await deleteOKR(id);
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
console.error('Error deleting OKR:', error);
|
||||
const errorMessage = error instanceof Error ? error.message : 'Erreur lors de la suppression de l\'OKR';
|
||||
return NextResponse.json(
|
||||
{ error: error.message || 'Erreur lors de la suppression de l\'OKR' },
|
||||
{ error: errorMessage },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user