Pages corrections pages missions

This commit is contained in:
alma 2026-01-16 14:53:47 +01:00
parent 634266756a
commit 435cf15eed
2 changed files with 40 additions and 16 deletions

View File

@ -64,14 +64,25 @@ export async function POST(
}); });
// Upload using the proven function from mission-uploads.ts // Upload using the proven function from mission-uploads.ts
const uploadResult = await uploadMissionAttachment(userId, missionId, file); let uploadResult;
try {
uploadResult = await uploadMissionAttachment(userId, missionId, file);
console.log(`[POST /api/missions/${missionId}/files/upload] Upload successful:`, { console.log(`[POST /api/missions/${missionId}/files/upload] Upload successful:`, {
filePath: uploadResult.filePath filePath: uploadResult.filePath
}); });
} catch (uploadError: any) {
console.error(`[POST /api/missions/${missionId}/files/upload] Upload failed:`, {
error: uploadError.message,
code: uploadError.Code,
fileName: file.name
});
throw uploadError;
}
// Create attachment record in database // Create attachment record in database
const attachment = await prisma.attachment.create({ let attachment;
try {
attachment = await prisma.attachment.create({
data: { data: {
filename: uploadResult.filename, filename: uploadResult.filename,
filePath: uploadResult.filePath, filePath: uploadResult.filePath,
@ -81,6 +92,17 @@ export async function POST(
uploaderId: userId uploaderId: userId
} }
}); });
console.log(`[POST /api/missions/${missionId}/files/upload] Attachment record created:`, {
attachmentId: attachment.id
});
} catch (dbError: any) {
console.error(`[POST /api/missions/${missionId}/files/upload] Database error:`, {
error: dbError.message,
fileName: file.name
});
// File was uploaded but DB record creation failed - still return success but log the error
// The file exists in S3 even if the DB record doesn't
}
return NextResponse.json({ return NextResponse.json({
success: true, success: true,

View File

@ -96,7 +96,9 @@ export const MissionFilesManager: React.FC<MissionFilesManagerProps> = ({
}); });
if (!response.ok) { if (!response.ok) {
throw new Error('Failed to upload file'); const errorData = await response.json().catch(() => ({}));
const errorMessage = errorData.details || errorData.error || 'Failed to upload file';
throw new Error(errorMessage);
} }
// Refresh file list // Refresh file list