- catalogo
- corretto logica del RefreshToken che non richiedeva il nuovo token, quindi scadeva tutte le volte, richiedendo sempre l'accesso !
This commit is contained in:
@@ -58,8 +58,11 @@ const catalogo = new Schema(
|
||||
//++AddCATALOGO_FIELDS
|
||||
productTypes: [{ type: Number }],
|
||||
excludeproductTypes: [{ type: Number }],
|
||||
Editore: [{ type: String }],
|
||||
sort: { type: Number },
|
||||
editore: [{ type: String }],
|
||||
argomenti: [{ type: String }],
|
||||
idCollana: { type: Number },
|
||||
sort_field: { type: String },
|
||||
sort_dir: { type: Number },
|
||||
pdf: { type: Boolean },
|
||||
pdf_filename: { type: String },
|
||||
printable: { type: Boolean },
|
||||
@@ -282,7 +285,7 @@ MyElemSchema.statics.SetIdPageInsteadThePah = async function (idapp) {
|
||||
for (const [path, id] of Object.entries(pathToIdMap)) {
|
||||
if (path) {
|
||||
await MyElem.updateMany(
|
||||
{ idapp },
|
||||
{ idapp },
|
||||
{ path: path }, // Condizione per aggiornare dove il path corrisponde
|
||||
{
|
||||
$set: {
|
||||
@@ -329,7 +332,7 @@ MyElemSchema.statics.SetIdPageInsteadThePah = async function (idapp) {
|
||||
|
||||
for (const [oldpath, id] of Object.entries(pathToIdMap2)) {
|
||||
await MyElem.updateMany(
|
||||
{ idapp },
|
||||
{ idapp },
|
||||
{ oldpath: oldpath }, // Condizione per aggiornare dove il path corrisponde
|
||||
{
|
||||
$set: { idPage: id }
|
||||
@@ -358,7 +361,7 @@ MyElemSchema.statics.findAllIdApp = async function (idapp) {
|
||||
|
||||
const myfind = { idapp };
|
||||
|
||||
const arrrec = await MyElem.find(myfind).sort({ order: 1 });
|
||||
const arrrec = await MyElem.find(myfind).lean().sort({ order: 1 });
|
||||
|
||||
return arrrec;
|
||||
};
|
||||
@@ -368,32 +371,68 @@ MyElemSchema.statics.findallSchedeTemplate = async function (idapp) {
|
||||
|
||||
try {
|
||||
|
||||
const ris = await MyElem.find({ idapp });
|
||||
const ris = await MyElem.find({ idapp }).lean();
|
||||
|
||||
// Estrai le schede che hanno isTemplate = true
|
||||
const schedeTemplate = ris.flatMap(elem =>
|
||||
elem.catalogo && elem.catalogo.arrSchede ? elem.catalogo.arrSchede.filter(scheda => scheda.scheda?.isTemplate) : []
|
||||
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
|
||||
}))
|
||||
: []
|
||||
);
|
||||
|
||||
/*
|
||||
// Trova tutti i documenti in cui idapp corrisponde e contiene schede con isTemplate = true
|
||||
const ris = await MyElem.find(
|
||||
{ idapp },
|
||||
{ 'catalogo.arrSchede': { $elemMatch: { isTemplate: true } } }
|
||||
).populate('catalogo.arrSchede');
|
||||
|
||||
// Estrai solo le schede che hanno isTemplate = true
|
||||
const schedeTemplate = ris.flatMap(elem =>
|
||||
elem.catalogo.arrSchede.filter(scheda => scheda.isTemplate)
|
||||
);
|
||||
*/
|
||||
|
||||
return schedeTemplate;
|
||||
} catch (e) {
|
||||
console.error('Err', e);
|
||||
}
|
||||
};
|
||||
|
||||
// Ricerca tra tutte le schede, contenute in catalogo, se esiste un nome di template uguale,
|
||||
// se non lo trova allora è quello giusto per crearne uno nuovo
|
||||
MyElemSchema.statics.getNewFreeNameTemplate = async function (idapp, idPageOrig, nomeTemplate) {
|
||||
const MyElem = this;
|
||||
|
||||
try {
|
||||
const ris = await MyElem.find(
|
||||
{
|
||||
idapp,
|
||||
'catalogo.arrSchede.scheda.isTemplate': true,
|
||||
'catalogo.arrSchede.scheda.idPage': { $ne: idPageOrig }
|
||||
},
|
||||
{
|
||||
'catalogo.arrSchede.scheda.name': 1,
|
||||
'catalogo.arrSchede.scheda.isTemplate': 1,
|
||||
'catalogo.arrSchede.scheda.idPage': 1
|
||||
});
|
||||
|
||||
const existingNames = new Set(
|
||||
ris.flatMap(elem =>
|
||||
elem.catalogo?.arrSchede?.filter(scheda =>
|
||||
scheda.scheda?.isTemplate &&
|
||||
scheda.scheda?.idPage !== idPageOrig
|
||||
)
|
||||
.map(scheda => scheda.scheda?.name) || []
|
||||
)
|
||||
);
|
||||
|
||||
let ind = 2;
|
||||
let newNameTemplate;
|
||||
|
||||
do {
|
||||
newNameTemplate = `${nomeTemplate}_copia_${ind}`;
|
||||
ind++;
|
||||
} while (existingNames.has(newNameTemplate) && ind <= 1000);
|
||||
|
||||
return newNameTemplate;
|
||||
} catch (e) {
|
||||
console.error('Err', e);
|
||||
throw e; // Propagate the error
|
||||
}
|
||||
};
|
||||
|
||||
const MyElem = mongoose.model('MyElem', MyElemSchema);
|
||||
|
||||
MyElem.createIndexes((err) => {
|
||||
|
||||
Reference in New Issue
Block a user