- Creazione di un Nuovo Catalogo (e la sua relativa pagina), a partire da un modello ed un catalogo esistente.
- Aggiunta dei bottoni sul Ccatalogocard
This commit is contained in:
@@ -99,9 +99,9 @@ const MyElemSchema = new Schema({
|
|||||||
path: {
|
path: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
oldpath: {
|
/*oldpath: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},*/
|
||||||
idPage: { type: String },
|
idPage: { type: String },
|
||||||
type: {
|
type: {
|
||||||
type: Number,
|
type: Number,
|
||||||
|
|||||||
@@ -208,6 +208,7 @@ MyPageSchema.statics.findOnlyStruttRec = async function (idapp) {
|
|||||||
path: 1,
|
path: 1,
|
||||||
active: 1,
|
active: 1,
|
||||||
onlyif_logged: 1,
|
onlyif_logged: 1,
|
||||||
|
isTemplate: 1,
|
||||||
only_residenti: 1,
|
only_residenti: 1,
|
||||||
only_admin: 1,
|
only_admin: 1,
|
||||||
inmenu: 1,
|
inmenu: 1,
|
||||||
|
|||||||
@@ -476,6 +476,7 @@ class Macro {
|
|||||||
for (const recproduct of recproducts) {
|
for (const recproduct of recproducts) {
|
||||||
await this.elaboraProdotto(recproduct, opt);
|
await this.elaboraProdotto(recproduct, opt);
|
||||||
|
|
||||||
|
|
||||||
const sku = recproduct.IdArticolo;
|
const sku = recproduct.IdArticolo;
|
||||||
|
|
||||||
if (sku) {
|
if (sku) {
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ const _ = require('lodash');
|
|||||||
|
|
||||||
const { Catalog } = require('../models/catalog');
|
const { Catalog } = require('../models/catalog');
|
||||||
|
|
||||||
//GET /catalogs
|
const globalTables = require('../tools/globalTables');
|
||||||
|
|
||||||
router.post('/', auth_default, async function (req, res, next) {
|
router.post('/', auth_default, async function (req, res, next) {
|
||||||
const idapp = req.body.idapp;
|
const idapp = req.body.idapp;
|
||||||
const userId = req.body.userId;
|
const userId = req.body.userId;
|
||||||
@@ -46,4 +47,22 @@ router.get('/id/:id', async function (req, res) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
router.post('/addnew', authenticate, async function (req, res, next) {
|
||||||
|
const idapp = req.body.idapp;
|
||||||
|
const data = req.body.newCatalog;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const newrecs = await globalTables.addNewCatalog(idapp, data);
|
||||||
|
if (newrecs) {
|
||||||
|
return res.send({ code: server_constants.RIS_CODE_OK, data: newrecs });
|
||||||
|
} else {
|
||||||
|
return res.send({ code: server_constants.RIS_CODE_OK, data: null });
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error fetching catalog by ID:', e);
|
||||||
|
return res.status(400).send({ code: server_constants.RIS_CODE_ERR, msg: e.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
@@ -430,7 +430,7 @@ router.post('/settable', authenticate, async (req, res) => {
|
|||||||
} else {
|
} else {
|
||||||
if (
|
if (
|
||||||
(mydata['_id'] === undefined || mydata['_id'] === '' || (mytablerec.isNew && mydata['_id'] === 0)) &&
|
(mydata['_id'] === undefined || mydata['_id'] === '' || (mytablerec.isNew && mydata['_id'] === 0)) &&
|
||||||
(mytablerec._id === undefined || mytablerec._id === '0'|| mytablerec._id === 0)
|
(mytablerec._id === undefined || mytablerec._id === '0' || mytablerec._id === 0)
|
||||||
) {
|
) {
|
||||||
mytablerec._id = new ObjectId();
|
mytablerec._id = new ObjectId();
|
||||||
mydata._id = new ObjectId();
|
mydata._id = new ObjectId();
|
||||||
@@ -891,69 +891,6 @@ router.post('/getpage', async (req, res) => {
|
|||||||
return found;
|
return found;
|
||||||
});
|
});
|
||||||
|
|
||||||
async function duplicatePage(pageId, newpath) {
|
|
||||||
try {
|
|
||||||
// Trova il record di Page da duplicare
|
|
||||||
const pageToDuplicate = await MyPage.findById(pageId);
|
|
||||||
if (!pageToDuplicate) {
|
|
||||||
console.error('Page not found.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Crea una copia del record di Page
|
|
||||||
const newPage = new MyPage({
|
|
||||||
...pageToDuplicate.toObject(), // Converte il documento Moongose in oggetto
|
|
||||||
_id: new mongoose.Types.ObjectId(), // Genera un nuovo ID
|
|
||||||
// modifiche ai campi se necessario, per esempio:
|
|
||||||
path: newpath,
|
|
||||||
title: newpath,
|
|
||||||
inmenu: false,
|
|
||||||
active: true,
|
|
||||||
date_updated: new Date(),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Salva il nuovo record di Page
|
|
||||||
await newPage.save();
|
|
||||||
|
|
||||||
// Trova tutti gli elementi associati a Page da duplicare
|
|
||||||
const elemsToDuplicate = await MyElem.find({ idPage: pageId }).lean();
|
|
||||||
|
|
||||||
// Duplica ogni elemento utilizzando il nuovo idPath
|
|
||||||
const duplicates = elemsToDuplicate.map((elem) => {
|
|
||||||
const catalogo = elem.catalogo;
|
|
||||||
|
|
||||||
if (catalogo) {
|
|
||||||
for (const recscheda of catalogo.arrSchede) {
|
|
||||||
if (recscheda.scheda?.isTemplate) {
|
|
||||||
// Se è un template allora devo mettergli un altro ID !
|
|
||||||
recscheda.scheda._id = new mongoose.Types.ObjectId();
|
|
||||||
// recscheda.scheda.name = getNewFreeNameTemplate(recscheda.scheda?.name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (catalogo) elem.catalogo = { ...catalogo };
|
|
||||||
|
|
||||||
const newElem = new MyElem({
|
|
||||||
...elem, // Copia le proprietà dell'elemento
|
|
||||||
_id: new mongoose.Types.ObjectId(), // Genera un nuovo ID
|
|
||||||
idPage: newPage._id.toString(), // Imposta il nuovo campo IdPage
|
|
||||||
});
|
|
||||||
|
|
||||||
return newElem;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Salva tutti gli elementi duplicati
|
|
||||||
await MyElem.insertMany(duplicates);
|
|
||||||
|
|
||||||
console.log('Duplicazione completata con successo.');
|
|
||||||
return true;
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Errore durante la duplicazione:', error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function exportPage(idapp, pageId) {
|
async function exportPage(idapp, pageId) {
|
||||||
try {
|
try {
|
||||||
const myexp = {
|
const myexp = {
|
||||||
@@ -1144,8 +1081,8 @@ router.post('/duppage', authenticate, async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
let found = await MyPage.findOne({ idapp, path: mypath })
|
let found = await MyPage.findOne({ idapp, path: mypath })
|
||||||
.then(async (ris) => {
|
.then(async (ris) => {
|
||||||
const result = await duplicatePage(ris._id, newpath);
|
const result = await globalTables.duplicatePage(ris._id, newpath);
|
||||||
if (result) {
|
if (result && result.newpage) {
|
||||||
return res.send({ code: server_constants.RIS_CODE_OK, msg: '' });
|
return res.send({ code: server_constants.RIS_CODE_OK, msg: '' });
|
||||||
} else {
|
} else {
|
||||||
return res.send({ code: server_constants.RIS_CODE_ERR, msg: '' });
|
return res.send({ code: server_constants.RIS_CODE_ERR, msg: '' });
|
||||||
@@ -1693,6 +1630,19 @@ router.delete('/delrec/:table/:id', authenticate, async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tablename === 'catalogs') {
|
||||||
|
// Devo cancellare anche la pagina associato al Catalogo!
|
||||||
|
|
||||||
|
const myrec = await mytable.findOne({ _id: id }).lean();
|
||||||
|
if (myrec.idPageAssigned) {
|
||||||
|
await MyPage.deleteOne({ _id: myrec.idPageAssigned }).then((rec) => {
|
||||||
|
if (!rec) {
|
||||||
|
console.log('Errore cancellazione pagina associata al catalogo');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let ris = null;
|
let ris = null;
|
||||||
|
|
||||||
if (!cancellato) {
|
if (!cancellato) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const os = require('os');
|
const os = require('os');
|
||||||
const fs = require('fs'); // 👈 Usa il modulo promises
|
const fs = require('fs-extra'); // 👈 Usa il modulo promises
|
||||||
const xml2js = require('xml2js');
|
const xml2js = require('xml2js');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const WebSocket = require('ws');
|
const WebSocket = require('ws');
|
||||||
@@ -5762,10 +5762,9 @@ module.exports = {
|
|||||||
|
|
||||||
if (table === 'catalog') {
|
if (table === 'catalog') {
|
||||||
mydir = 'upload/cataloghi/';
|
mydir = 'upload/cataloghi/';
|
||||||
}
|
}
|
||||||
|
|
||||||
return mydir;
|
return mydir;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getURLImg(idapp, table, username, img, checkifExist) {
|
getURLImg(idapp, table, username, img, checkifExist) {
|
||||||
@@ -5773,12 +5772,8 @@ module.exports = {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// let dir = this.getdirByIdApp(idapp) + dirmain + '/' + this.getDirUpload();
|
// let dir = this.getdirByIdApp(idapp) + dirmain + '/' + this.getDirUpload();
|
||||||
let dir =
|
let dir = this.getdirByIdApp(idapp);
|
||||||
this.getdirByIdApp(idapp)
|
'/' + this.getDirUpload() + shared_consts.getDirectoryImgByTable(table, username) + dirmain;
|
||||||
'/' +
|
|
||||||
this.getDirUpload() +
|
|
||||||
shared_consts.getDirectoryImgByTable(table, username) +
|
|
||||||
dirmain;
|
|
||||||
|
|
||||||
img = dir + img;
|
img = dir + img;
|
||||||
|
|
||||||
@@ -6073,11 +6068,8 @@ module.exports = {
|
|||||||
|
|
||||||
if (aggiornatoimg?.filepath.includes('noimg.jpg')) {
|
if (aggiornatoimg?.filepath.includes('noimg.jpg')) {
|
||||||
// nascondi il prodotto se non trovo l'immagine !
|
// nascondi il prodotto se non trovo l'immagine !
|
||||||
await Product.updateOne(
|
await Product.updateOne({ idProductInfo: productInfo._id }, { $set: { deleted: true } });
|
||||||
{ idProductInfo: productInfo._id },
|
|
||||||
{ $set: { deleted: true } }
|
|
||||||
);
|
|
||||||
|
|
||||||
aggiornatoimg = { ris: false, deleted: true };
|
aggiornatoimg = { ris: false, deleted: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6199,7 +6191,16 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async attendiNSecondi(numsec) {
|
async attendiNSecondi(numsec) {
|
||||||
await new Promise(resolve => setTimeout(resolve, numsec * 1000));
|
await new Promise((resolve) => setTimeout(resolve, numsec * 1000));
|
||||||
|
},
|
||||||
|
|
||||||
|
async copyDirectory(sourceDir, destinationDir) {
|
||||||
|
try {
|
||||||
|
await fs.copy(sourceDir, destinationDir);
|
||||||
|
console.log('Directory copiata con successo!');
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Errore durante la copia della directory:', err);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
fixFilePath(myfilepath) {
|
fixFilePath(myfilepath) {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user