Fixing the error when importing a large Excel file

This commit is contained in:
2026-10-03 15:01:01 +03:30
parent f8313c0ea5
commit 2e315c9cfd
15 changed files with 503 additions and 86 deletions
+19 -6
View File
@@ -17,6 +17,10 @@ import {
writeXlsx,
type ExcelPreviewResult,
} from '../common/excel';
import {
chunkImportMeta,
resolveExcelImportChunk,
} from '../common/excel-import-session';
import { PipelinesService } from './pipelines.service';
const DEAL_COLUMNS = [
@@ -154,16 +158,25 @@ export class DealsExcelService {
async import(
actor: Actor,
file: Express.Multer.File,
file: Express.Multer.File | undefined,
mappingRaw?: string,
chunk?: { sessionId?: string; offset?: string | number; limit?: string | number },
): Promise<ImportContactsResult> {
const rows = await readMappedRows(file, DEAL_ALIASES, parseExcelMapping(mappingRaw));
const ctx = await resolveExcelImportChunk({
organizationId: actor.organizationId,
file,
sessionId: chunk?.sessionId,
offset: chunk?.offset,
limit: chunk?.limit,
loadRows: () =>
readMappedRows(file!, DEAL_ALIASES, parseExcelMapping(mappingRaw)),
});
const result: ImportContactsResult = { created: 0, skipped: 0, errors: [] };
const affected = new Map<string, string>();
for (let i = 0; i < rows.length; i++) {
const row = rows[i]!;
const rowNum = i + 2;
for (let i = 0; i < ctx.slice.length; i++) {
const row = ctx.slice[i]!;
const rowNum = ctx.offset + i + 2;
if ((row._type || '').trim() && row._type.trim().toLowerCase() !== 'deal') {
continue;
}
@@ -235,7 +248,7 @@ export class DealsExcelService {
result.boardId = entries[0][0];
result.boards = entries.map(([, n]) => n);
}
return result;
return { ...result, ...chunkImportMeta(ctx) };
}
private async resolvePipelineAndStage(
+9 -2
View File
@@ -70,10 +70,17 @@ export class DealsController {
)
import(
@CurrentUser() user: Actor,
@UploadedFile() file: Express.Multer.File,
@UploadedFile() file: Express.Multer.File | undefined,
@Body('mapping') mapping?: string,
@Body('sessionId') sessionId?: string,
@Body('offset') offset?: string,
@Body('limit') limit?: string,
) {
return this.excelService.import(user, file, mapping);
return this.excelService.import(user, file, mapping, {
sessionId,
offset,
limit,
});
}
@Get(':id')