@@ -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