Browse Source

refactor(excel-import): remove status field updates from import processor

Removed all database status field updates from the import processor since the Import model no longer has a status field. The processor now focuses solely on data processing without managing import state.

- Removed PROCESSING, COMPLETED, and FAILED status updates
- Added Buffer.from() wrapper for file data conversion
- Updated ExcelImportConfig type with proper layout configuration structure
vtugulan 6 months ago
parent
commit
d5a1c10629
2 changed files with 25 additions and 25 deletions
  1. 3 24
      app/lib/excel-import/import-processor.ts
  2. 22 1
      app/lib/excel-import/types.ts

+ 3 - 24
app/lib/excel-import/import-processor.ts

@@ -38,12 +38,6 @@ export class ImportProcessor {
         throw new Error('Import not found or no file attached');
       }
 
-      // Update import status to processing
-      await this.prisma.import.update({
-        where: { id: importId },
-        data: { status: 'PROCESSING' }
-      });
-
       // Initialize progress tracking
       const progress: ImportProgress = {
         importId,
@@ -58,7 +52,7 @@ export class ImportProcessor {
 
       // Read Excel file
       const sections = await this.reader.readExcelFile(
-        importRecord.file.data,
+        Buffer.from(importRecord.file.data),
         importRecord.layout,
         (sectionProgress) => {
           this.progressServer.broadcastProgress(importId, sectionProgress);
@@ -100,14 +94,7 @@ export class ImportProcessor {
         }
       }
 
-      // Update import status to completed
-      await this.prisma.import.update({
-        where: { id: importId },
-        data: { 
-          status: 'COMPLETED',
-          processedAt: new Date()
-        }
-      });
+      // Import processing completed - no status field to update
 
       progress.status = 'completed';
       this.progressServer.broadcastProgress(importId, progress);
@@ -119,15 +106,7 @@ export class ImportProcessor {
       };
 
     } catch (error) {
-      // Update import status to failed
-      await this.prisma.import.update({
-        where: { id: importId },
-        data: { 
-          status: 'FAILED',
-          error: error instanceof Error ? error.message : 'Unknown error',
-          processedAt: new Date()
-        }
-      });
+      // Import processing failed - no status field to update
 
       const progress: ImportProgress = {
         importId,

+ 22 - 1
app/lib/excel-import/types.ts

@@ -51,7 +51,28 @@ export interface ImportProgress {
 
 export interface ExcelImportConfig {
   fileBuffer: Buffer;
-  layoutConfiguration: any;
+  layoutConfiguration: {
+    id: number;
+    name: string;
+    sections: Array<{
+      id: number;
+      name: string;
+      type: string;
+      sheetName: string;
+      startingRow?: number;
+      endingRow?: number;
+      tableName: string;
+      fields: Array<{
+        id: number;
+        cellPosition: string;
+        name: string;
+        dataType: string;
+        dataTypeFormat?: string;
+        importTableColumnName: string;
+        importColumnOrderNumber: number;
+      }>;
+    }>;
+  } | null;
   importId: number;
 }