- inizio di modifiche all'editor di Pagine Web
This commit is contained in:
@@ -14,6 +14,9 @@ const Author = require('../models/author');
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const { MyPage } = require('../models/mypage');
|
||||
const { MyElem } = require('../models/myelem');
|
||||
|
||||
const axios = require('axios');
|
||||
|
||||
router.post('/test-lungo', authenticate, (req, res) => {
|
||||
@@ -195,19 +198,20 @@ router.delete('/mypage/:id', authenticate, async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
|
||||
|
||||
|
||||
// Trova il record di MyPage da cancellare
|
||||
const pageToDelete = await MyPage.findByIdAndRemove(id);
|
||||
const pageToDelete = await MyPage.findByIdAndDelete(id);
|
||||
|
||||
if (!pageToDelete) return res.status(404).json({ error: 'Pagina non trovata' });
|
||||
if (!pageToDelete) {
|
||||
return res.status(404).json({ error: 'Pagina non trovata' });
|
||||
} else {
|
||||
await MyElem.deleteAllFromThisPage(id);
|
||||
}
|
||||
|
||||
res.json({ message: `Pagina eliminata con successo: ${pageToDelete.path}` });
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
res.status(500).json({ error: 'Errore durante l\'eliminazione della pagina' });
|
||||
res.status(500).json({ error: "Errore durante l'eliminazione della pagina" });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -487,5 +491,4 @@ router.post('/chatbot', authenticate, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -906,8 +906,22 @@ router.post('/savepage', authenticate, async (req, res) => {
|
||||
const mypage = params.page;
|
||||
|
||||
try {
|
||||
if (mypage?._id) {
|
||||
let found = await MyPage.findOneAndUpdate({ idapp, _id: mypage._id }, mypage, { upsert: true, new: true })
|
||||
if (!mypage?._id) {
|
||||
// creazione nuovo record
|
||||
return await MyPage.create({ idapp, ...mypage })
|
||||
.then((ris) => {
|
||||
if (ris) {
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, mypage: ris });
|
||||
}
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, msg: '' });
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(e.message);
|
||||
res.status(400).send(e);
|
||||
});
|
||||
} else {
|
||||
// update record
|
||||
return await MyPage.findOneAndUpdate({ idapp, _id: mypage._id }, mypage, { upsert: true, new: true })
|
||||
.then((ris) => {
|
||||
if (ris) {
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, mypage: ris });
|
||||
@@ -2303,7 +2317,11 @@ async function uploadFile(req, res, version, options = {}) {
|
||||
console.log('File ricevuto:', file.originalFilename);
|
||||
|
||||
const oldFile = file.filepath || file.path;
|
||||
const newFilePath = path.join(uploadDir, `${file.newFilename}_${file.originalFilename}`);
|
||||
//const newFilePath = path.join(uploadDir, `${file.newFilename}_${file.originalFilename}`);
|
||||
const newFilePath = path.join(uploadDir, `${file.originalFilename}`);
|
||||
|
||||
//@@ATTENZIONE ! HO RIMESSO COM'ERA PRIMA ! MA NON MI CONVINCE !
|
||||
// RICONTROLLARE SE DEVO METTERLGI UN SUFFISSO PRIMA... (newFilePath)
|
||||
|
||||
// Sposta e rinomina
|
||||
await tools.move(oldFile, newFilePath);
|
||||
|
||||
Reference in New Issue
Block a user