- aggiornamento Cataloghi

- Gestione delle versioni del prodotto ("Nuovi","Usati","Epub", ecc..)
This commit is contained in:
Surya Paolo
2024-06-20 17:16:56 +02:00
parent 8dbdad1e02
commit c3cc344b9f
6 changed files with 136 additions and 45 deletions

View File

@@ -44,6 +44,17 @@ const elemText = new Schema(
} }
); );
const catalogo = new Schema(
{
//++AddCATALOGO_FIELDS
productTypes: [{ type: Number }],
excludeproductTypes: [{ type: Number }],
// formato: [{ type: String, default: '' }],
// categoria: [{ type: String, default: '' }],
// Editore: [{ type: String, default: '' }],
}
);
const MyElemSchema = new Schema({ const MyElemSchema = new Schema({
_id: { _id: {
type: ObjectId, type: ObjectId,
@@ -164,6 +175,7 @@ const MyElemSchema = new Schema({
type: String, type: String,
}, },
listcards: [myCard], listcards: [myCard],
catalogo: catalogo,
list: [ list: [
{ {
imagefile: { imagefile: {

View File

@@ -61,9 +61,9 @@ const productSchema = new Schema({
active: { active: {
type: Boolean, type: Boolean,
}, },
versione: { arrversioni: [{
type: Number, type: Number,
}, }],
status: { //publish status: { //publish
type: String, type: String,
}, },

View File

@@ -88,6 +88,9 @@ const productInfoSchema = new Schema({
checkout_link: { checkout_link: {
type: String, type: String,
}, },
versioneGM: {
type: String,
},
img2: { img2: {
type: String, type: String,
}, },
@@ -114,9 +117,9 @@ const productInfoSchema = new Schema({
date_publishing: { date_publishing: {
type: Date, type: Date,
}, },
productType: { productTypes: [{
type: Number, type: Number,
}, }],
}); });
@@ -215,6 +218,51 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
module.exports.getProductByCode = function (idapp, code) { module.exports.getProductByCode = function (idapp, code) {
return productInfo.findAllIdApp(idapp, code); return productInfo.findAllIdApp(idapp, code);
} }
module.exports.correggiProductTypes = async function() {
const ProductInfo = this;
const bulkOps = [];
try {
// Fase di aggregazione
const cursor = ProductInfo.aggregate([
{
$project: {
_id: 1,
productType: 1,
productTypes: [{ $ifNull: ['$productType', 10] }]
}
}
]).cursor({ batchSize: 1000 }).exec();
// Itera attraverso ogni documento utilizzando il cursore
for await (const doc of cursor) {
bulkOps.push({
updateOne: {
filter: { _id: doc._id },
update: {
$set: { productTypes: doc.productTypes },
$unset: { productType: "" }
}
}
});
// Scrivi i batch di operazioni ogni 1000 documenti
if (bulkOps.length === 1000) {
await ProductInfo.bulkWrite(bulkOps);
bulkOps.length = 0;
}
}
// Scrivi eventuali operazioni rimanenti
if (bulkOps.length > 0) {
await ProductInfo.bulkWrite(bulkOps);
}
console.log('ProductInfo.productType converted to productTypes array and saved');
} catch (err) {
console.error('Error converting ProductInfo.productType:', err);
}
}
module.exports.createIndexes((err) => { module.exports.createIndexes((err) => {
if (err) throw err; if (err) throw err;

View File

@@ -99,7 +99,7 @@ async function completaSettaggioProduct_AndProductInfo(arrcampi_productInfo, arr
productInfo.img = 'upload/products/' + rec['img']; productInfo.img = 'upload/products/' + rec['img'];
} else { } else {
productInfo.img = ''; productInfo.img = '';
} }
} }
} }
@@ -119,10 +119,10 @@ async function completaSettaggioProduct_AndProductInfo(arrcampi_productInfo, arr
productInfo.code = preccode; productInfo.code = preccode;
} }
} }
if (rec.hasOwnProperty('productType')) { if (rec.hasOwnProperty('productTypes')) {
productInfo.productType = rec.hasOwnProperty('productType'); productInfo.productTypes = productInfo.productTypes;
} else { } else {
productInfo.productType = shared_consts.PRODUCTTYPE.PRODUCT; productInfo.productTypes = [shared_consts.PRODUCTTYPE.PRODUCT];
} }
return { product, productInfo }; return { product, productInfo };
@@ -339,6 +339,11 @@ router.post('/import', authenticate, async (req, res) => {
importa = false; importa = false;
if (importa) { if (importa) {
let versGM = product.Versione ? product.Versione : '';
// split versioneGM in array with separated ","
let arrversGM = versGM.split(",").map(x => x.trim());
let productInfo = { let productInfo = {
idapp: product.idapp, idapp: product.idapp,
code: product.isbn, code: product.isbn,
@@ -361,41 +366,53 @@ router.post('/import', authenticate, async (req, res) => {
} }
let versione = 0; let versione = 0;
let arrversioni = [];
// Download, DVD, Epub, Mobi, Nuovo, PDF, Streaming, Usato productInfo.productTypes = [];
if (product.Versione === 'Nuovo') // console.log('indprod', indprod, 'arrversGM', arrversGM, 'versione', product.Versione);
versione = shared_consts.VERSIONE.NUOVO
else if (product.Versione === 'Usato')
versione = shared_consts.VERSIONE.USATO;
else if (product.Versione === 'Download')
versione = shared_consts.VERSIONE.DOWNLOAD;
else if (product.Versione === 'DVD')
versione = shared_consts.VERSIONE.DVD;
else if (product.Versione === 'Epub')
versione = shared_consts.VERSIONE.EPUB;
else if (product.Versione === 'Mobi')
versione = shared_consts.VERSIONE.MOBI;
else if (product.Versione === 'PDF')
versione = shared_consts.VERSIONE.PDF;
else if (product.Versione === 'Streaming')
versione = shared_consts.VERSIONE.STREAMING;
else
versione = 100;
if (versione === shared_consts.VERSIONE.DOWNLOAD) for (let i = 0; i < arrversGM.length; i++) {
productInfo.productType = shared_consts.PRODUCTTYPE.DOWNLOAD; // Download, DVD, Epub, Mobi, Nuovo, PDF, Streaming, Usato
else if (versione === shared_consts.VERSIONE.DVD) if (arrversGM[i] === 'Nuovo')
productInfo.productType = shared_consts.PRODUCTTYPE.DVD; versione = shared_consts.VERSIONE.NUOVO
else if (versione === shared_consts.VERSIONE.EPUB) else if (arrversGM[i] === 'Usato')
productInfo.productType = shared_consts.PRODUCTTYPE.EPUB; versione = shared_consts.VERSIONE.USATO;
else if (versione === shared_consts.VERSIONE.MOBI) else if (arrversGM[i] === 'Download')
productInfo.productType = shared_consts.PRODUCTTYPE.MOBI; versione = shared_consts.VERSIONE.DOWNLOAD;
else if (versione === shared_consts.VERSIONE.PDF) else if (arrversGM[i] === 'DVD')
productInfo.productType = shared_consts.PRODUCTTYPE.PDF; versione = shared_consts.VERSIONE.DVD;
else if (versione === shared_consts.VERSIONE.STREAMING) else if (arrversGM[i] === 'Epub')
productInfo.productType = shared_consts.PRODUCTTYPE.STREAMING; versione = shared_consts.VERSIONE.EPUB;
else else if (arrversGM[i] === 'Mobi')
productInfo.productType = shared_consts.PRODUCTTYPE.LIBRO; versione = shared_consts.VERSIONE.MOBI;
else if (arrversGM[i] === 'PDF')
versione = shared_consts.VERSIONE.PDF;
else if (arrversGM[i] === 'Streaming')
versione = shared_consts.VERSIONE.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 (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); productInfo.date_publishing = new Date(product.Data * 1000);
@@ -604,7 +621,7 @@ router.post('/import', authenticate, async (req, res) => {
} }
// cerca l'indice della versione in arrvariazioni // cerca l'indice della versione in arrvariazioni
let ind = arrvariazioni.findIndex(x => x.versione === versione); let ind = arrvariazioni.findIndex(x => arrversioni.includes(x.versione));
let nuovaVariazione = ind < 0; let nuovaVariazione = ind < 0;
// //
@@ -615,7 +632,7 @@ router.post('/import', authenticate, async (req, res) => {
} }
variazione.active = true; // ++ ?? variazione.active = true; // ++ ??
variazione.versione = versione; variazione.arrversioni = arrversioni;
variazione.status = product.Stato ? product.Stato : null; variazione.status = product.Stato ? product.Stato : null;
variazione.price = product.price ? parseFloat(tools.convertPriceEurToValue(product.price)) : null; variazione.price = product.price ? parseFloat(tools.convertPriceEurToValue(product.price)) : null;
variazione.sale_price = product.sale_price ? parseFloat(tools.convertPriceEurToValue(product.sale_price)) : null; variazione.sale_price = product.sale_price ? parseFloat(tools.convertPriceEurToValue(product.sale_price)) : null;
@@ -770,7 +787,7 @@ router.post('/import', authenticate, async (req, res) => {
img: 'upload/products/' + product.code + '.jpg', img: 'upload/products/' + product.code + '.jpg',
weight: product.weight, weight: product.weight,
unit: tools.getIdUnitsByText(product.unit), unit: tools.getIdUnitsByText(product.unit),
productType: shared_consts.PRODUCTTYPE.PRODUCT, productTypes: shared_consts.PRODUCTTYPE.PRODUCT,
} }
let reccateg = null; let reccateg = null;

View File

@@ -36,9 +36,9 @@ const { authenticate, authenticate_noerror } = require('../middleware/authentica
const Cart = require('../models/cart'); const Cart = require('../models/cart');
const CartClass = require('../modules/Cart'); const CartClass = require('../modules/Cart');
const Product = require('../models/product'); const Product = require('../models/product');
const ProductInfo = require('../models/productInfo');
const CatProd = require('../models/catprod'); const CatProd = require('../models/catprod');
const SubCatProd = require('../models/subcatprod'); const SubCatProd = require('../models/subcatprod');
const ProductInfo = require('../models/productInfo');
const Order = require('../models/order'); const Order = require('../models/order');
const OrdersCart = require('../models/orderscart'); const OrdersCart = require('../models/orderscart');
const Variant = require('../models/variant'); const Variant = require('../models/variant');
@@ -1623,6 +1623,10 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
await Circuit.createCircuitIfNotExist(req, idapp, recprov.prov); await Circuit.createCircuitIfNotExist(req, idapp, recprov.prov);
} }
} else if (mydata.dbop === 'correggiProductTypes') {
await ProductInfo.correggiProductTypes();
} else if (mydata.dbop === 'correggiCircuitiANull') { } else if (mydata.dbop === 'correggiCircuitiANull') {

View File

@@ -1091,6 +1091,16 @@ module.exports = {
AUDIOLIBRO: 22, AUDIOLIBRO: 22,
VIDEO: 23, VIDEO: 23,
CARTE: 25, CARTE: 25,
// -----------
NUOVO: 101,
USATO: 102,
DOWNLOAD: 103,
DVD: 104,
EPUB: 105,
MOBI: 106,
PDF: 107,
STREAMING: 108,
}, },
// Download, DVD, Epub, Mobi, Nuovo, PDF, Streaming, Usato // Download, DVD, Epub, Mobi, Nuovo, PDF, Streaming, Usato