- Cataloghi

- Import ed Export Pagine
- ObjectID sostituita con ObjectId
This commit is contained in:
Surya Paolo
2024-12-17 17:55:47 +01:00
parent 14b3e18986
commit 300bab2125
91 changed files with 404 additions and 272 deletions

View File

@@ -2,7 +2,7 @@ const mongoose = require('mongoose').set('debug', false)
const Schema = mongoose.Schema;
const tools = require('../tools/general');
const { ObjectID, ObjectId } = require('mongodb');
const { ObjectId } = require('mongodb');
const { MySchedaSchema, IDimensioni, IImg, IText, IAreaDiStampa } = require('../models/myscheda');
@@ -246,7 +246,7 @@ const MyElemSchema = new Schema({
MyElemSchema.pre('save', async function (next) {
if (this.isNew) {
this._id = new ObjectID();
this._id = new ObjectId();
}
next();
@@ -280,16 +280,19 @@ MyElemSchema.statics.SetIdPageInsteadThePah = async function (idapp) {
// 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 (path) {
await MyElem.updateMany(
{ idapp },
{ 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) {
@@ -319,6 +322,21 @@ MyElemSchema.statics.SetIdPageInsteadThePah = async function (idapp) {
}
}
const pathToIdMap2 = {};
pages.forEach(page => {
pathToIdMap2[page.path] = page._id.toString(); // Mappa il path all'ID del documento MyPage
});
for (const [oldpath, id] of Object.entries(pathToIdMap2)) {
await MyElem.updateMany(
{ idapp },
{ 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.';
@@ -340,7 +358,9 @@ MyElemSchema.statics.findAllIdApp = async function (idapp) {
const myfind = { idapp };
return await MyElem.find(myfind).sort({ order: 1 });
const arrrec = await MyElem.find(myfind).sort({ order: 1 });
return arrrec;
};
MyElemSchema.statics.findallSchedeTemplate = async function (idapp) {