- fix with old_code
- filtro per GAS
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
DATABASE=test_FreePlanet
|
DATABASE=test_PiuCheBuono
|
||||||
UDB=paofreeplanet
|
UDB=paofreeplanet
|
||||||
PDB=mypassword@1A
|
PDB=mypassword@1A
|
||||||
SEND_EMAIL=0
|
SEND_EMAIL=0
|
||||||
SEND_EMAIL_ORDERS=1
|
SEND_EMAIL_ORDERS=1
|
||||||
PORT=3000
|
PORT=3000
|
||||||
appTelegram_TEST=["1","13"]
|
appTelegram_TEST=["1","17"]
|
||||||
appTelegram=["1","13"]
|
appTelegram=["1","17"]
|
||||||
DOMAIN=mongodb://localhost:27017/
|
DOMAIN=mongodb://localhost:27017/
|
||||||
AUTH_MONGODB=true
|
AUTH_MONGODB=true
|
||||||
MONGODB_USER=admin
|
MONGODB_USER=admin
|
||||||
|
|||||||
@@ -43,33 +43,41 @@ function fixURL(url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function completaSettaggioProduct_AndProductInfo(arrcampi_productInfo, arrcampi_product, rec, product, productInfo) {
|
async function completaSettaggioProduct_AndProductInfo(arrcampi_productInfo, arrcampi_product, rec, product, productInfo) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (shared_consts.CAMPI_PRODUCTINFO_CONVERT.includes('weight_and_unit')) {
|
if (shared_consts.CAMPI_PRODUCTINFO_CONVERT.includes('weight_and_unit')) {
|
||||||
const ris1 = tools.getWeightAndUnitByText(rec['weight_and_unit']);
|
if (rec.hasOwnProperty('weight_and_unit')) {
|
||||||
if (ris1) {
|
const ris1 = tools.getWeightAndUnitByText(rec['weight_and_unit']);
|
||||||
productInfo.weight = ris1.weight;
|
if (ris1) {
|
||||||
productInfo.unit = ris1.unit;
|
productInfo.weight = ris1.weight;
|
||||||
|
productInfo.unit = ris1.unit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shared_consts.CAMPI_PRODUCTINFO_CONVERT.includes('weight_and_unit_lordo')) {
|
if (shared_consts.CAMPI_PRODUCTINFO_CONVERT.includes('weight_and_unit_lordo')) {
|
||||||
const ris2 = tools.getWeightAndUnitByText(rec['weight_and_unit_lordo']);
|
if (rec.hasOwnProperty('weight_and_unit_lordo')) {
|
||||||
if (ris2) {
|
const ris2 = tools.getWeightAndUnitByText(rec['weight_and_unit_lordo']);
|
||||||
productInfo.weight_lordo = ris2.weight;
|
if (ris2) {
|
||||||
productInfo.unit_lordo = ris2.unit;
|
productInfo.weight_lordo = ris2.weight;
|
||||||
|
productInfo.unit_lordo = ris2.unit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rec.hasOwnProperty('link_scheda')) {
|
if (rec.hasOwnProperty('link_scheda')) {
|
||||||
productInfo['link_scheda'] = fixURL(rec['link_scheda'])
|
if (fixURL(rec['link_scheda']))
|
||||||
|
productInfo['link_scheda'] = fixURL(rec['link_scheda'])
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const campo of shared_consts.PRODUCTINFO.CAMPI_FIRST_UPPERCASE) {
|
for (const campo of shared_consts.PRODUCTINFO.CAMPI_FIRST_UPPERCASE) {
|
||||||
|
|
||||||
if (rec.hasOwnProperty(campo)) {
|
if (rec.hasOwnProperty(campo)) {
|
||||||
productInfo[campo] = tools.capitalize(rec[campo]);
|
let mystr = tools.capitalize(rec[campo]).trim();
|
||||||
|
if (mystr)
|
||||||
|
productInfo[campo] = mystr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +85,6 @@ function completaSettaggioProduct_AndProductInfo(arrcampi_productInfo, arrcampi_
|
|||||||
for (campoprezzo of shared_consts.CAMPI_EURO) {
|
for (campoprezzo of shared_consts.CAMPI_EURO) {
|
||||||
if (rec.hasOwnProperty(campoprezzo)) {
|
if (rec.hasOwnProperty(campoprezzo)) {
|
||||||
product[campoprezzo] = tools.convertPriceEurToValue(rec[campoprezzo])
|
product[campoprezzo] = tools.convertPriceEurToValue(rec[campoprezzo])
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,6 +96,23 @@ function completaSettaggioProduct_AndProductInfo(arrcampi_productInfo, arrcampi_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rec.hasOwnProperty('old_code')) {
|
||||||
|
const old_code = rec['old_code'];
|
||||||
|
let oldrec = await ProductInfo.findOne({ code: old_code }).lean();
|
||||||
|
if (oldrec) {
|
||||||
|
const precid = productInfo._id;
|
||||||
|
const preccode = productInfo.code;
|
||||||
|
|
||||||
|
productInfo = oldrec;
|
||||||
|
if (precid)
|
||||||
|
productInfo._id = precid;
|
||||||
|
else
|
||||||
|
delete productInfo._id;
|
||||||
|
|
||||||
|
productInfo.code = preccode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return { product, productInfo };
|
return { product, productInfo };
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -133,7 +157,7 @@ function getValoriAndIndice_Product(dati) {
|
|||||||
return shared_consts.CAMPI_PRODUCT;
|
return shared_consts.CAMPI_PRODUCT;
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractArrayDataFromCSV(idapp, rec) {
|
async function extractArrayDataFromCSV(idapp, rec) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// la prima riga contiene il nome della proprietà:
|
// la prima riga contiene il nome della proprietà:
|
||||||
@@ -163,7 +187,7 @@ function extractArrayDataFromCSV(idapp, rec) {
|
|||||||
product[campoobj] = rec[campoobj];
|
product[campoobj] = rec[campoobj];
|
||||||
}
|
}
|
||||||
|
|
||||||
const ris = completaSettaggioProduct_AndProductInfo(arrcampi_productInfo, arrcampi_product, rec, product, productInfo);
|
const ris = await completaSettaggioProduct_AndProductInfo(arrcampi_productInfo, arrcampi_product, rec, product, productInfo);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// code: product.code,
|
// code: product.code,
|
||||||
@@ -399,7 +423,7 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
for (const rec of myarrshift) {
|
for (const rec of myarrshift) {
|
||||||
|
|
||||||
let risprod = extractArrayDataFromCSV(idapp, rec);
|
let risprod = await extractArrayDataFromCSV(idapp, rec);
|
||||||
let product = risprod.product;
|
let product = risprod.product;
|
||||||
let productInfo = risprod.productInfo;
|
let productInfo = risprod.productInfo;
|
||||||
|
|
||||||
|
|||||||
@@ -973,6 +973,10 @@ module.exports = {
|
|||||||
'weight_and_unit_lordo',
|
'weight_and_unit_lordo',
|
||||||
],
|
],
|
||||||
|
|
||||||
|
CAMPI_PRODUCTINFO_RICOPIA_DATI: [
|
||||||
|
'old_code',
|
||||||
|
],
|
||||||
|
|
||||||
PRODUCTINFO: {
|
PRODUCTINFO: {
|
||||||
CAMPI_FIRST_UPPERCASE: [
|
CAMPI_FIRST_UPPERCASE: [
|
||||||
'name',
|
'name',
|
||||||
|
|||||||
Reference in New Issue
Block a user