- Cataloghi aggiornamento...

This commit is contained in:
Surya Paolo
2025-02-11 18:57:57 +01:00
parent f674791dbc
commit b643c7cdc3
7 changed files with 88 additions and 13 deletions

View File

@@ -24,10 +24,6 @@ const CatalogSchema = new Schema({
type: Boolean, type: Boolean,
default: false, default: false,
}, },
versione_perstampa: {
type: Boolean,
default: false,
},
title: { title: {
type: String, type: String,
}, },
@@ -35,6 +31,9 @@ const CatalogSchema = new Schema({
idCollane: [{ idCollane: [{
type: Number, type: Number,
}], }],
argomenti: [{
type: String,
}],
editore: [{ type: String }], editore: [{ type: String }],
descr_introduttiva: { descr_introduttiva: {
type: String, type: String,
@@ -42,12 +41,17 @@ const CatalogSchema = new Schema({
idPageAssigned: { idPageAssigned: {
type: String, type: String,
}, },
idPageAssigned_stampa: {
type: String,
},
referenti: [{ referenti: [{
type: String, type: String,
}], }],
img_bordata: IImg, img_bordata: IImg,
img_intro: IImg, img_intro: IImg,
img_bordata_stampa: IImg,
img_intro_stampa: IImg,
pagina_introduttiva_sfondo_nero: { pagina_introduttiva_sfondo_nero: {
type: Boolean, type: Boolean,
}, },
@@ -70,6 +74,8 @@ const CatalogSchema = new Schema({
}, },
}); });
/*
TOLTO ALTRIMENTI su /settable non mi crea l'ID
CatalogSchema.pre('save', async function (next) { CatalogSchema.pre('save', async function (next) {
if (this.isNew) { if (this.isNew) {
this._id = new ObjectId(); this._id = new ObjectId();
@@ -77,6 +83,7 @@ CatalogSchema.pre('save', async function (next) {
next(); next();
}); });
*/
CatalogSchema.statics.getFieldsForSearch = function () { CatalogSchema.statics.getFieldsForSearch = function () {
return [{ field: 'title', type: tools.FieldType.string }] return [{ field: 'title', type: tools.FieldType.string }]

View File

@@ -37,7 +37,7 @@ var Collana = module.exports = mongoose.model('Collana', CollanaSchema);
module.exports.getFieldsForSearch = function () { module.exports.getFieldsForSearch = function () {
return [ return [
{ field: 'descrizione', type: tools.FieldType.string }, { field: 'title', type: tools.FieldType.string },
] ]
}; };
@@ -49,7 +49,7 @@ module.exports.executeQueryTable = function (idapp, params) {
module.exports.findAllIdApp = async function (idapp) { module.exports.findAllIdApp = async function (idapp) {
const myfind = { idapp }; const myfind = { idapp };
return await Collana.find(myfind).sort({descrizione: 1}); return await Collana.find(myfind).sort({title: 1}).lean();
}; };
module.exports.createIndexes((err) => { module.exports.createIndexes((err) => {

View File

@@ -68,6 +68,7 @@ const catalogo = new Schema(
pdf_filename: { type: String }, pdf_filename: { type: String },
printable: { type: Boolean }, printable: { type: Boolean },
indebug: { type: Boolean }, indebug: { type: Boolean },
maxnumlibri: { type: Number },
first_page: IDimensioni, first_page: IDimensioni,
last_page: IDimensioni, last_page: IDimensioni,
@@ -381,11 +382,40 @@ MyElemSchema.statics.findAllIdApp = async function (idapp) {
return arrrec; return arrrec;
}; };
async function deleteOldMyElems(idapp) {
try {
const { MyPage } = require('../models/mypage');
// 1. Recupera tutti gli _id dalle pagine
const existingPages = await MyPage.find({idapp}).select('_id').lean();
const existingPageIds = existingPages.map(page => page._id.toString());
// 2. Trova gli MyElem che hanno idPage non esistenti in MyPage
const elemsToDelete = await MyElem.find({
idapp,
idPage: { $nin: existingPageIds }
});
if (elemsToDelete.length > 0) {
// 3. Esegui la cancellazione
const result = await MyElem.deleteMany({ idPage: { $nin: existingPageIds } });
console.log(`Cancellati ${result.deletedCount} documenti di MyElem.`);
} else {
console.log('Nessun documento da cancellare.');
}
} catch (error) {
console.error('Errore durante la cancellazione dei documenti:', error);
}
}
MyElemSchema.statics.findallSchedeTemplate = async function (idapp) { MyElemSchema.statics.findallSchedeTemplate = async function (idapp) {
const MyElem = this; const MyElem = this;
try { try {
const { MyPage } = require('../models/mypage');
const ris = await MyElem.find({ idapp }).lean(); const ris = await MyElem.find({ idapp }).lean();
const schedeTemplate = ris.flatMap(elem => const schedeTemplate = ris.flatMap(elem =>
@@ -399,6 +429,45 @@ MyElemSchema.statics.findallSchedeTemplate = async function (idapp) {
: [] : []
); );
const duplicateIds = schedeTemplate.reduce((acc, scheda) => {
const id = scheda.scheda._id; // Ottieni l'ID della scheda
if (!acc[id]) {
acc[id] = []; // Inizializza un array per tenere traccia delle pagine
}
acc[id].push(scheda.idPageOrig); // Aggiungi l'idPage all'array
return acc;
}, {});
// Filtra i duplicati
const duplicates = Object.entries(duplicateIds)
.filter(([_, pages]) => pages.length > 1) // Mantieni solo gli ID con più di un'istanza
.map(([id, pages]) => ({ id, pages })); // Ottieni ID e pagine corrispondenti
// Recupera i dettagli delle pagine
const pageIds = duplicates.flatMap(dup => dup.pages); // Estrai tutti gli idPage
const pages = await MyPage.find({ idapp, _id: { $in: pageIds } }).lean();
// Crea una mappatura tra idPage e title
const pageMap = pages.reduce((acc, page) => {
acc[page._id] = page.title; // Mappa idPage a title
return acc;
}, {});
// Associa i titoli delle pagine agli ID duplicati
const resultWithTitles = duplicates.map(dup => ({
id: dup.id,
pages: dup.pages.map(_id => ({
_id,
title: pageMap[_id] || 'Titolo non trovato' // Usa la mappatura per trovare il titolo
}))
}));
if (resultWithTitles.length > 0) {
console.log('Duplicati e titoli delle pagine:', JSON.stringify(resultWithTitles, null, 2));
await deleteOldMyElems(idapp);
}
return schedeTemplate; return schedeTemplate;
} catch (e) { } catch (e) {
console.error('Err', e); console.error('Err', e);
@@ -420,6 +489,7 @@ MyElemSchema.statics.getNewFreeNameTemplate = async function (idapp, idPageOrig,
{ {
'catalogo.arrSchede.scheda.name': 1, 'catalogo.arrSchede.scheda.name': 1,
'catalogo.arrSchede.scheda.isTemplate': 1, 'catalogo.arrSchede.scheda.isTemplate': 1,
'catalogo.arrSchede.scheda.isPagIntro': 1,
'catalogo.arrSchede.scheda.idPage': 1 'catalogo.arrSchede.scheda.idPage': 1
}); });

View File

@@ -166,7 +166,7 @@ MyPageSchema.statics.findAllIdApp = async function (idapp) {
return await MyPage.find(myfind, (err, arrrec) => { return await MyPage.find(myfind, (err, arrrec) => {
return arrrec return arrrec
}); }).sort({ title: 1 }).lean();
}; };
MyPageSchema.statics.findOnlyStruttRec = async function (idapp) { MyPageSchema.statics.findOnlyStruttRec = async function (idapp) {
@@ -229,7 +229,7 @@ MyPageSchema.statics.findInternalPages = async function (idapp) {
only_residenti: 1, only_residenti: 1,
}, (err, arrrec) => { }, (err, arrrec) => {
return arrrec return arrrec
}); }).lean();
}; };
const MyPage = mongoose.model('MyPage', MyPageSchema); const MyPage = mongoose.model('MyPage', MyPageSchema);

View File

@@ -42,7 +42,7 @@ module.exports.executeQueryTable = function (idapp, params) {
module.exports.findAllIdApp = async function (idapp) { module.exports.findAllIdApp = async function (idapp) {
const myfind = { idapp }; const myfind = { idapp };
return await Publisher.find(myfind); return await Publisher.find(myfind).sort({ name: 1 }).lean();
}; };
module.exports.createIndexes((err) => { module.exports.createIndexes((err) => {

View File

@@ -682,7 +682,7 @@ router.post('/getobj', authenticate_noerror, async (req, res) => {
perm: { $bitsAnySet: 0b10000 }, perm: { $bitsAnySet: 0b10000 },
}, },
{ username: 1, name: 1, surname: 1 } { username: 1, name: 1, surname: 1 }
).lean(); ).sort({ username: 1 }).lean();
} }
// Invia la risposta // Invia la risposta
@@ -905,8 +905,6 @@ async function duplicatePage(pageId, newpath) {
} }
} }
let newelem = { ...elem };
if (catalogo) if (catalogo)
elem.catalogo = { ...catalogo }; elem.catalogo = { ...catalogo };

View File

@@ -1 +1 @@
1.1.20 1.1.21