- 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

@@ -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","18"]
appTelegram=["1","17","18"]
DOMAIN=mongodb://localhost:27017/
AUTH_MONGODB=1
MONGODB_USER=admin

View File

@@ -49,9 +49,9 @@ const catalogo = new Schema(
//++AddCATALOGO_FIELDS
productTypes: [{ type: Number }],
excludeproductTypes: [{ type: Number }],
Editore: [{ type: String }],
// formato: [{ type: String, default: '' }],
// categoria: [{ type: String, default: '' }],
// Editore: [{ type: String, default: '' }],
}
);

View File

@@ -61,9 +61,9 @@ const productSchema = new Schema({
active: {
type: Boolean,
},
arrversioni: [{
versione: {
type: Number,
}],
},
status: { //publish
type: String,
},
@@ -500,6 +500,20 @@ module.exports.findAllIdApp = async function (idapp, code, id, all) {
as: 'productInfo.authors'
}
},
{
$lookup: {
from: 'publishers',
localField: 'productInfo.idPublisher',
foreignField: '_id',
as: 'productInfo.publisher'
}
},
{
$unwind: {
path: '$productInfo.publisher',
preserveNullAndEmptyArrays: true,
},
},
{
$lookup: {
from: 'catprods',

View File

@@ -117,6 +117,9 @@ const productInfoSchema = new Schema({
date_publishing: {
type: Date,
},
date_publishing_ts: {
type: Number,
},
productTypes: [{
type: Number,
}],

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 (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);
if (i === 0) {
// salvati il primo, // nel 99,9% dei casi c'è solo 1 elemento (perchè queste sono tutte le variazioni)
versione = vers;
}
/*if (productInfo.productTypes.length === 0) {
productInfo.productTypes.push(shared_consts.PRODUCTTYPE.LIBRO);
}*/
productInfo.productTypes.push(vers);
}
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;

View File

@@ -74,6 +74,7 @@ const SubCatProd = require('../models/subcatprod');
const Gasordine = require('../models/gasordine');
const Product = require('../models/product');
const Author = require('../models/author');
const Publisher = require('../models/publisher');
const ProductInfo = require('../models/productInfo');
const Scontistica = require('../models/scontistica');
const Department = require('../models/department');
@@ -1366,6 +1367,7 @@ router.post('/duprec/:table/:id', authenticate, async (req, res) => {
tools.mylog('DUPLICATED ', rec);
// Do extra things after deleted
return await actions.doOtherThingsAfterDuplicated(tablename, rec).
then(({ myrec }) => {
@@ -1425,6 +1427,7 @@ function load(req, res, version) {
// tools.mylog('loadsite : ', req.params);
let bookedevent = [];
// let msgs = [];
@@ -1490,6 +1493,7 @@ function load(req, res, version) {
}
let products = Product.findAllIdApp(idapp, undefined, undefined, ismanager);
let authors = Author.findAllIdApp(idapp);
let publishers = Publisher.findAllIdApp(idapp);
let productInfos = ProductInfo.findAllIdApp(idapp);
let scontisticas = Scontistica.findAllIdApp(idapp);
let departments = Department.findAllIdApp(idapp);
@@ -1587,6 +1591,7 @@ function load(req, res, version) {
catprods_gas,
catAI,
authors,
publishers,
]).then((arrdata) => {
// console.table(arrdata);
let myuser = req.user;
@@ -1680,6 +1685,7 @@ function load(req, res, version) {
catAI: arrdata[48],
code: req.code,
authors: arrdata[49],
publishers: arrdata[50],
});
const prova = 1;

View File

@@ -1104,15 +1104,5 @@ module.exports = {
},
// Download, DVD, Epub, Mobi, Nuovo, PDF, Streaming, Usato
VERSIONE: {
NUOVO: 1,
USATO: 2,
DOWNLOAD: 3,
DVD: 4,
EPUB: 5,
MOBI: 6,
PDF: 7,
STREAMING: 8,
},
};