- ordinamento per Data

This commit is contained in:
Surya Paolo
2024-06-21 16:11:03 +02:00
parent c3cc344b9f
commit 1c7b89a55b
7 changed files with 51 additions and 48 deletions

View File

@@ -366,7 +366,7 @@ router.post('/import', authenticate, async (req, res) => {
}
let versione = 0;
let arrversioni = [];
productInfo.productTypes = [];
// console.log('indprod', indprod, 'arrversGM', arrversGM, 'versione', product.Versione);
@@ -374,48 +374,36 @@ router.post('/import', authenticate, async (req, res) => {
for (let i = 0; i < arrversGM.length; i++) {
// Download, DVD, Epub, Mobi, Nuovo, PDF, Streaming, Usato
if (arrversGM[i] === 'Nuovo')
versione = shared_consts.VERSIONE.NUOVO
vers = shared_consts.PRODUCTTYPE.NUOVO
else if (arrversGM[i] === 'Usato')
versione = shared_consts.VERSIONE.USATO;
vers = shared_consts.PRODUCTTYPE.USATO;
else if (arrversGM[i] === 'Download')
versione = shared_consts.VERSIONE.DOWNLOAD;
vers = shared_consts.PRODUCTTYPE.DOWNLOAD;
else if (arrversGM[i] === 'DVD')
versione = shared_consts.VERSIONE.DVD;
vers = shared_consts.PRODUCTTYPE.DVD;
else if (arrversGM[i] === 'Epub')
versione = shared_consts.VERSIONE.EPUB;
vers = shared_consts.PRODUCTTYPE.EPUB;
else if (arrversGM[i] === 'Mobi')
versione = shared_consts.VERSIONE.MOBI;
vers = shared_consts.PRODUCTTYPE.MOBI;
else if (arrversGM[i] === 'PDF')
versione = shared_consts.VERSIONE.PDF;
vers = shared_consts.PRODUCTTYPE.PDF;
else if (arrversGM[i] === 'Streaming')
versione = shared_consts.VERSIONE.STREAMING;
vers = shared_consts.PRODUCTTYPE.STREAMING;
arrversioni.push(versione);
if (i === 0) {
// salvati il primo, // nel 99,9% dei casi c'è solo 1 elemento (perchè queste sono tutte le variazioni)
versione = vers;
}
if (versione === shared_consts.VERSIONE.DOWNLOAD)
productInfo.productTypes.push(shared_consts.PRODUCTTYPE.DOWNLOAD);
else if (versione === shared_consts.VERSIONE.DVD)
productInfo.productTypes.push(shared_consts.PRODUCTTYPE.DVD);
else if (versione === shared_consts.VERSIONE.EPUB)
productInfo.productTypes.push(shared_consts.PRODUCTTYPE.EPUB);
else if (versione === shared_consts.VERSIONE.MOBI)
productInfo.productTypes.push(shared_consts.PRODUCTTYPE.MOBI);
else if (versione === shared_consts.VERSIONE.PDF)
productInfo.productTypes.push(shared_consts.PRODUCTTYPE.PDF);
else if (versione === shared_consts.VERSIONE.STREAMING)
productInfo.productTypes.push(shared_consts.PRODUCTTYPE.STREAMING);
else if (versione === shared_consts.VERSIONE.USATO)
productInfo.productTypes.push(shared_consts.PRODUCTTYPE.USATO);
else if (versione === shared_consts.VERSIONE.NUOVO)
productInfo.productTypes.push(shared_consts.PRODUCTTYPE.NUOVO);
productInfo.productTypes.push(vers);
}
/*if (productInfo.productTypes.length === 0) {
productInfo.productTypes.push(shared_consts.PRODUCTTYPE.LIBRO);
}*/
if (product.Data)
if (product.Data) {
productInfo.date_publishing = new Date(product.Data * 1000);
// convert data to timestamp
productInfo.date_publishing_ts = productInfo.date_publishing.getTime();
}
productInfo.name = productInfo.name.replace(/ - Usato$| - Nuovo$| - Epub$| - Ebook$| - Mobi$| - DVD$| - Streaming$| - Download$/, "");
@@ -621,7 +609,9 @@ router.post('/import', authenticate, async (req, res) => {
}
// cerca l'indice della versione in arrvariazioni
let ind = arrvariazioni.findIndex(x => arrversioni.includes(x.versione));
let ind = arrvariazioni.findIndex(x =>
x.versione === versione)
let nuovaVariazione = ind < 0;
//
@@ -632,7 +622,7 @@ router.post('/import', authenticate, async (req, res) => {
}
variazione.active = true; // ++ ??
variazione.arrversioni = arrversioni;
variazione.versione = versione;
variazione.status = product.Stato ? product.Stato : null;
variazione.price = product.price ? parseFloat(tools.convertPriceEurToValue(product.price)) : null;
variazione.sale_price = product.sale_price ? parseFloat(tools.convertPriceEurToValue(product.sale_price)) : null;