- fix with old_code

- filtro per GAS
This commit is contained in:
Surya Paolo
2024-03-08 18:57:13 +01:00
parent c94d5dc844
commit 44b25fdf33
3 changed files with 46 additions and 18 deletions

View File

@@ -1,11 +1,11 @@
DATABASE=test_FreePlanet
DATABASE=test_PiuCheBuono
UDB=paofreeplanet
PDB=mypassword@1A
SEND_EMAIL=0
SEND_EMAIL_ORDERS=1
PORT=3000
appTelegram_TEST=["1","13"]
appTelegram=["1","13"]
appTelegram_TEST=["1","17"]
appTelegram=["1","17"]
DOMAIN=mongodb://localhost:27017/
AUTH_MONGODB=true
MONGODB_USER=admin

View File

@@ -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 {
if (shared_consts.CAMPI_PRODUCTINFO_CONVERT.includes('weight_and_unit')) {
const ris1 = tools.getWeightAndUnitByText(rec['weight_and_unit']);
if (ris1) {
productInfo.weight = ris1.weight;
productInfo.unit = ris1.unit;
if (rec.hasOwnProperty('weight_and_unit')) {
const ris1 = tools.getWeightAndUnitByText(rec['weight_and_unit']);
if (ris1) {
productInfo.weight = ris1.weight;
productInfo.unit = ris1.unit;
}
}
}
if (shared_consts.CAMPI_PRODUCTINFO_CONVERT.includes('weight_and_unit_lordo')) {
const ris2 = tools.getWeightAndUnitByText(rec['weight_and_unit_lordo']);
if (ris2) {
productInfo.weight_lordo = ris2.weight;
productInfo.unit_lordo = ris2.unit;
if (rec.hasOwnProperty('weight_and_unit_lordo')) {
const ris2 = tools.getWeightAndUnitByText(rec['weight_and_unit_lordo']);
if (ris2) {
productInfo.weight_lordo = ris2.weight;
productInfo.unit_lordo = ris2.unit;
}
}
}
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) {
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) {
if (rec.hasOwnProperty(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 };
} catch (e) {
@@ -133,7 +157,7 @@ function getValoriAndIndice_Product(dati) {
return shared_consts.CAMPI_PRODUCT;
}
function extractArrayDataFromCSV(idapp, rec) {
async function extractArrayDataFromCSV(idapp, rec) {
try {
// la prima riga contiene il nome della proprietà:
@@ -163,7 +187,7 @@ function extractArrayDataFromCSV(idapp, rec) {
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,
@@ -399,7 +423,7 @@ router.post('/import', authenticate, async (req, res) => {
for (const rec of myarrshift) {
let risprod = extractArrayDataFromCSV(idapp, rec);
let risprod = await extractArrayDataFromCSV(idapp, rec);
let product = risprod.product;
let productInfo = risprod.productInfo;

View File

@@ -973,6 +973,10 @@ module.exports = {
'weight_and_unit_lordo',
],
CAMPI_PRODUCTINFO_RICOPIA_DATI: [
'old_code',
],
PRODUCTINFO: {
CAMPI_FIRST_UPPERCASE: [
'name',