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 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -28,10 +28,11 @@ export async function POST(request: Request, { params }: { params: Promise<{ id:
|
||||
const member = await addTeamMember(id, userId, role || 'MEMBER');
|
||||
|
||||
return NextResponse.json(member, { status: 201 });
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
console.error('Error adding team member:', error);
|
||||
const errorMessage = error instanceof Error ? error.message : 'Erreur lors de l\'ajout du membre';
|
||||
return NextResponse.json(
|
||||
{ error: error.message || 'Erreur lors de l\'ajout du membre' },
|
||||
{ error: errorMessage },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,23 @@ export default function EditOKRPage() {
|
||||
});
|
||||
}, [okrId, teamId]);
|
||||
|
||||
const handleSubmit = async (data: CreateOKRInput & { keyResultsUpdates?: { create?: any[]; update?: any[]; delete?: string[] } }) => {
|
||||
type KeyResultUpdate = {
|
||||
id: string;
|
||||
title?: string;
|
||||
targetValue?: number;
|
||||
unit?: string;
|
||||
order?: number;
|
||||
};
|
||||
|
||||
const handleSubmit = async (data: CreateOKRInput & {
|
||||
startDate: Date | string;
|
||||
endDate: Date | string;
|
||||
keyResultsUpdates?: {
|
||||
create?: Array<{ title: string; targetValue: number; unit: string; order: number }>;
|
||||
update?: KeyResultUpdate[];
|
||||
delete?: string[]
|
||||
}
|
||||
}) => {
|
||||
// Convert to UpdateOKRInput format
|
||||
const updateData = {
|
||||
objective: data.objective,
|
||||
@@ -64,7 +80,18 @@ export default function EditOKRPage() {
|
||||
endDate: typeof data.endDate === 'string' ? new Date(data.endDate) : data.endDate,
|
||||
};
|
||||
|
||||
const payload: any = {
|
||||
const payload: {
|
||||
objective: string;
|
||||
description?: string;
|
||||
period: string;
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
keyResultsUpdates?: {
|
||||
create?: Array<{ title: string; targetValue: number; unit: string; order: number }>;
|
||||
update?: KeyResultUpdate[];
|
||||
delete?: string[];
|
||||
};
|
||||
} = {
|
||||
...updateData,
|
||||
startDate: updateData.startDate.toISOString(),
|
||||
endDate: updateData.endDate.toISOString(),
|
||||
@@ -83,7 +110,7 @@ export default function EditOKRPage() {
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json();
|
||||
throw new Error(error.error || 'Erreur lors de la mise à jour de l\'OKR');
|
||||
throw new Error(error.error || 'Erreur lors de la mise à jour de l'OKR');
|
||||
}
|
||||
|
||||
router.push(`/teams/${teamId}/okrs/${okrId}`);
|
||||
@@ -121,12 +148,12 @@ export default function EditOKRPage() {
|
||||
<main className="mx-auto max-w-4xl px-4 py-8">
|
||||
<div className="mb-6">
|
||||
<Link href={`/teams/${teamId}/okrs/${okrId}`} className="text-muted hover:text-foreground">
|
||||
← Retour à l'OKR
|
||||
← Retour à l'OKR
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<Card className="p-6">
|
||||
<h1 className="text-2xl font-bold text-foreground mb-6">Modifier l'OKR</h1>
|
||||
<h1 className="text-2xl font-bold text-foreground mb-6">Modifier l'OKR</h1>
|
||||
<OKRForm
|
||||
teamMembers={teamMembers}
|
||||
onSubmit={handleSubmit}
|
||||
|
||||
@@ -148,7 +148,7 @@ export default function OKRDetailPage() {
|
||||
<main className="mx-auto max-w-4xl px-4 py-8">
|
||||
<div className="mb-6">
|
||||
<Link href={`/teams/${teamId}`} className="text-muted hover:text-foreground">
|
||||
← Retour à l'équipe
|
||||
← Retour à l'équipe
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ export default function NewOKRPage() {
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json();
|
||||
throw new Error(error.error || 'Erreur lors de la création de l\'OKR');
|
||||
throw new Error(error.error || 'Erreur lors de la création de l'OKR');
|
||||
}
|
||||
|
||||
router.push(`/teams/${teamId}`);
|
||||
@@ -64,7 +64,7 @@ export default function NewOKRPage() {
|
||||
<main className="mx-auto max-w-4xl px-4 py-8">
|
||||
<div className="mb-6">
|
||||
<Link href={`/teams/${teamId}`} className="text-muted hover:text-foreground">
|
||||
← Retour à l'équipe
|
||||
← Retour à l'équipe
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user