- corretto scheda prodotto, record salvato

This commit is contained in:
Surya Paolo
2025-05-01 00:20:16 +02:00
parent 97abe8b46d
commit fcc3755c19
13 changed files with 89 additions and 49 deletions

View File

@@ -28,11 +28,16 @@ class MssqlMigrator {
async migrateTables(tableNames) {
try {
const numtables = tableNames.length;
let indtab = 0;
let indtabok = 0;
const logs = [];
for (const tableName of tableNames) {
try {
logs.push(`\n>> Recupero dati da MSSQL per la tabella: ${tableName}`);
const percentuale = ((indtab / numtables) * 100).toFixed(2);
logs.push(`\n>> Recupero dati da MSSQL per la tabella: ${tableName} - (Completamento: ${percentuale}%)`);
console.log(logs[logs.length - 1]);
const dataQuery = `SELECT * FROM [${tableName}]`;
@@ -44,7 +49,7 @@ class MssqlMigrator {
{ query: dataQuery },
{ headers: { 'x-api-key': this.apiKey } },
null,
{ timeout: 300000 });
{ timeout: 900000 });
} catch (error) {
console.error('Error: ', error);
if (error.message === 'socket hang up') {
@@ -56,10 +61,11 @@ class MssqlMigrator {
{ query: dataQuery },
{ headers: { 'x-api-key': this.apiKey } },
null,
{ timeout: 300000 });
{ timeout: 900000 });
} else {
throw error;
console.error('Unexpected error while fetching data from MSSQL:', error.message);
// throw error;
}
}
@@ -101,14 +107,19 @@ class MssqlMigrator {
logs.push(`✅ Inserimento di ${records.length} record nella collezione MongoDB: ${modelName}`);
console.log(logs[logs.length - 1]);
await DynamicModel.insertMany(records);
indtabok++;
} catch (error) {
logs.push(`❌ Errore con la tabella ${tableName}:`, error.message);
console.log(logs[logs.length - 1]);
}
indtab++;
}
logs.push('\n🎉 Tutte le tabelle sono state migrate.');
logs.push(`\n🎉 ${indtabok} tabelle su ${numtables} sono state migrate.`);
console.log(logs[logs.length - 1]);
return logs.join('\n');
} catch (error) {