Cataloghi...

This commit is contained in:
Surya Paolo
2025-02-05 12:13:27 +01:00
parent 41d5f562ec
commit 2f92dfe5b0
13 changed files with 498 additions and 458 deletions

View File

@@ -42,13 +42,13 @@ const CatalogSchema = new Schema({
type: String,
},
foto_collana: Foto,
idCollana: {
type: String,
},
idCollane: [{
type: Number,
}],
descr_introduttiva: {
type: String,
},
idTemplateScheda: {
idPageAssigned: {
type: String,
},
referenti: [{
@@ -92,9 +92,24 @@ CatalogSchema.statics.executeQueryTable = function (idapp, params, user) {
CatalogSchema.statics.findAllIdApp = async function (idapp) {
const Catalog = this;
const myfind = { idapp };
const arrrec = await Catalog.aggregate([
// Filtra i documenti per idapp
{ $match: { idapp } },
const arrrec = await Catalog.find(myfind).lean().sort({ title: 1 });
// Ordina i risultati per titolo
{ $sort: { title: 1 } },
// Esegui il join con la collezione Collana
{
$lookup: {
from: "collanas", // Nome della collezione Collana
localField: "idCollane", // Campo in Catalog
foreignField: "idCollana", // Campo in Collana
as: "collana_info" // Nome del campo che conterrà i risultati del join
}
},
]);
return arrrec;
};

View File

@@ -18,10 +18,7 @@ const CollanaSchema = new Schema({
idCollana: {
type: Number,
},
descrizione: {
type: String,
},
descrizione_estesa: {
title: {
type: String,
},
dataOra: {

View File

@@ -60,7 +60,7 @@ const catalogo = new Schema(
excludeproductTypes: [{ type: Number }],
editore: [{ type: String }],
argomenti: [{ type: String }],
idCollana: { type: Number },
idCollane: [{ type: Number }],
sort_field: { type: String },
sort_dir: { type: Number },
pdf: { type: Boolean },
@@ -361,7 +361,21 @@ MyElemSchema.statics.findAllIdApp = async function (idapp) {
const myfind = { idapp };
const arrrec = await MyElem.find(myfind).lean().sort({ order: 1 });
const aggiorna = false;
let arrrec = null;
if (aggiorna) {
arrrec = await MyElem.find(myfind).sort({ order: 1 });
for (const elem of arrrec) {
if (elem.heightimg === 'NaNpx') {
elem.heightimg = '';
await elem.save();
}
}
} else {
arrrec = await MyElem.find(myfind).lean().sort({ order: 1 });
}
return arrrec;
};
@@ -374,13 +388,13 @@ MyElemSchema.statics.findallSchedeTemplate = async function (idapp) {
const ris = await MyElem.find({ idapp }).lean();
const schedeTemplate = ris.flatMap(elem =>
elem.catalogo && elem.catalogo.arrSchede ?
elem.catalogo && elem.catalogo.arrSchede ?
elem.catalogo.arrSchede
.filter(scheda => scheda.scheda?.isTemplate)
.map(scheda => ({
...scheda, // mantieni i dati originali della scheda
idPageOrig: elem.idPage // aggiungi l'idPage
}))
}))
: []
);

View File

@@ -130,7 +130,7 @@ const scheletroScheda = {
excludeproductTypes: [{ type: Number }],
editore: [{ type: String }],
argomenti: [{ type: String }],
idCollana: { type: Number },
idCollane: [{ type: Number }],
author: { type: String },
sort_field: { type: String },
sort_dir: { type: Number },

View File

@@ -870,6 +870,9 @@ UserSchema.statics.findByCredentials = function (idapp, username, password, pwdc
UserSchema.statics.findByUsername = async function (idapp, username, alsoemail, onlyifVerifiedByAportador) {
const User = this;
if (!username)
return null;
const myreg = ['^', username, '$'].join('');
let regexusername = new RegExp(myreg, 'i');