- Catalogo: Aggiunta di Schede
This commit is contained in:
@@ -4,6 +4,8 @@ const Schema = mongoose.Schema;
|
||||
const tools = require('../tools/general');
|
||||
const { ObjectID, ObjectId } = require('mongodb');
|
||||
|
||||
const { MySchedaSchema, scheletroScheda } = require('../models/myscheda');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
|
||||
@@ -46,6 +48,7 @@ const elemText = new Schema(
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
const catalogo = new Schema(
|
||||
{
|
||||
//++AddCATALOGO_FIELDS
|
||||
@@ -59,16 +62,28 @@ const catalogo = new Schema(
|
||||
widthpag: { type: Number },
|
||||
widthpagPrintable: { type: Number },
|
||||
width: { type: String },
|
||||
widthscheda: { type: String },
|
||||
height: { type: String },
|
||||
numschede_perRiga: { type: Number },
|
||||
numschede_perCol: { type: Number },
|
||||
margine_pagina: { type: String },
|
||||
margine_riga: { type: String },
|
||||
|
||||
first_page_img: { type: String },
|
||||
first_page_html: { type: String },
|
||||
first_page_width: { type: Number },
|
||||
first_page_height: { type: Number },
|
||||
last_page_img: { type: String },
|
||||
last_page_html: { type: String },
|
||||
last_page_height: { type: Number },
|
||||
last_page_width: { type: Number },
|
||||
|
||||
margine_paginaPrintable: { type: String },
|
||||
margine_rigaPrintable: { type: String },
|
||||
// formato: [{ type: String, default: '' }],
|
||||
// categoria: [{ type: String, default: '' }],
|
||||
|
||||
// -------------------
|
||||
arrSchede: [
|
||||
{
|
||||
scheda: scheletroScheda,
|
||||
order: { type: Number },
|
||||
numSchede: { type: Number },
|
||||
}
|
||||
],
|
||||
}
|
||||
);
|
||||
|
||||
@@ -79,6 +94,10 @@ const MyElemSchema = new Schema({
|
||||
path: {
|
||||
type: String,
|
||||
},
|
||||
oldpath: {
|
||||
type: String,
|
||||
},
|
||||
idPage: { type: String },
|
||||
type: {
|
||||
type: Number,
|
||||
},
|
||||
@@ -237,6 +256,79 @@ MyElemSchema.statics.executeQueryTable = function (idapp, params, user) {
|
||||
return tools.executeQueryTable(this, idapp, params, user);
|
||||
};
|
||||
|
||||
MyElemSchema.statics.SetIdPageInsteadThePah = async function (idapp) {
|
||||
const MyElem = this;
|
||||
|
||||
const { MyPage } = require('../models/mypage');
|
||||
|
||||
// Sostituisci path con IdPage
|
||||
try {
|
||||
// Recupera tutti i documenti di MyPage
|
||||
const pages = await MyPage.find({ idapp }); // Puoi anche specificare condizioni, se necessario
|
||||
|
||||
// Utilizza una mappa per accoppiare i path con i loro Id
|
||||
const pathToIdMap = {};
|
||||
pages.forEach(page => {
|
||||
pathToIdMap[page.path] = page._id; // Mappa il path all'ID del documento MyPage
|
||||
});
|
||||
|
||||
// Aggiorna MyElem utilizzando la mappa
|
||||
for (const [path, id] of Object.entries(pathToIdMap)) {
|
||||
await MyElem.updateMany(
|
||||
{ path: path }, // Condizione per aggiornare dove il path corrisponde
|
||||
{
|
||||
$set: {
|
||||
idPage: id,
|
||||
oldpath: path,
|
||||
},
|
||||
$unset: { path: "" } // Rimuove il campo path
|
||||
} // Imposta IdPage all'ID del documento corrispondente
|
||||
);
|
||||
}
|
||||
|
||||
if (false) {
|
||||
// Utilizza una mappa per accoppiare i path con i loro Id
|
||||
const pathToIdMap2 = {};
|
||||
pages.forEach(page => {
|
||||
pathToIdMap2[page.path] = page._id.toString(); // Mappa il path all'ID del documento MyPage
|
||||
});
|
||||
|
||||
// Aggiorna MyElem utilizzando la mappa
|
||||
for (const [path, id] of Object.entries(pathToIdMap2)) {
|
||||
await MyElem.updateMany(
|
||||
{ oldpath: path }, // Condizione per aggiornare dove il path corrisponde
|
||||
{
|
||||
$unset: { idPage: "" } // Rimuove il campo path
|
||||
} // Imposta IdPage all'ID del documento corrispondente
|
||||
);
|
||||
}
|
||||
|
||||
for (const [oldpath, id] of Object.entries(pathToIdMap2)) {
|
||||
await MyElem.updateMany(
|
||||
{ oldpath: oldpath }, // Condizione per aggiornare dove il path corrisponde
|
||||
{
|
||||
$set: { idPage: id }
|
||||
} // Imposta IdPage all'ID del documento corrispondente
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
console.log('Aggiornamenti effettuati con successo.');
|
||||
return 'Aggiornamenti effettuati con successo.';
|
||||
} catch (error) {
|
||||
console.error('Errore durante l\'aggiornamento:', error);
|
||||
return 'Errore durante l\'aggiornamento:', error;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
MyElemSchema.statics.deleteAllFromThisPage = async function (id) {
|
||||
const MyElem = this;
|
||||
|
||||
return MyElem.deleteMany({ idPage: id });
|
||||
|
||||
};
|
||||
MyElemSchema.statics.findAllIdApp = async function (idapp) {
|
||||
const MyElem = this;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user