- corretto scheda prodotto, record salvato
This commit is contained in:
@@ -10,7 +10,7 @@ const T_Web_Articoli = require('../models/t_web_articoli');
|
||||
const T_Web_StatiProdotto = require('../models/t_web_statiprodotto');
|
||||
const T_Web_TipiFormato = require('../models/t_web_tipiformato');
|
||||
|
||||
const SERVER_A_URL = process.env.SERVER_A_URL || "http://IP_DI_SERVER_A:3000";
|
||||
const SERVER_A_URL = process.env.SERVER_A_URL || "";
|
||||
const API_KEY = process.env.API_KEY_MSSQL;
|
||||
|
||||
const mongoose = require('mongoose').set('debug', false);
|
||||
@@ -81,15 +81,14 @@ exports.getTableContent = async (options) => {
|
||||
try {
|
||||
// Chiama getTableContent, se ritorna errore hangup, allora attendi 2 secondi e poi richiamala.
|
||||
const tableContent = await this.getTableContentBase(options);
|
||||
console.log(' uscito dalla funzione getTableContentBase ... ')
|
||||
return tableContent;
|
||||
} catch (error) {
|
||||
console.error('Error: ', error);
|
||||
console.error('Error: ', error?.message);
|
||||
if (error.message === 'socket hang up') {
|
||||
console.log('Error: hangup, waiting 2 seconds and retrying...');
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
return await this.getTableContent(options);
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -118,11 +117,14 @@ exports.getModelByNameTable = (nameTable) => {
|
||||
|
||||
exports.getTableContentBase = async (options) => {
|
||||
try {
|
||||
const myurl = SERVER_A_URL + '/query';
|
||||
console.log('getTableContentBase...', myurl)
|
||||
// Verifica se la tabella esiste
|
||||
const checkTableQuery = `SELECT COUNT(*) as tableExists FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '${options.nameTable}'`;
|
||||
const checkResponse = await axios.post(SERVER_A_URL + '/query', { query: checkTableQuery }, {
|
||||
const checkResponse = await axios.post(myurl, { query: checkTableQuery }, {
|
||||
headers: { 'x-api-key': API_KEY }
|
||||
});
|
||||
console.log(' risposta 1...')
|
||||
if (!checkResponse?.data || checkResponse?.data.length === 0 || checkResponse?.data[0].tableExists === 0) {
|
||||
return `La tabella '${options.nameTable}' non esiste.`;
|
||||
}
|
||||
@@ -132,6 +134,7 @@ exports.getTableContentBase = async (options) => {
|
||||
const columnsResponse = await axios.post(SERVER_A_URL + '/query', { query: columnsQuery }, {
|
||||
headers: { 'x-api-key': API_KEY }
|
||||
});
|
||||
console.log(' risposta 2 (schema)...')
|
||||
const tableColumns = columnsResponse.data.map(col => col.COLUMN_NAME);
|
||||
|
||||
// Mappatura per unire i campi (ID e Descrizione)
|
||||
@@ -162,6 +165,7 @@ exports.getTableContentBase = async (options) => {
|
||||
}
|
||||
|
||||
if (options.aggregation) {
|
||||
console.log('options.aggregation', options.aggregation);
|
||||
records = await mymodel.aggregate(options.aggregation);
|
||||
|
||||
} else {
|
||||
@@ -186,10 +190,11 @@ exports.getTableContentBase = async (options) => {
|
||||
pipeline.push({ $project: { [options.fieldGM]: 1 } });
|
||||
}
|
||||
|
||||
console.log(' aggregate pipeline...', pipeline);
|
||||
records = await mymodel.aggregate(pipeline);
|
||||
}
|
||||
|
||||
console.log('results', records[0]);
|
||||
console.log('results', records ? records[0] : ' non ricevuto');
|
||||
|
||||
} else {
|
||||
|
||||
@@ -340,6 +345,7 @@ exports.getTableContentBase = async (options) => {
|
||||
}
|
||||
|
||||
if (!records || records.length === 0) {
|
||||
console.log(`Nessun record trovato per la tabella ${options.nameTable}.`);
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -879,16 +885,24 @@ exports.mssqlmigrateTables = async (req) => {
|
||||
const MssqlMigrator = require('../modules/MssqlMigrator'); // Importa la classe Macro
|
||||
|
||||
try {
|
||||
const options = req.body.options;
|
||||
const options = req.body.mydata.options;
|
||||
let listaTabelle = [];
|
||||
|
||||
|
||||
if (options?.tutte) {
|
||||
// const listaTabelle = ['T_WEB_StatiProdotto'];
|
||||
listaTabelle = ['T_WEB_TitoliOriginali', 'T_WEB_TestateOrdini', 'T_WEB_Ordini', 'T_WEB_Disponibile', 'T_WOO_TestateOrdini', 'T_WOO_Ordini', 'T_WEB_Articoli',
|
||||
'T_WEB_Argomenti', 'T_WEB_ClientiInternet', 'T_WOO_Clienti', 'T_WEB_Autori', 'T_WEB_Collane', 'T_WEB_MarchiEditoriali', 'T_WEB_StatiProdotto', 'T_WEB_TipiFormato', 'T_WEB_Tipologie', 'T_WEB_ArticoliFatturati', 'T_WEB_IdInternetFatturati',
|
||||
'T_WEB_Edizioni', 'T_WEB_Contratti'];
|
||||
} else if (options?.parte1) {
|
||||
listaTabelle = ['T_WEB_TitoliOriginali', 'T_WEB_TestateOrdini', 'T_WEB_Ordini', 'T_WOO_TestateOrdini', 'T_WOO_Ordini', 'T_WEB_Articoli'];
|
||||
} else if (options?.parte2) {
|
||||
listaTabelle = ['T_WEB_Disponibile', 'T_WEB_Argomenti', 'T_WEB_ClientiInternet', 'T_WOO_Clienti', 'T_WEB_Autori'];
|
||||
} else if (options?.parte3) {
|
||||
listaTabelle = ['T_WEB_Collane', 'T_WEB_MarchiEditoriali', 'T_WEB_StatiProdotto', 'T_WEB_TipiFormato', 'T_WEB_Tipologie', 'T_WEB_ArticoliFatturati', 'T_WEB_IdInternetFatturati',
|
||||
'T_WEB_Edizioni', 'T_WEB_Contratti'];
|
||||
} else {
|
||||
listaTabelle = ['T_WEB_Ordini'];
|
||||
listaTabelle = ['T_WEB_Articoli'];
|
||||
}
|
||||
|
||||
const migrator = new MssqlMigrator();
|
||||
@@ -908,11 +922,11 @@ exports.updateAllBook = async (idapp, options) => {
|
||||
const macro = new Macro(idapp); // Crea un'istanza della classe Macro
|
||||
options.idapp = idapp;
|
||||
|
||||
return await macro.updateLocalDbFromGM_T_Web_Articoli(options);
|
||||
return await macro.updateLocalDbFromGM_T_Web_Articoli(options);
|
||||
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
throw e;
|
||||
return e.message;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user