- Modifiche a ProductInfo... Continua

This commit is contained in:
Surya Paolo
2025-08-29 23:34:08 +02:00
parent 2ee710b748
commit fcbc64cea8
24 changed files with 1006 additions and 1010 deletions

View File

@@ -194,25 +194,29 @@ CatalogSchema.statics.getCatalogById = async function (id) {
try {
let arrrec = await Catalog.find({ _id: id })
.populate({
path: 'lista_prodotti', // Popola il campo lista_prodotti
populate: {
path: 'idProductInfo',
model: 'ProductInfo',
populate: [
{
path: 'idCatProds',
model: 'CatProd',
},
{
path: 'idSubCatProds',
model: 'SubCatProd',
},
{
path: 'idAuthors',
model: 'Author',
},
],
},
path: 'lista_prodotti',
populate: [
{
path: 'productInfo.idCatProds',
model: 'CatProd',
},
{
path: 'productInfo.idSubCatProds',
model: 'SubCatProd',
},
{
path: 'productInfo.idAuthors',
model: 'Author',
},
{
path: 'productInfo.idCollana',
model: 'Collana',
},
{
path: 'productInfo.idPublisher',
model: 'Publisher',
},
],
})
.populate({
path: 'lista_prodotti',
@@ -254,11 +258,11 @@ CatalogSchema.statics.getCatalogById = async function (id) {
const originalLength = catalog.lista_prodotti.length;
catalog.lista_prodotti = catalog.lista_prodotti.filter(
(product) =>
product.idProductInfo &&
product.idProductInfo.code &&
product.idProductInfo.code !== '' &&
product.idProductInfo.imagefile &&
product.idProductInfo.imagefile !== 'noimg.jpg' &&
product.productInfo &&
product.productInfo.code &&
product.productInfo.code !== '' &&
product.productInfo.imagefile &&
product.productInfo.imagefile !== 'noimg.jpg' &&
!product.delete
);
if (catalog.lista_prodotti.length !== originalLength) {
@@ -272,17 +276,16 @@ CatalogSchema.statics.getCatalogById = async function (id) {
lista_prodotti: catalog.lista_prodotti.map((product) => ({
...product.toObject(),
productInfo: {
...product.idProductInfo.toObject(), // Copia tutti i campi di idProductInfo
catprods: product.idProductInfo.idCatProds, // Rinomina idCatProds in catprods
subcatprods: product.idProductInfo.idSubCatProds,
collana: product.idProductInfo.idCollana,
authors: product.idProductInfo.idAuthors,
...product.productInfo,
catprods: product.productInfo.idCatProds,
subcatprods: product.productInfo.idSubCatProds,
collana: product.productInfo.idCollana,
authors: product.productInfo.idAuthors,
},
producer: product.idProducer,
storehouse: product.idStorehouses,
scontisticas: product.idScontisticas,
gasordine: product.idGasordine,
idProductInfo: product.idProductInfo._id, // CHECK
})),
}));