Pages corrections pages missions
This commit is contained in:
parent
634266756a
commit
435cf15eed
@ -64,23 +64,45 @@ export async function POST(
|
||||
});
|
||||
|
||||
// Upload using the proven function from mission-uploads.ts
|
||||
const uploadResult = await uploadMissionAttachment(userId, missionId, file);
|
||||
|
||||
console.log(`[POST /api/missions/${missionId}/files/upload] Upload successful:`, {
|
||||
filePath: uploadResult.filePath
|
||||
});
|
||||
let uploadResult;
|
||||
try {
|
||||
uploadResult = await uploadMissionAttachment(userId, missionId, file);
|
||||
console.log(`[POST /api/missions/${missionId}/files/upload] Upload successful:`, {
|
||||
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
|
||||
const attachment = await prisma.attachment.create({
|
||||
data: {
|
||||
filename: uploadResult.filename,
|
||||
filePath: uploadResult.filePath,
|
||||
fileType: uploadResult.fileType,
|
||||
fileSize: uploadResult.fileSize,
|
||||
missionId: missionId,
|
||||
uploaderId: userId
|
||||
}
|
||||
});
|
||||
let attachment;
|
||||
try {
|
||||
attachment = await prisma.attachment.create({
|
||||
data: {
|
||||
filename: uploadResult.filename,
|
||||
filePath: uploadResult.filePath,
|
||||
fileType: uploadResult.fileType,
|
||||
fileSize: uploadResult.fileSize,
|
||||
missionId: missionId,
|
||||
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({
|
||||
success: true,
|
||||
|
||||
@ -96,7 +96,9 @@ export const MissionFilesManager: React.FC<MissionFilesManagerProps> = ({
|
||||
});
|
||||
|
||||
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user