- prima bozza catalogo
This commit is contained in:
63
src/server/models/importadescr.js
Executable file
63
src/server/models/importadescr.js
Executable file
@@ -0,0 +1,63 @@
|
|||||||
|
mongoose = require('mongoose').set('debug', false)
|
||||||
|
const Schema = mongoose.Schema;
|
||||||
|
|
||||||
|
const tools = require('../tools/general');
|
||||||
|
|
||||||
|
const shared_consts = require('../tools/shared_nodejs');
|
||||||
|
|
||||||
|
const { ObjectID } = require('mongodb');
|
||||||
|
|
||||||
|
mongoose.Promise = global.Promise;
|
||||||
|
mongoose.level = "F";
|
||||||
|
|
||||||
|
// A1P
|
||||||
|
|
||||||
|
// Resolving error Unknown modifier: $pushAll
|
||||||
|
mongoose.plugin(schema => {
|
||||||
|
schema.options.usePushEach = true
|
||||||
|
});
|
||||||
|
|
||||||
|
const ImportaDescrSchema = new Schema({
|
||||||
|
idapp: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
_id: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
var ImportaDescr = module.exports = mongoose.model('ImportaDescr', ImportaDescrSchema);
|
||||||
|
|
||||||
|
ImportaDescrSchema.index({ idapp: 1 });
|
||||||
|
|
||||||
|
module.exports.getFieldsForSearch = function () {
|
||||||
|
return [
|
||||||
|
{ field: 'name', type: tools.FieldType.string },
|
||||||
|
{ field: 'description', type: tools.FieldType.string },
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.executeQueryTable = function (idapp, params) {
|
||||||
|
params.fieldsearch = this.getFieldsForSearch();
|
||||||
|
return tools.executeQueryTable(this, idapp, params);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.getImportaDescrByCode = function (idapp, code) {
|
||||||
|
return ImportaDescr.findAllIdApp(idapp, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.getImportaDescrById = async function (id) {
|
||||||
|
const arrris = await ImportaDescr.findAllIdApp('', '', id);
|
||||||
|
return arrris && arrris.length > 0 ? arrris[0] : null
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.findAllIdApp = async function (idapp) {
|
||||||
|
const ImportaDescr = this;
|
||||||
|
|
||||||
|
const myfind = { idapp, deleted: false };
|
||||||
|
|
||||||
|
return await ImportaDescr.find(myfind, (err, arrrec) => {
|
||||||
|
return arrrec;
|
||||||
|
});
|
||||||
|
};
|
||||||
63
src/server/models/importaisbn.js
Executable file
63
src/server/models/importaisbn.js
Executable file
@@ -0,0 +1,63 @@
|
|||||||
|
mongoose = require('mongoose').set('debug', false)
|
||||||
|
const Schema = mongoose.Schema;
|
||||||
|
|
||||||
|
const tools = require('../tools/general');
|
||||||
|
|
||||||
|
const shared_consts = require('../tools/shared_nodejs');
|
||||||
|
|
||||||
|
const { ObjectID } = require('mongodb');
|
||||||
|
|
||||||
|
mongoose.Promise = global.Promise;
|
||||||
|
mongoose.level = "F";
|
||||||
|
|
||||||
|
// A1P
|
||||||
|
|
||||||
|
// Resolving error Unknown modifier: $pushAll
|
||||||
|
mongoose.plugin(schema => {
|
||||||
|
schema.options.usePushEach = true
|
||||||
|
});
|
||||||
|
|
||||||
|
const ImportaIsbnSchema = new Schema({
|
||||||
|
idapp: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
_id: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
var ImportaIsbn = module.exports = mongoose.model('ImportaIsbn', ImportaIsbnSchema);
|
||||||
|
|
||||||
|
ImportaIsbnSchema.index({ idapp: 1 });
|
||||||
|
|
||||||
|
module.exports.getFieldsForSearch = function () {
|
||||||
|
return [
|
||||||
|
{ field: 'name', type: tools.FieldType.string },
|
||||||
|
{ field: 'description', type: tools.FieldType.string },
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.executeQueryTable = function (idapp, params) {
|
||||||
|
params.fieldsearch = this.getFieldsForSearch();
|
||||||
|
return tools.executeQueryTable(this, idapp, params);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.getImportaIsbnByCode = function (idapp, code) {
|
||||||
|
return ImportaIsbn.findAllIdApp(idapp, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.getImportaIsbnById = async function (id) {
|
||||||
|
const arrris = await ImportaIsbn.findAllIdApp('', '', id);
|
||||||
|
return arrris && arrris.length > 0 ? arrris[0] : null
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.findAllIdApp = async function (idapp) {
|
||||||
|
const ImportaIsbn = this;
|
||||||
|
|
||||||
|
const myfind = { idapp, deleted: false };
|
||||||
|
|
||||||
|
return await ImportaIsbn.find(myfind, (err, arrrec) => {
|
||||||
|
return arrrec;
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -19,6 +19,9 @@ const productInfoSchema = new Schema({
|
|||||||
department: {
|
department: {
|
||||||
type: String, ref: 'Department'
|
type: String, ref: 'Department'
|
||||||
},
|
},
|
||||||
|
sku: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
code: {
|
code: {
|
||||||
type: String,
|
type: String,
|
||||||
unique: true,
|
unique: true,
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ const { City } = require('../models/city');
|
|||||||
const Product = require('../models/product');
|
const Product = require('../models/product');
|
||||||
const Inventariogm = require('../models/inventariogm');
|
const Inventariogm = require('../models/inventariogm');
|
||||||
const Importamacro = require('../models/importamacro');
|
const Importamacro = require('../models/importamacro');
|
||||||
|
const ImportaDescr = require('../models/importadescr');
|
||||||
|
const ImportaIsbn = require('../models/importaIsbn');
|
||||||
const ProductInfo = require('../models/productInfo');
|
const ProductInfo = require('../models/productInfo');
|
||||||
const CatProd = require('../models/catprod');
|
const CatProd = require('../models/catprod');
|
||||||
const Author = require('../models/author');
|
const Author = require('../models/author');
|
||||||
@@ -355,6 +357,8 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
let imported = 0;
|
let imported = 0;
|
||||||
let errors = 0;
|
let errors = 0;
|
||||||
|
|
||||||
|
const ripopola = false;
|
||||||
|
|
||||||
dataObjects = null;
|
dataObjects = null;
|
||||||
|
|
||||||
let myarr = null;
|
let myarr = null;
|
||||||
@@ -367,12 +371,10 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
dataObjects = null;
|
dataObjects = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (myarr && ripopola) {
|
||||||
|
|
||||||
if (myarr) {
|
|
||||||
|
|
||||||
// Cancella la collection ImportaMacros
|
// Cancella la collection ImportaMacros
|
||||||
await Importamacro.deleteMany({ idapp });
|
await ImportaDescr.deleteMany({ idapp });
|
||||||
|
|
||||||
// Aggiungi i record su ImportaMacros
|
// Aggiungi i record su ImportaMacros
|
||||||
for (const recinv of myarr) {
|
for (const recinv of myarr) {
|
||||||
@@ -389,13 +391,13 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
let queryprod = { idapp, code: recmacro._id };
|
let queryprod = { idapp, code: recmacro._id };
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let risrec = await Importamacro.findOneAndUpdate(queryprod, { $set: recmacro }, { new: true, upsert: true, strict: false });
|
let risrec = await ImportaDescr.findOneAndUpdate(queryprod, { $set: recmacro }, { new: true, upsert: true, strict: false });
|
||||||
if (risrec) {
|
if (risrec) {
|
||||||
imported++;
|
imported++;
|
||||||
// if (imported > 1000)
|
// if (imported > 1000)
|
||||||
// break;
|
// break;
|
||||||
|
if (imported % 10 === 0)
|
||||||
console.log('importato ', imported, 'su ', myarr.length);
|
console.log('importato ', imported, 'su ', myarr.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -407,10 +409,10 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rileggi tutti i record di ImportaMacros
|
// Rileggi tutti i record di ImportaDescr
|
||||||
dataObjects = await Importamacro.find({ idapp }).lean();
|
dataObjects = await ImportaDescr.find({ idapp }).lean();
|
||||||
|
|
||||||
console.log('*** INIZIO IMPORT PRODOTTI ... ');
|
console.log('*** INIZIO IMPORT MACRO_DESCRELINKSITOWEB ... ');
|
||||||
|
|
||||||
let indprod = 0;
|
let indprod = 0;
|
||||||
let newprod = 0;
|
let newprod = 0;
|
||||||
@@ -446,20 +448,42 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
productInfo.sottotitolo = getvalueByJsonText(product.sottotitolo);
|
productInfo.sottotitolo = getvalueByJsonText(product.sottotitolo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pagine = getvalueByJsonText(product.pagine);
|
||||||
|
|
||||||
|
let recisbn = {};
|
||||||
|
|
||||||
|
if (pagine && pagine !== '0') {
|
||||||
|
recisbn.Pagine = pagine;
|
||||||
|
}
|
||||||
|
|
||||||
|
recisbn.link_macro = productInfo.link_macro;
|
||||||
|
recisbn.descrizione_breve_macro = productInfo.descrizione_breve_macro;
|
||||||
|
recisbn.descrizione_completa_macro = productInfo.descrizione_completa_macro;
|
||||||
|
recisbn.sottotitolo = productInfo.sottotitolo;
|
||||||
|
|
||||||
|
let risisbn = await ImportaIsbn.findOneAndUpdate({ isbn: product.code }, { $set: recisbn }, { new: true, upsert: true, strict: false });
|
||||||
|
|
||||||
// Update ProductInfo
|
// Update ProductInfo
|
||||||
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: true });
|
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: true });
|
||||||
|
|
||||||
indprod++;
|
indprod++;
|
||||||
|
if (indprod % 10 === 0)
|
||||||
console.log(indprod + '/' + numprod);
|
console.log(indprod + '/' + numprod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('*** IMPORTATI: ', imported, '*** NUOVI: ', newprod, 'AGGIORNATI = ' + updated + ' (su ' + dataObjects.length + ' RECORD)');
|
||||||
|
|
||||||
|
return res.status(200).send({ updated, imported, errors });
|
||||||
|
|
||||||
} else if (cmd === shared_consts.Cmd.MACRO_RANKING) {
|
} else if (cmd === shared_consts.Cmd.MACRO_RANKING) {
|
||||||
let updated = 0;
|
let updated = 0;
|
||||||
let imported = 0;
|
let imported = 0;
|
||||||
let errors = 0;
|
let errors = 0;
|
||||||
|
|
||||||
|
const ripopola = true;
|
||||||
|
|
||||||
|
if (ripopola) {
|
||||||
dataObjects = null;
|
dataObjects = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -470,27 +494,30 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
if (dataObjects && dataObjects[0]) {
|
if (dataObjects && dataObjects[0]) {
|
||||||
// Cancella la collection ImportaMacros
|
// Cancella la collection ImportaMacros
|
||||||
await Importamacro.deleteMany({ idapp });
|
await ImportaIsbn.deleteMany({ idapp });
|
||||||
|
|
||||||
|
const numtot = dataObjects[0].length
|
||||||
|
|
||||||
// Aggiungi i record su ImportaMacros
|
// Aggiungi i record su ImportaMacros
|
||||||
for (const recinv of dataObjects[0]) {
|
for (const recinv of dataObjects[0]) {
|
||||||
let isnuovo = false
|
|
||||||
let setta = false
|
|
||||||
|
|
||||||
let recmacro = recinv;
|
let recmacro = recinv;
|
||||||
|
|
||||||
recmacro.idapp = idapp;
|
recmacro.idapp = idapp;
|
||||||
|
|
||||||
recmacro._id = recmacro.id;
|
//recmacro._id = recmacro.id;
|
||||||
|
recmacro.sku = recmacro.idArticolo;
|
||||||
|
|
||||||
delete recmacro.id;
|
if (recmacro.DataPubblicazione) {
|
||||||
|
|
||||||
let queryprod = { idapp, _id: recmacro._id };
|
// delete recmacro.id;
|
||||||
|
|
||||||
|
let queryprod = { idapp, sku: recmacro.sku };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let risrec = await Importamacro.findOneAndUpdate(queryprod, { $set: recmacro }, { new: true, upsert: true, strict: false });
|
let risrec = await ImportaIsbn.findOneAndUpdate(queryprod, { $set: recmacro }, { new: true, upsert: true, strict: false });
|
||||||
if (risrec) {
|
if (risrec) {
|
||||||
imported++;
|
imported++;
|
||||||
|
console.log('Importati dir TEMPORANEA ... ', imported + '/' + numtot);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -499,17 +526,20 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Rileggi tutti i record di ImportaMacros
|
// Rileggi tutti i record di ImportaIsbn
|
||||||
dataObjects = await Importamacro.find({ idapp }).lean();
|
dataObjects = await ImportaIsbn.find({ idapp }).lean();
|
||||||
|
|
||||||
console.log('*** INIZIO IMPORT PRODOTTI ... ');
|
console.log('*** INIZIO IMPORT RANKING ... ');
|
||||||
|
|
||||||
let indprod = 0;
|
let indprod = 0;
|
||||||
let newprod = 0;
|
let newprod = 0;
|
||||||
|
|
||||||
let numprod = dataObjects.length;
|
let numprod = dataObjects.length;
|
||||||
|
|
||||||
|
imported = 0;
|
||||||
|
|
||||||
for (const product of dataObjects) {
|
for (const product of dataObjects) {
|
||||||
let isnuovo = false
|
let isnuovo = false
|
||||||
@@ -517,7 +547,8 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
let importa = true;
|
let importa = true;
|
||||||
|
|
||||||
if (!product.title || !product.isbn)
|
//if (!product.title || !product.isbn)
|
||||||
|
if (!product.sku || !product.DataPubblicazione)
|
||||||
importa = false;
|
importa = false;
|
||||||
|
|
||||||
if (importa) {
|
if (importa) {
|
||||||
@@ -528,36 +559,53 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
let productInfo = {
|
let productInfo = {
|
||||||
idapp: product.idapp,
|
idapp: product.idapp,
|
||||||
code: product.isbn,
|
code: product.isbn ? product.isbn : product.code,
|
||||||
id_wp: product._id,
|
sku: product.sku,
|
||||||
|
|
||||||
|
// id_wp: product._id,
|
||||||
|
|
||||||
// name: product.title,
|
// name: product.title,
|
||||||
totaleVenduti: product.totaleVenduti,
|
totaleVenduti: product.totaleaVenduti,
|
||||||
venditeLastM: product.venditeLastM,
|
venditeLastM: product.venditeLastM,
|
||||||
venditeLast6M: product.venditeLast6M,
|
venditeLast6M: product.venditeLast6M,
|
||||||
venditeLastY: product.venditeLastY,
|
venditeLastY: product.venditeLastY,
|
||||||
venditeLast2Y: product.venditeLast2Y,
|
venditeLast2Y: product.venditeLast2Y,
|
||||||
dataUltimoOrdine: product.dataUltimoOrdine,
|
|
||||||
rank3M: product.rank3M,
|
rank3M: product.rank3M,
|
||||||
rank6M: product.rank6M,
|
rank6M: product.rank6M,
|
||||||
rank1Y: product.rank1Y,
|
rank1Y: product.rank1Y,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(indprod + '/' + numprod);
|
if (product.DataPubblicazione) {
|
||||||
|
productInfo.date_publishing = new Date(product.DataPubblicazione);
|
||||||
|
// convert data to timestamp
|
||||||
|
productInfo.date_publishing_ts = productInfo.date_publishing.getTime();
|
||||||
|
}
|
||||||
|
if (product.dataUltimoOrdine) {
|
||||||
|
productInfo.dataUltimoOrdine = new Date(product.dataUltimoOrdine);
|
||||||
|
}
|
||||||
|
|
||||||
// Update ProductInfo
|
// Update ProductInfo
|
||||||
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: true });
|
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: true });
|
||||||
|
if (risrecInfo) {
|
||||||
|
imported++;
|
||||||
|
console.log('Importati... ', imported + '/' + numprod);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
indprod++;
|
console.log('*** IMPORTATI: ', imported, ' [Prodotti = ' + indprod + '] *** NUOVI: ', newprod, 'AGGIORNATI = ' + updated + ' (su ' + dataObjects.length + ' RECORD)');
|
||||||
}
|
|
||||||
}
|
return res.status(200).send({ updated, imported, errors });
|
||||||
|
|
||||||
} else if (cmd === shared_consts.Cmd.MACRO_CATALOGO_JSON) {
|
} else if (cmd === shared_consts.Cmd.MACRO_CATALOGO_JSON) {
|
||||||
let updated = 0;
|
let updated = 0;
|
||||||
let imported = 0;
|
let imported = 0;
|
||||||
let errors = 0;
|
let errors = 0;
|
||||||
|
|
||||||
|
const ripopola = true;
|
||||||
|
|
||||||
|
|
||||||
|
if (ripopola) {
|
||||||
dataObjects = null;
|
dataObjects = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -583,12 +631,29 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
delete recmacro.id;
|
delete recmacro.id;
|
||||||
|
|
||||||
|
// Ottengo isbn e Pagine da ImportaIsbn
|
||||||
|
|
||||||
|
const recrankingisbn = await ImportaIsbn.findOne({ sku: recmacro.sku }).lean();
|
||||||
|
if (recrankingisbn) {
|
||||||
|
if (!recmacro.isbn) {
|
||||||
|
recmacro.isbn = recrankingisbn.isbn;
|
||||||
|
}
|
||||||
|
if ((!recmacro.Pagine || recmacro.Pagine === 0) && recrankingisbn.Pagine)
|
||||||
|
recmacro.Pagine = recrankingisbn.Pagine;
|
||||||
|
|
||||||
|
if (!recmacro.misure && recrankingisbn.misure) {
|
||||||
|
recmacro.misure = recrankingisbn.misure;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let queryprod = { idapp, _id: recmacro._id };
|
let queryprod = { idapp, _id: recmacro._id };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let risrec = await Importamacro.findOneAndUpdate(queryprod, { $set: recmacro }, { new: true, upsert: true, strict: false });
|
let risrec = await Importamacro.findOneAndUpdate(queryprod, { $set: recmacro }, { new: true, upsert: true, strict: false });
|
||||||
if (risrec) {
|
if (risrec) {
|
||||||
imported++;
|
imported++;
|
||||||
|
if (imported % 10 === 0)
|
||||||
|
console.log('Importati su dir Temporanea ', imported);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -604,6 +669,7 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
await CatProd.deleteMany({ idapp });
|
await CatProd.deleteMany({ idapp });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Rileggi tutti i record di ImportaMacros
|
// Rileggi tutti i record di ImportaMacros
|
||||||
dataObjects = await Importamacro.find({ idapp }).lean();
|
dataObjects = await Importamacro.find({ idapp }).lean();
|
||||||
@@ -621,7 +687,7 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
let importa = true;
|
let importa = true;
|
||||||
|
|
||||||
if (!product.title || !product.isbn)
|
if (!product.title || !product.sku)
|
||||||
importa = false;
|
importa = false;
|
||||||
|
|
||||||
if (importa) {
|
if (importa) {
|
||||||
@@ -634,6 +700,7 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
idapp: product.idapp,
|
idapp: product.idapp,
|
||||||
code: product.isbn,
|
code: product.isbn,
|
||||||
id_wp: product._id,
|
id_wp: product._id,
|
||||||
|
sku: product.sku,
|
||||||
|
|
||||||
name: product.title,
|
name: product.title,
|
||||||
description: product.description,
|
description: product.description,
|
||||||
@@ -654,6 +721,7 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
let versione = 0;
|
let versione = 0;
|
||||||
|
|
||||||
|
if (indprod % 10 === 0)
|
||||||
console.log(indprod + '/' + numprod);
|
console.log(indprod + '/' + numprod);
|
||||||
|
|
||||||
|
|
||||||
@@ -688,11 +756,11 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (product.Data) {
|
/*if (product.Data) {
|
||||||
productInfo.date_publishing = new Date(product.Data * 1000);
|
productInfo.date_publishing = new Date(product.Data * 1000);
|
||||||
// convert data to timestamp
|
// convert data to timestamp
|
||||||
productInfo.date_publishing_ts = productInfo.date_publishing.getTime();
|
productInfo.date_publishing_ts = productInfo.date_publishing.getTime();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
productInfo.name = productInfo.name.replace(/ - Usato$| - Nuovo$| - Epub$| - Ebook$| - Mobi$| - DVD$| - Streaming$| - Download$/, "");
|
productInfo.name = productInfo.name.replace(/ - Usato$| - Nuovo$| - Epub$| - Ebook$| - Mobi$| - DVD$| - Streaming$| - Download$/, "");
|
||||||
|
|
||||||
@@ -916,7 +984,7 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
variazione.formato = product.formato ? product.formato : '';
|
variazione.formato = product.formato ? product.formato : '';
|
||||||
variazione.tipologia = product.Tipologia ? product.Tipologia : '';
|
variazione.tipologia = product.Tipologia ? product.Tipologia : '';
|
||||||
variazione.edizione = product.Edizione ? product.Edizione : '';
|
variazione.edizione = product.Edizione ? product.Edizione : '';
|
||||||
variazione.pagine = product.Pagine ? parseInt(product.Pagine) : '';
|
variazione.pagine = tools.isValidNumber(product.Pagine) ? tools.convstrToInt(product.Pagine) : 0;
|
||||||
variazione.misure = product.misure ? product.misure : '';
|
variazione.misure = product.misure ? product.misure : '';
|
||||||
variazione.eta = product.eta ? product.eta : '';
|
variazione.eta = product.eta ? product.eta : '';
|
||||||
variazione.addtocart_link = product.addtocart_link ? product.addtocart_link : '';
|
variazione.addtocart_link = product.addtocart_link ? product.addtocart_link : '';
|
||||||
|
|||||||
@@ -4387,6 +4387,20 @@ module.exports = {
|
|||||||
return parseInt(version);
|
return parseInt(version);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
convstrToInt(mystr) {
|
||||||
|
try {
|
||||||
|
const parsed = parseInt(mystr, 10); // Specifica la base come 10
|
||||||
|
return isNaN(parsed) ? 0 : parsed; // Restituisce 0 se il valore è NaN
|
||||||
|
} catch (e) {
|
||||||
|
return 0; // Se c'è un errore, restituisce 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
isValidNumber(value) {
|
||||||
|
// Controlla se il valore è un numero valido
|
||||||
|
return !isNaN(value) && value !== null && value !== '';
|
||||||
|
},
|
||||||
|
|
||||||
invertescapeslash(mystr) {
|
invertescapeslash(mystr) {
|
||||||
return mystr.replace(/Ç/g, '/');
|
return mystr.replace(/Ç/g, '/');
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user