From a2b4dd7eb7fa434d90ca58161370884841b08ec9 Mon Sep 17 00:00:00 2001 From: mertmit Date: Tue, 10 Oct 2023 14:01:52 +0000 Subject: [PATCH] fix: improved readability for loops --- .../jobs/at-import/at-import.processor.ts | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/packages/nocodb/src/modules/jobs/jobs/at-import/at-import.processor.ts b/packages/nocodb/src/modules/jobs/jobs/at-import/at-import.processor.ts index 28ba007a14..c0a09883f3 100644 --- a/packages/nocodb/src/modules/jobs/jobs/at-import/at-import.processor.ts +++ b/packages/nocodb/src/modules/jobs/jobs/at-import/at-import.processor.ts @@ -314,7 +314,7 @@ export class AtImportProcessor { const nc_getSanitizedColumnName = (table, name) => { let col_name = nc_sanitizeName(name); - // truncate to 60 chars if character if exceeds above 50 + // truncate to 50 chars if character if exceeds above 50 col_name = col_name?.slice(0, 50); // for knex, replace . with _ @@ -327,27 +327,33 @@ export class AtImportProcessor { const duplicateColumn = table.columns.find( (x) => x.column_name?.toLowerCase() === col_name?.toLowerCase(), ); + if (duplicateTitle) { - let iterator = 1; + let tempAlias = col_alias; + let suffix = 1; while ( table.columns.find( - (x) => - x.title?.toLowerCase() === - `${col_alias}_${++iterator}`?.toLowerCase(), + (x) => x.title?.toLowerCase() === tempAlias?.toLowerCase(), ) - ) {} - col_alias = `${col_alias}_${iterator}`; + ) { + tempAlias = col_alias; + tempAlias += `_${suffix++}`; + } + col_alias = tempAlias; } + if (duplicateColumn) { - let iterator = 1; + let tempName = col_name; + let suffix = 1; while ( table.columns.find( - (x) => - x.column_name?.toLowerCase() === - `${col_name}_${++iterator}`?.toLowerCase(), + (x) => x.column_name?.toLowerCase() === tempName?.toLowerCase(), ) - ) {} - col_name = `${col_name}_${iterator}`; + ) { + tempName = col_name; + tempName += `_${suffix++}`; + } + col_name = tempName; } return {