Skip to content

Commit d741ce9

Browse files
committed
Improve report processing status handling and user feedback in document processing
1 parent cbc469b commit d741ce9

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

backend/src/document-processor/controllers/document-processor.controller.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,21 +143,31 @@ export class DocumentProcessorController {
143143
throw new BadRequestException(`Report with ID ${reportId} has no associated file`);
144144
}
145145

146-
// Update report status to IN_PROGRESS before starting async processing
147-
report.processingStatus = ProcessingStatus.IN_PROGRESS;
148-
report.updatedAt = new Date().toISOString();
149-
await this.reportsService.updateReport(report);
146+
let message = '';
150147

151-
// Start async processing in background
152-
this.processReportAsync(reportId, userId, report.filePath).catch(error => {
153-
this.logger.error(`Async processing failed for report ${reportId}: ${error.message}`);
154-
});
148+
if (report.processingStatus === ProcessingStatus.IN_PROGRESS) {
149+
message = 'Document processing is already in progress. Please check the report status.';
150+
} else if (report.processingStatus === ProcessingStatus.PROCESSED) {
151+
message = 'Document has already been processed. No further action is needed.';
152+
} else {
153+
message = 'Document processing started. Check the report status to know when it completes.';
154+
155+
// Update report status to IN_PROGRESS before starting async processing
156+
report.processingStatus = ProcessingStatus.IN_PROGRESS;
157+
report.updatedAt = new Date().toISOString();
158+
await this.reportsService.updateReport(report);
159+
160+
// Start async processing in background
161+
this.processReportAsync(reportId, userId, report.filePath).catch(error => {
162+
this.logger.error(`Async processing failed for report ${reportId}: ${error.message}`);
163+
});
164+
}
155165

156166
return {
157167
success: true,
158168
reportId: report.id,
159-
status: ProcessingStatus.IN_PROGRESS,
160-
message: 'Document processing started. Check the report status to know when it completes.',
169+
status: report.processingStatus,
170+
message,
161171
};
162172
} catch (error: unknown) {
163173
this.logger.error(

0 commit comments

Comments
 (0)