- piuchebuono: possiblità di modificare l'immagine dalla scheda direttamente
- migliorata di poco la grafica dell'immagine.
This commit is contained in:
@@ -73,9 +73,15 @@ const productInfoSchema = new Schema({
|
||||
icon: {
|
||||
type: String,
|
||||
},
|
||||
img: { // Se esiste img (sul server) visualizza questa, altrimenti vedi se esiste image_link
|
||||
img: {
|
||||
type: String,
|
||||
},
|
||||
imagefile: {
|
||||
type: String,
|
||||
},
|
||||
vers_img: {
|
||||
type: Number,
|
||||
},
|
||||
image_link: {
|
||||
type: String,
|
||||
},
|
||||
@@ -221,7 +227,54 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
|
||||
module.exports.getProductByCode = function (idapp, code) {
|
||||
return productInfo.findAllIdApp(idapp, code);
|
||||
}
|
||||
module.exports.correggiProductTypes = async function() {
|
||||
module.exports.replaceProductImgToImageFile = async function () {
|
||||
const ProductInfo = this;
|
||||
|
||||
let abilitaserver = false;
|
||||
|
||||
if (abilitaserver) {
|
||||
// const result = await ProductInfo.updateMany({ "img": { $exists: true } }, { $rename: { 'img': 'imagefile' } });
|
||||
|
||||
// Trova tutti i documenti con il campo 'img' che esiste
|
||||
const documents = await ProductInfo.find({ "img": { $exists: true } });
|
||||
|
||||
// Aggiorna ciascun documento
|
||||
for (let doc of documents) {
|
||||
if (doc.img && doc.img.startsWith('/upload/products/')) {
|
||||
// Rimuovi il prefisso '/upload/products' dal campo `img`
|
||||
doc.imagefile = doc.img.replace(/^\/upload\/products\//, '');
|
||||
doc.img = undefined; // Può anche rimuovere il campo img corrente se desiderato
|
||||
await doc.save(); // Salva il documento aggiornato
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Updated ${documents.length} document(s) with new imagefile paths.`);
|
||||
|
||||
} else {
|
||||
const documents = await ProductInfo.find({ "imagefile": { $exists: true } });
|
||||
|
||||
// Aggiorna ciascun documento
|
||||
for (let doc of documents) {
|
||||
if (doc.imagefile && doc.imagefile.startsWith('upload/products/')) {
|
||||
// Rimuovi il prefisso '/upload/products' dal campo `img`
|
||||
doc.imagefile = doc.imagefile.replace(/^\upload\/products\//, '');
|
||||
await doc.save(); // Salva il documento aggiornato
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Updated ${documents.length} document(s) with new imagefile paths.`);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
await ProductInfo.updateMany({}, { 'vers_img': 0 });
|
||||
|
||||
console.log(`Updated ${result.modifiedCount} document(s).`);
|
||||
|
||||
};
|
||||
|
||||
module.exports.correggiProductTypes = async function () {
|
||||
const ProductInfo = this;
|
||||
const bulkOps = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user