Cataloghi...

This commit is contained in:
Surya Paolo
2025-02-05 12:13:27 +01:00
parent 41d5f562ec
commit 2f92dfe5b0
13 changed files with 498 additions and 458 deletions

View File

@@ -42,13 +42,13 @@ const CatalogSchema = new Schema({
type: String, type: String,
}, },
foto_collana: Foto, foto_collana: Foto,
idCollana: { idCollane: [{
type: String, type: Number,
}, }],
descr_introduttiva: { descr_introduttiva: {
type: String, type: String,
}, },
idTemplateScheda: { idPageAssigned: {
type: String, type: String,
}, },
referenti: [{ referenti: [{
@@ -92,9 +92,24 @@ CatalogSchema.statics.executeQueryTable = function (idapp, params, user) {
CatalogSchema.statics.findAllIdApp = async function (idapp) { CatalogSchema.statics.findAllIdApp = async function (idapp) {
const Catalog = this; const Catalog = this;
const myfind = { idapp }; const arrrec = await Catalog.aggregate([
// Filtra i documenti per idapp
{ $match: { idapp } },
const arrrec = await Catalog.find(myfind).lean().sort({ title: 1 }); // Ordina i risultati per titolo
{ $sort: { title: 1 } },
// Esegui il join con la collezione Collana
{
$lookup: {
from: "collanas", // Nome della collezione Collana
localField: "idCollane", // Campo in Catalog
foreignField: "idCollana", // Campo in Collana
as: "collana_info" // Nome del campo che conterrà i risultati del join
}
},
]);
return arrrec; return arrrec;
}; };

View File

@@ -18,10 +18,7 @@ const CollanaSchema = new Schema({
idCollana: { idCollana: {
type: Number, type: Number,
}, },
descrizione: { title: {
type: String,
},
descrizione_estesa: {
type: String, type: String,
}, },
dataOra: { dataOra: {

View File

@@ -60,7 +60,7 @@ const catalogo = new Schema(
excludeproductTypes: [{ type: Number }], excludeproductTypes: [{ type: Number }],
editore: [{ type: String }], editore: [{ type: String }],
argomenti: [{ type: String }], argomenti: [{ type: String }],
idCollana: { type: Number }, idCollane: [{ type: Number }],
sort_field: { type: String }, sort_field: { type: String },
sort_dir: { type: Number }, sort_dir: { type: Number },
pdf: { type: Boolean }, pdf: { type: Boolean },
@@ -361,7 +361,21 @@ MyElemSchema.statics.findAllIdApp = async function (idapp) {
const myfind = { idapp }; const myfind = { idapp };
const arrrec = await MyElem.find(myfind).lean().sort({ order: 1 }); const aggiorna = false;
let arrrec = null;
if (aggiorna) {
arrrec = await MyElem.find(myfind).sort({ order: 1 });
for (const elem of arrrec) {
if (elem.heightimg === 'NaNpx') {
elem.heightimg = '';
await elem.save();
}
}
} else {
arrrec = await MyElem.find(myfind).lean().sort({ order: 1 });
}
return arrrec; return arrrec;
}; };

View File

@@ -130,7 +130,7 @@ const scheletroScheda = {
excludeproductTypes: [{ type: Number }], excludeproductTypes: [{ type: Number }],
editore: [{ type: String }], editore: [{ type: String }],
argomenti: [{ type: String }], argomenti: [{ type: String }],
idCollana: { type: Number }, idCollane: [{ type: Number }],
author: { type: String }, author: { type: String },
sort_field: { type: String }, sort_field: { type: String },
sort_dir: { type: Number }, sort_dir: { type: Number },

View File

@@ -870,6 +870,9 @@ UserSchema.statics.findByCredentials = function (idapp, username, password, pwdc
UserSchema.statics.findByUsername = async function (idapp, username, alsoemail, onlyifVerifiedByAportador) { UserSchema.statics.findByUsername = async function (idapp, username, alsoemail, onlyifVerifiedByAportador) {
const User = this; const User = this;
if (!username)
return null;
const myreg = ['^', username, '$'].join(''); const myreg = ['^', username, '$'].join('');
let regexusername = new RegExp(myreg, 'i'); let regexusername = new RegExp(myreg, 'i');

View File

@@ -134,56 +134,56 @@ module.exports = {
{ {
"_id": ObjectId("515a353c002c8298f4495bf7"), "_id": ObjectId("515a353c002c8298f4495bf7"),
"idapp": "13", "idapp": "13",
"label" : "Dono", "label": "🎁 Dono",
"__v": 0 "__v": 0
}, },
{ {
"_id": ObjectId("51bc466567de9a1f54b254f4"), "_id": ObjectId("51bc466567de9a1f54b254f4"),
"idapp": "13", "idapp": "13",
"label" : "Offerta Libera", "label": "💸 Offerta Libera",
"__v": 0 "__v": 0
}, },
{ {
"_id": ObjectId("51bc454867de9a1f54b254f2"), "_id": ObjectId("51bc454867de9a1f54b254f2"),
"idapp": "13", "idapp": "13",
"label" : "Baratto", "label": "🤝 Baratto",
"__v": 0 "__v": 0
}, },
{ {
"_id": ObjectId("51bc482667de9a1f54b25412"), "_id": ObjectId("51bc482667de9a1f54b25412"),
"idapp": "13", "idapp": "13",
"label" : "Scambio Lavoro", "label": "💪 Scambio Lavoro",
"__v": 0 "__v": 0
}, },
{ {
"_id": ObjectId("51bc482667de9a1f64b254ab"), "_id": ObjectId("51bc482667de9a1f64b254ab"),
"idapp": "13", "idapp": "13",
"label" : "Monete Alternative", "label": "🪙 Monete Alternative",
"__v": 0 "__v": 0
}, },
{ {
"_id": ObjectId("51bc482667de9a1f64b254ac"), "_id": ObjectId("51bc482667de9a1f64b254ac"),
"idapp": "13", "idapp": "13",
"label" : "RIS", "label": "🍚 RIS",
"__v": 0 "__v": 0
}, },
{ {
"_id": ObjectId("51bc482667de9a1f64b254fb"), "_id": ObjectId("51bc482667de9a1f64b254fb"),
"idapp": "13", "idapp": "13",
"label" : "Euro", "label": "💶 Euro",
"__v": 0 "__v": 0
}, },
{ {
"_id": ObjectId("51bc482667de9a1f64b254ff"), "_id": ObjectId("51bc482667de9a1f64b254ff"),
"idapp": "13", "idapp": "13",
"label" : "Bitcoin", "label": "Bitcoin",
"__v": 0 "__v": 0
}, },
{ {
"_id": ObjectId("51bc482667de9a1f64b255ff"), "_id": ObjectId("51bc482667de9a1f64b255ff"),
"idapp": "13", "idapp": "13",
"label" : "Banca del Tempo", "label": "Banca del Tempo",
"__v": 0 "__v": 0
}, }
] ]
} }

View File

@@ -776,7 +776,6 @@ router.post('/import', authenticate, async (req, res) => {
let imported = 0; let imported = 0;
let errors = 0; let errors = 0;
const ripopola = true; const ripopola = true;
if (ripopola) { if (ripopola) {
@@ -901,7 +900,8 @@ router.post('/import', authenticate, async (req, res) => {
} }
// Aggiorna la collana solo se non è stata già impostata nel record attuale // Aggiorna la collana solo se non è stata già impostata nel record attuale
if (recproductInfoAttuale && !recproductInfoAttuale.idCollana && product.DescrizioneCollana) { //if (recproductInfoAttuale && !recproductInfoAttuale.idCollana && product.DescrizioneCollana) {
if (recproductInfoAttuale && product.DescrizioneCollana) {
const idCollanaNum = parseInt(product.IdCollana) const idCollanaNum = parseInt(product.IdCollana)
productInfo.idCollana = idCollanaNum; productInfo.idCollana = idCollanaNum;
@@ -909,7 +909,7 @@ router.post('/import', authenticate, async (req, res) => {
if (!reccollana) { if (!reccollana) {
try { try {
// Non esiste questa collana, quindi la creo ! // Non esiste questa collana, quindi la creo !
reccoll = new Collana({ idapp, idCollana: idCollanaNum, descrizione: product.DescrizioneCollana }); reccoll = new Collana({ idapp, idCollana: idCollanaNum, title: product.DescrizioneCollana });
ris = await reccoll.save(); ris = await reccoll.save();
} catch (e) { } catch (e) {
console.error('Err', e); console.error('Err', e);

View File

@@ -220,6 +220,8 @@ router.post(process.env.LINK_REQUEST_NEWPASSWORD, async (req, res) => {
// Invio la Nuova Password richiesta dal reset! // Invio la Nuova Password richiesta dal reset!
// Ritorna il token per poter effettuare le chiamate... // Ritorna il token per poter effettuare le chiamate...
router.post(process.env.LINK_UPDATE_PWD, async (req, res) => { router.post(process.env.LINK_UPDATE_PWD, async (req, res) => {
try {
const body = _.pick(req.body, ['idapp', 'email', 'tokenforgot', 'tokenforgot_code', 'password']); const body = _.pick(req.body, ['idapp', 'email', 'tokenforgot', 'tokenforgot_code', 'password']);
const idapp = body.idapp; const idapp = body.idapp;
const email = body.email.toLowerCase().trim(); const email = body.email.toLowerCase().trim();
@@ -227,6 +229,7 @@ router.post(process.env.LINK_UPDATE_PWD, async (req, res) => {
const tokenforgot_code = body.tokenforgot_code; const tokenforgot_code = body.tokenforgot_code;
const password = body.password; const password = body.password;
const msg = 'Richiesta Nuova Password: idapp= ' + idapp + ' email = ' + email; const msg = 'Richiesta Nuova Password: idapp= ' + idapp + ' email = ' + email;
console.log(msg); console.log(msg);
// telegrambot.sendMsgTelegramToTheManagers(body.idapp, msg); // telegrambot.sendMsgTelegramToTheManagers(body.idapp, msg);
@@ -272,6 +275,10 @@ router.post(process.env.LINK_UPDATE_PWD, async (req, res) => {
}); });
}); });
} }
} catch (e) {
console.error('Error: ', e);
}
}); });
router.post('/testServer', authenticate_noerror, async (req, res) => { router.post('/testServer', authenticate_noerror, async (req, res) => {

View File

@@ -87,6 +87,7 @@ router.post('/test1', async (req, res) => {
// POST /users // POST /users
router.post('/', async (req, res) => { router.post('/', async (req, res) => {
try {
tools.mylog('POST /users'); tools.mylog('POST /users');
const body = _.pick(req.body, [ const body = _.pick(req.body, [
'email', 'email',
@@ -389,6 +390,10 @@ router.post('/', async (req, res) => {
console.error(e.message); console.error(e.message);
res.status(400).send(e); res.status(400).send(e);
}); });
} catch (e) {
console.error(e.message);
}
}); });
router.get('/:idapp/:username', async (req, res) => { router.get('/:idapp/:username', async (req, res) => {

View File

@@ -1043,11 +1043,11 @@ function startServer(app, port) {
ws.send(JSON.stringify({ type: 'output', data: data })); ws.send(JSON.stringify({ type: 'output', data: data }));
// Controlla se c'è una richiesta di input // Controlla se c'è una richiesta di input
if (buffer.endsWith(': ') || buffer.includes('? ') || if (buffer && (buffer.endsWith(': ') || buffer.includes('? ') ||
buffer.toLowerCase().includes('password') buffer.toLowerCase().includes('password')
|| buffer.includes('Inserisci') || buffer.includes('Inserisci')
|| buffer.includes('Inserted') || buffer.includes('Inserted')
|| buffer.includes('(Y') || buffer.includes('(Y'))
) { ) {
ws.send(JSON.stringify({ type: 'input_required', prompt: data.trim() })); ws.send(JSON.stringify({ type: 'input_required', prompt: data.trim() }));
buffer = ''; buffer = '';

View File

@@ -927,7 +927,7 @@ const MyTelegramBot = {
let useraportador = await User.getUserShortDataByUsername(idapp, userDest); let useraportador = await User.getUserShortDataByUsername(idapp, userDest);
if (useraportador && useraportador.tokenreg && (regexpire.toLowerCase() === useraportador.tokenreg.toLowerCase())) { if (useraportador && useraportador.tokenreg && useraportador.tokenreg && (regexpire && (regexpire?.toLowerCase() === useraportador.tokenreg?.toLowerCase()))) {
const nonchiedereverifica = await User.getifRegTokenIsValid(idapp, useraportador.tokenreg); const nonchiedereverifica = await User.getifRegTokenIsValid(idapp, useraportador.tokenreg);
if (nonchiedereverifica) if (nonchiedereverifica)
notask_verif = true; notask_verif = true;
@@ -2103,7 +2103,7 @@ class Telegram {
// await this.menumsg_to_Nave(msg, cmd2); // await this.menumsg_to_Nave(msg, cmd2);
// } else if (testo === Menu.MSG_SI_INVITATI_NO_7REQ_INVITATI) { // } else if (testo === Menu.MSG_SI_INVITATI_NO_7REQ_INVITATI) {
// await this.menumsg_Si_Invitati_No_7Req(msg); // await this.menumsg_Si_Invitati_No_7Req(msg);
} else if (cmd1.toLowerCase() === Menu.MSG_TO_USER) { } else if (cmd1 && cmd1.toLowerCase() === Menu.MSG_TO_USER) {
await this.menumsg_A_Utente(msg); await this.menumsg_A_Utente(msg);
} else if (testo === Menu.SETPICPROFILE) { } else if (testo === Menu.SETPICPROFILE) {
await this.setPhotoProfile(rec.user, msg.from.id); await this.setPhotoProfile(rec.user, msg.from.id);
@@ -2838,7 +2838,7 @@ class Telegram {
async setUsernameInvitante(msg) { async setUsernameInvitante(msg) {
try { try {
let mymsg = msg.text.toString().trim().toLowerCase(); let mymsg = msg.text?.toString().trim().toLowerCase();
let nomeapp = tools.getNomeAppByIdApp(this.idapp); let nomeapp = tools.getNomeAppByIdApp(this.idapp);
@@ -3271,7 +3271,7 @@ class Telegram {
getInvitanteByMsg(msg) { getInvitanteByMsg(msg) {
try { try {
let mymsg = msg.text.toString().trim().toLowerCase(); let mymsg = msg.text?.toString().trim().toLowerCase();
let invitante = ''; let invitante = '';
let regexpire = ''; let regexpire = '';
const sep = '-' const sep = '-'
@@ -3324,8 +3324,7 @@ class Telegram {
} }
const rec = this.getRecInMem(msg); const rec = this.getRecInMem(msg);
let testo = msg.text.toLowerCase().trim(); let testo = msg.text?.toLowerCase().trim();
status = this.getstatus(rec); status = this.getstatus(rec);
if (testo === Menu.EXIT_TELEGRAM) { if (testo === Menu.EXIT_TELEGRAM) {
@@ -3389,7 +3388,7 @@ class Telegram {
rec.chatId = msg.chat.id; rec.chatId = msg.chat.id;
rec.messageId = msg.message_id; rec.messageId = msg.message_id;
rec.msgall_status = StatusMSGALL.CONFIRM; rec.msgall_status = StatusMSGALL.CONFIRM;
const cmd = rec.msgtosent.toLowerCase(); const cmd = rec?.msgtosent?.toString().toLowerCase() ?? '';
let achi = this.getDestinStr(msg, rec.msgall_achi, rec); let achi = this.getDestinStr(msg, rec.msgall_achi, rec);
let domanda = ''; let domanda = '';
if (rec.msgall_domanda) { if (rec.msgall_domanda) {
@@ -3716,7 +3715,7 @@ class Telegram {
for (const rec of recuser.menuDb) { for (const rec of recuser.menuDb) {
if (rec.active_mem) { if (rec.active_mem) {
if (rec.idapp === idapp && rec.lang === lang && if (rec.idapp === idapp && rec.lang === lang &&
rec.label.toLowerCase() === testo) { rec.label?.toLowerCase() === testo) {
return true; return true;
} }
} }
@@ -3800,7 +3799,7 @@ class Telegram {
for (const recdb of recuser.menuDb) { for (const recdb of recuser.menuDb) {
if (recdb.active_mem) { if (recdb.active_mem) {
if (recdb.idapp === idapp && recdb.lang === lang && if (recdb.idapp === idapp && recdb.lang === lang &&
recdb.label.toLowerCase() === testo) { recdb.label?.toLowerCase() === testo) {
if (recdb.type === shared_consts.BOTTYPE_BOTTONI_INLINE) { if (recdb.type === shared_consts.BOTTYPE_BOTTONI_INLINE) {
const jsonString = '[{"text": "primo", "callback_data": "1"}, {"text": "sec", "callback_data": "2"}]'; const jsonString = '[{"text": "primo", "callback_data": "1"}, {"text": "sec", "callback_data": "2"}]';
const jsonObject = JSON.parse(jsonString); const jsonObject = JSON.parse(jsonString);

View File

@@ -5396,7 +5396,7 @@ module.exports = {
contatto = ''; contatto = '';
} }
} }
if ((myrec.contact_telegram && myrec.contact_telegram.toLowerCase() !== contatto_telegram.toLowerCase()) || !contatto) { if ((myrec.contact_telegram && myrec.contact_telegram?.toLowerCase() !== contatto_telegram?.toLowerCase()) || !contatto) {
contatto += '\n' + myrec.contact_telegram; contatto += '\n' + myrec.contact_telegram;
} }
/*if (myrec.contact_phone) { /*if (myrec.contact_phone) {
@@ -5709,7 +5709,7 @@ module.exports = {
const allElements = document.body.querySelectorAll('*'); const allElements = document.body.querySelectorAll('*');
allElements.forEach(element => { allElements.forEach(element => {
const tagName = element.tagName.toLowerCase(); const tagName = element.tagName?.toLowerCase();
if (!allowedTags.includes(tagName)) { if (!allowedTags.includes(tagName)) {
// Crea un nodo di testo e sostituisci l'elemento con quel nodo di testo // Crea un nodo di testo e sostituisci l'elemento con quel nodo di testo

View File

@@ -274,7 +274,7 @@ module.exports = {
{ table: 'catgrps', key: 'descr' }, { table: 'catgrps', key: 'descr' },
{ {
table: 'contribtypes', table: 'contribtypes',
key: 'descr', keyOLD: 'descr',
}, },
{ table: 'goods', key: 'descr', key2: 'idSectorGood' }, { table: 'goods', key: 'descr', key2: 'idSectorGood' },
{ table: 'levels', key: 'descr' }, { table: 'levels', key: 'descr' },