diff --git a/docs/passi.txt b/docs/passi.txt index 7708482..4d42b9e 100644 --- a/docs/passi.txt +++ b/docs/passi.txt @@ -3,20 +3,14 @@ AGGIORNARE: // ++Todo: DA FARE: +- Se sei imbarcata i tuoi due invitati usati per quella posizione sono bloccati. Se ne hai in più li puoi regalare + - Mettere il tragitto anche sul BOT. + + TESTARE -> inviare il msg anche al Sognatore della Gift Chat -X - Aggiornare il titolo della Gift Chat (da 5/5 a 12/5) -X - Aggiornare il testo sulla Placca (Data Inizio e Data Fine Doni) // ++Todo: SISTEMARE: - X - Devo comparire come mio invitato se aggiungo un nuovo Viaggio. - X - Fare la lista delle Navi (in alto alla Lavagna) con il loro tragitto. - X- Nel campo note, metterci il Sogno - X - Se nave Temporanea, mettere Info. - X- Mettere flag se si vuole spostare l'Utente oppure Aggiungerlo... - - - Mettere Sfondo immagine su ogni nave - - Mettere il tragitto anche sul BOT. x- AGGIONARE AMBIENTE DI TEST @@ -28,7 +22,7 @@ x - Sistemare le navi con num_tess === 4 : indorder=0 e 46 : ------------- - AGGIONARE AMBIENTE DI PRODUZIONE -- ESEGUIRE LA CONVERSIONE 1 E 2 ! +- ESEGUIRE LA CONVERSIONE 1 E 2 e ! - Sistemare le navi con num_tess === 4 : indorder=0 e 46 : Prendere quelli del num_tess === 3 e SOSTITUISCI ind_order del num_Tess = 4 con ind_order di num_tess = 3 @@ -52,3 +46,38 @@ SOSTITUISCI: TRADURRE: - Mettere le bandierine nella lista Zoom (su AYNI BOT). + + +1- mi appaiono prima le navi del secondo account +2- forse metterei ogni nave seguita dal relativo viaggio di "ritorno" (a me piace chiamarlo così!) +X 3- sotto le navi, alla voce donatore, c'è ancora scritto "Effettuerai il tuo dono ESATTAMENTE il giorno indicato" +X 4- nei miei invitati non compaiono le mie ritessiture, fatte con il magico bottone, da chi sono invitata? + + +- Controllare Tragitto (Elisabetta) +- Monica Sozzi -> Davide Moirano (0) è giusto. + - Andrea Decouter (2) + - Enrica Pescio (OK) + - 852 (Gerico2) Elio2 Garelli -> (Gerico) + +Andrea 346 + +ind_order: 231 Gerico Elio Garelli +ind_order: 852 Gerico2 Elio2 Garelli + + +Morgana Roveta (Maelabo) + --- Gerico Elio Garelli + + +ANDREA + |-----GERICO2 852 + + + +.update({}, {$unset: {$ind_order: 1}, {multi: true}); + + + + + diff --git a/docs/query_mongodb.js b/docs/query_mongodb.js new file mode 100644 index 0000000..c948710 --- /dev/null +++ b/docs/query_mongodb.js @@ -0,0 +1,28 @@ +db.getCollection('users').aggregate([ + { $match: { idapp: '7', username:'Emycapp' } }, + { + $lookup: { + from: "naves", + as: "ingr", + let: { ind_order: '$ind_order' }, + pipeline: [ + { + $match: { + $expr: { + $and: [ + { $eq: ['$ind_order', '$$ind_order'] }, + ] + } + } + } + ] + } + }, + { + $replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$ingr", 0] }, "$$ROOT"] } } + }, + { + $match: { made_gift: { $exists: true } } + } + +]) diff --git a/src/server/models/listaingresso.js b/src/server/models/listaingresso.js index 99078c0..678f594 100755 --- a/src/server/models/listaingresso.js +++ b/src/server/models/listaingresso.js @@ -43,6 +43,9 @@ const ListaIngressoSchema = new mongoose.Schema({ date_added: { type: Date, }, + date_deleted: { + type: Date, + }, added: { // Added into Programmation (Nave) type: Boolean, default: false, @@ -311,6 +314,50 @@ function getQueryProj(myfilter, myobjField, myfilter2, mygroup) { return query; } +function getQueryIndOrder(myfilter, myobjField, myfilter2, mygroup) { + const query = [ + { $match: myfilter }, + { + $lookup: { + from: "users", + as: "user", + let: { ind_order: '$ind_order' }, + pipeline: [ + { + $match: { + $expr: { + $and: [ + { $eq: ['$ind_order', '$$ind_order'] }, + { $eq: ['$idapp', myfilter.idapp] }, + ] + } + } + } + ] + } + }, + { + $replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] }, "$$ROOT"] } } + }, + { $match: myfilter2 }, + ]; + + if (!!mygroup) { + query.push( + { $group: mygroup } + ); + } + + if (!!myobjField) { + query.push( + { $project: myobjField } + ); + } + + return query; +} + + ListaIngressoSchema.statics.getPosizioneInLista = async function (idapp, arrrec, ind_order, num_tess) { @@ -338,9 +385,11 @@ ListaIngressoSchema.statics.showListaOrd = async function (idapp, solonuovi) { let mystr = ''; let conta = 1; for (const rec of arrrec) { - mystr += conta + ' - ' + ' [' + rec.numinvitatiattivi + '] - [' + rec.numinvitati + '] (' + rec.ind_order + ') ' + rec.username + ' ' + rec.name + ' ' + rec.surname; + mystr += conta + '- ' + ' [' + rec.numinvitatiattivi + '-' + rec.numinvitati + '] (' + rec.index + ') '; + mystr += ' [' + tools.getstrDateShort(rec.date_added, 'it') + '] '; + mystr += rec.username + ' ' + rec.name + ' ' + rec.surname; mystr += ' inv = ' + rec.invitante_username; - mystr += ' num_tess = ' + rec.num_tess; + mystr += ' tess = ' + rec.num_tess; if (rec.added) mystr += ' (ADDED ++)'; @@ -388,6 +437,7 @@ ListaIngressoSchema.statics.getProssimiInLista = async function (idapp, solonuov let myobjField = { idapp: 1, + index: 1, ind_order: 1, name: 1, surname: 1, @@ -396,6 +446,7 @@ ListaIngressoSchema.statics.getProssimiInLista = async function (idapp, solonuov email: 1, lang: 1, num_tess: 1, + date_added: 1, added: 1, deleted: 1, sospeso: 1, @@ -491,6 +542,14 @@ ListaIngressoSchema.statics.eliminaListeIngressoNascoste = async function (idapp }; +ListaIngressoSchema.statics.RendiVisibileIrecordNascosti = async function (idapp) { + const ListaIngresso = this; + + const num = await ListaIngresso.updateMany({ idapp, deleted: true }, { $set: { deleted: false } }); + +}; + + ListaIngressoSchema.statics.creaTessituraeConv = async function (idapp) { const ListaIngresso = this; @@ -513,8 +572,6 @@ ListaIngressoSchema.statics.creaTessituraeConv = async function (idapp) { idapp, }); - // Ricalcola il Campo Index - await User.ricalcolaIndex(idapp); // Ricrea i record ListaIngresso (num_tess = 1), per ogni User for (const user of arrusers) { @@ -634,7 +691,7 @@ ListaIngressoSchema.statics.creaTessituraeConv = async function (idapp) { await ListaIngresso.findByIdAndUpdate(findlistaingresso._id, { $set: { username, - invitante_username, + // invitante_username, note: findlistaingresso.username, } }, { new: false }); @@ -652,7 +709,7 @@ ListaIngressoSchema.statics.creaTessituraeConv = async function (idapp) { } // poi imposta come cancellato questo record - await User.findByIdAndUpdate(myuser._id, { $set: { deleted: true } }); + await User.findByIdAndUpdate(myuser._id, { $set: { deleted: true, date_deleted: new Date() } }); } } @@ -660,6 +717,13 @@ ListaIngressoSchema.statics.creaTessituraeConv = async function (idapp) { index++; } + // RIMUOVI IL CAMPO IND_ORDER SULLA USER! + await User.update({}, {$unset: {ind_order: 1}}, {multi: true}); + + // Ricalcola il Campo Index + await User.ricalcolaIndex(idapp); + + return index; } catch (e) { @@ -684,6 +748,13 @@ ListaIngressoSchema.statics.getListaTessByUsername = function (idapp, username) ListaIngressoSchema.statics.getarray = async function (idapp, filtri, myobjField) { const ListaIngresso = this; + const { User } = require('./user'); + + if (!await User.NuovoSistema(idapp)) { + return await ListaIngresso.getarrayIndOrder(idapp, filtri, myobjField); + } + + let myfilter2 = { surname: { $exists: true }, $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], @@ -699,6 +770,24 @@ ListaIngressoSchema.statics.getarray = async function (idapp, filtri, myobjField }; +ListaIngressoSchema.statics.getarrayIndOrder = async function (idapp, filtri, myobjField) { + const ListaIngresso = this; + + let myfilter2 = { + surname: { $exists: true }, + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + }; + + let myquery = getQueryIndOrder( + filtri, + myobjField, + myfilter2 + ); + + return await ListaIngresso.aggregate(myquery); + +}; + ListaIngressoSchema.statics.getInvitati = async function (idapp, username, includemyself, myobjField) { const ListaIngresso = this; @@ -758,10 +847,10 @@ ListaIngressoSchema.statics.getnumInvitati = async function (idapp, username) { $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }] }); - /*for (const inv of arrinv) { + for (const inv of arrinv) { if (!arrlistainv.find((rec) => rec.username === inv.username)) arrlistainv.push(inv); - }*/ + } if (!!arrlistainv) return arrlistainv.length; @@ -802,11 +891,11 @@ ListaIngressoSchema.statics.getnumInvitatiAttivi = async function (idapp, userna $and: User.getQueryQualified() }); - /* + for (const inv of arrinv) { if (!arrlistainv.find((rec) => rec.username === inv.username)) arrlistainv.push(inv); - }*/ + } if (!!arrlistainv) return arrlistainv.length; diff --git a/src/server/models/nave.js b/src/server/models/nave.js index f2452f0..2675830 100755 --- a/src/server/models/nave.js +++ b/src/server/models/nave.js @@ -485,6 +485,71 @@ function getQueryProj(myfilter) { return query; } +function getQueryInvitante(myfilter) { + + myobjField = { + ind_order: 1, + name: 1, + surname: 1, + username: 1, + invitante_username: 1, + made_gift: 1, + sent_msg_howto_make_gift: 1, + date_made_gift: 1, + note: 1, + received_gift: 1, + date_received_gift: 1, + num_tess: 1, + parent_id: 1, + riga: 1, + col: 1, + created: 1, + }; + + const query = [ + { $match: myfilter }, + { + $lookup: { + from: "listaingressos", + localField: "ind_order", + foreignField: "ind_order", // field in the user collection + as: "mylista" + } + }, + { + $replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$mylista", 0] }, "$$ROOT"] } } + }, + { + $lookup: { + from: "users", + as: "user", + let: { username: '$username' }, + pipeline: [ + { + $match: { + $expr: { + $and: [ + { $eq: ['$username', '$$username'] }, + { $eq: ['$idapp', myfilter.idapp] }, + ] + } + } + } + ] + } + }, + { + $replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] }, "$$ROOT"] } } + // $replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] },] } } + }, + { $match: { $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }] } }, + { $project: myobjField } + ]; + + return query; +} + + NaveSchema.statics.setRiga = function (idapp, riga) { return Settings.setKeyNum(idapp, 'riga', riga); @@ -848,11 +913,22 @@ NaveSchema.statics.getArrPosizioniByUsername = async function (idapp, username) let arrposizioni = []; + for (const ind_order of arrrec_indorder) { + const myquery = getQueryInvitante({ idapp, ind_order }); + + const arr = await Nave.aggregate(myquery).sort({ riga: 1, col: 1 }); + if (!!arr) + arrposizioni = [...arrposizioni, ...arr]; + } + + + /* for (const ind_order of arrrec_indorder) { const arr = await Nave.find({ 'idapp': idapp, ind_order }).sort({ riga: 1, col: 1 }); if (!!arr) arrposizioni = [...arrposizioni, ...arr]; } + */ return arrposizioni; } catch (e) { diff --git a/src/server/models/user.js b/src/server/models/user.js index 4d998b5..3650d25 100755 --- a/src/server/models/user.js +++ b/src/server/models/user.js @@ -115,6 +115,9 @@ const UserSchema = new mongoose.Schema({ date_reg: { type: Date, }, + date_deleted: { + type: Date, + }, date_tokenforgot: { type: Date }, @@ -143,7 +146,8 @@ const UserSchema = new mongoose.Schema({ type: String, }, deleted: { - type: Boolean + type: Boolean, + default: false }, sospeso: { type: Boolean @@ -445,12 +449,12 @@ UserSchema.statics.getUserShortDataByUsername = async function (idapp, username) return myrec }; -UserSchema.statics.getDownlineByUsername = async function (idapp, username, includemyself) { +UserSchema.statics.getDownlineByUsername = async function (idapp, username, includemyself, onlynumber) { if (username === undefined) return null; - const arrrec = await ListaIngresso.getInvitati(idapp, username, includemyself, + let arrrec = await ListaIngresso.getInvitati(idapp, username, includemyself, { index: 1, lang: 1, @@ -481,7 +485,7 @@ UserSchema.statics.getDownlineByUsername = async function (idapp, username, incl }; if (!includemyself) { - myq = { ...myq, username: {$ne: username} } + myq = { ...myq, username: { $ne: username } } } // Ottieni gli invitati che ancora non hanno un'imbarco @@ -489,16 +493,35 @@ UserSchema.statics.getDownlineByUsername = async function (idapp, username, incl for (const inv of arrinv) { if (!arrrec.find((rec) => rec.username === inv.username)) - arrrec.push(inv); + arrrec.push(inv._doc); } + const arrusername = []; - if (!!arrrec) { - for (const rec of arrrec) { - rec.qualified = await User.isUserQualified7(idapp, rec.username); - rec.numNaviEntrato = await Nave.getnumNaviByUsername(idapp, rec.username); - rec.numinvitati = await ListaIngresso.getnumInvitati(idapp, rec.username); - rec.numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp, rec.username); + for (const inv of arrrec) { + + const rectrovato = arrusername.find((rec) => inv.username === rec.username); + if (!!rectrovato) { + rectrovato.quanti++; + } else { + const myrec = { ...inv }; + myrec.quanti = 1; + arrusername.push(myrec) + } + + } + + arrrec = arrusername; + + + if (!onlynumber) { + if (!!arrrec) { + for (const rec of arrrec) { + rec.qualified = await User.isUserQualified7(idapp, rec.username); + rec.numNaviEntrato = await Nave.getnumNaviByUsername(idapp, rec.username); + rec.numinvitati = await ListaIngresso.getnumInvitati(idapp, rec.username); + rec.numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(idapp, rec.username); + } } } return arrrec; @@ -928,7 +951,7 @@ UserSchema.statics.getSmallRecByIndOrder = async function (idapp, ind_order) { { idapp, ind_order, - deleted: false, + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }] }, { idapp: 1, @@ -953,15 +976,44 @@ UserSchema.statics.getSmallRecByIndOrder = async function (idapp, ind_order) { }; -UserSchema.statics.getRecByIndOrder = async function (idapp, ind_order) { +UserSchema.statics.NuovoSistema = function (idapp) { + const User = this; try { + return User.findOne({ idapp, old_order: { $exists: true } }) + .then((ris) => { + return !!ris; + }); + } catch (e) { + console.error('NuovoSistema', e.message); + } + +}; + + +UserSchema.statics.getRecByIndOrder = async function (idapp, ind_order) { + const User = this; + + try { + + let filters = { + idapp: 1, + index: 1, + ind_order: 1, + old_order: 1, + username: 1, + name: 1, + lang: 1, + surname: 1, + 'profile.teleg_id': 1, + }; + const rec = await ListaIngresso.getarray(idapp, { idapp, ind_order, - deleted: false, - }); + }, + filters); if (!!rec) return rec[0]; @@ -1139,7 +1191,6 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us // DATA: username, name, surname, email, intcode_cell, cell const dashboard = { aportador: {}, - downline: [], arrposizioni: [], arrimbarchi: [], arrusers: {}, @@ -1152,26 +1203,10 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us // dashboard.aportador = await ExtraList.getUserNotRegisteredByNameSurname(idapp, aportador_solidario_nome_completo); // } - dashboard.downline = []; - - // Data of my Downline - const arrap = await User.getDownlineByUsername(idapp, username); + const arrap = await User.getDownlineByUsername(idapp, username, false, true); if (!!arrap) dashboard.numpeople_aportador = arrap.length; - dashboard.downline = await User.getDownlineByUsername(idapp, username, true); - // dashboard.downnotreg = await ExtraList.getDownlineNotRegisteredByNameSurname(idapp, dashboard.myself.name + ' ' + dashboard.myself.surname); - - dashboard.downbyuser = {}; - - for (const down of dashboard.downline) { - dashboard.downbyuser[down.username] = await User.getDownlineByUsername(idapp, down.username, false); - - for (const down2 of dashboard.downbyuser[down.username]) { - dashboard.downbyuser[down2.username] = await User.getDownlineByUsername(idapp, down2.username, false); - } - } - dashboard.arrimbarchi = await ListaIngresso.findAllByUsername(idapp, username); // dashboard.arrprofili = await Nave.getArrProfiliByIndOrder(idapp, dashboard.myself.ind_order); @@ -1193,8 +1228,8 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us dashboard.lastnave = await NavePersistente.getLastNave(idapp); for (let mypos of dashboard.arrposizioni) { - mypos._doc.rec = await Nave.getNaveByRigaCol(idapp, mypos.riga, mypos.col); - mypos._doc.nave_partenza = await NavePersistente.findByRigaColByDonatore(idapp, mypos.riga, mypos.col, 0); + mypos.rec = await Nave.getNaveByRigaCol(idapp, mypos.riga, mypos.col); + mypos.nave_partenza = await NavePersistente.findByRigaColByDonatore(idapp, mypos.riga, mypos.col, 0); } @@ -1205,40 +1240,53 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us const arrnew = []; - for (let mypos of dashboard.arrposizioni) { - // Controlla se è presente la Nave con il num_tess pari + try { + for (let mypos of dashboard.arrposizioni) { + // Controlla se è presente la Nave con il num_tess pari - let trovato = false; + let trovato = false; - if (mypos.num_tess % 2 !== 0) { - for (let myrec of dashboard.arrposizioni) { - if (myrec.num_tess === mypos.num_tess + 1 && (myrec.ind_order === mypos.ind_order)) { - // La Nave di Ritorno (numtess = 2) esiste nella lista ! - trovato = true + if (mypos.num_tess % 2 !== 0) { + for (let myrec of dashboard.arrposizioni) { + if (myrec.num_tess === mypos.num_tess + 1 && (myrec.ind_order === mypos.ind_order)) { + // La Nave di Ritorno (numtess = 2) esiste nella lista ! + trovato = true; + break; + } + } + } else { + trovato = true; + } + if (!trovato) { + let myr = null; + if (!!mypos._doc) + myr = mypos._doc; + else + myr = mypos; + + if (!!myr && !!myr.rec.mediatore) { + const mymediatore = myr.rec.mediatore.arrdonatori[7]; + if (!!mymediatore) { + const myrec = { + riga: mymediatore.riga, + col: mymediatore.col, + name: myr.rec.mediatore.recmediatore.name, + surname: myr.rec.mediatore.recmediatore.surname, + username: myr.rec.mediatore.recmediatore.username, + num_tess: myr.rec.mediatore.recmediatore.num_tess + 1, + rec: await Nave.getNaveByRigaCol(idapp, mymediatore.riga, mymediatore.col), + nave_partenza: {}, + }; + + myrec.nave_partenza = await NavePersistente.findByRigaColByDonatore(idapp, myrec.riga, myrec.col, 0); + + arrnew.push(myrec); + } } } - } else { - trovato = true; - } - if (!trovato) { - const mymediatore = mypos._doc.rec.mediatore.arrdonatori[7]; - if (!!mymediatore) { - const myrec = { - riga: mymediatore.riga, - col: mymediatore.col, - name: mypos._doc.rec.mediatore.recmediatore.name, - surname: mypos._doc.rec.mediatore.recmediatore.surname, - username: mypos._doc.rec.mediatore.recmediatore.username, - num_tess: mypos._doc.rec.mediatore.recmediatore.num_tess + 1, - rec: await Nave.getNaveByRigaCol(idapp, mymediatore.riga, mymediatore.col), - nave_partenza: {}, - }; - - myrec.nave_partenza = await NavePersistente.findByRigaColByDonatore(idapp, myrec.riga, myrec.col, 0); - - arrnew.push(myrec); - } } + } catch (e) { + console.error(e.message); } dashboard.arrposizioni = [...dashboard.arrposizioni, ...arrnew]; @@ -1252,6 +1300,38 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us } }; +UserSchema.statics.getDownline = async function (idapp, aportador_solidario, username) { + try { + + // DATA: username, name, surname, email, intcode_cell, cell + let downline = {}; + + downline.downline = []; + + // Data of my Downline + const arrap = await User.getDownlineByUsername(idapp, username); + if (!!arrap) + downline.numpeople_aportador = arrap.length; + + downline.downline = await User.getDownlineByUsername(idapp, username, true); + + downline.downbyuser = {}; + + for (const down of downline.downline) { + downline.downbyuser[down.username] = await User.getDownlineByUsername(idapp, down.username, false); + + for (const down2 of downline.downbyuser[down.username]) { + downline.downbyuser[down2.username] = await User.getDownlineByUsername(idapp, down2.username, false); + } + } + + return downline; + } catch (e) { + console.error(e.message); + return false; + } +}; + /* UserSchema.statics.fixUsername = async function (idapp, aportador_solidario_ind_order, username) { const User = this; @@ -1780,7 +1860,10 @@ UserSchema.statics.getUsernameByIndex = async function (idapp, index) { UserSchema.statics.ricalcolaIndex = async function (idapp) { const User = this; - const arrusers = await User.find({ idapp }).sort({ ind_order: 1 }); + const arrusers = await User.find({ + idapp, + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }] + }).sort({ old_order: 1 }); let index = 0; try { for (const user of arrusers) { diff --git a/src/server/router/dashboard_router.js b/src/server/router/dashboard_router.js index 0319278..352561a 100755 --- a/src/server/router/dashboard_router.js +++ b/src/server/router/dashboard_router.js @@ -33,13 +33,6 @@ router.post('/', authenticate, async (req, res) => { let aportador_solidario = req.user.aportador_solidario; let aportador_solidario_nome_completo = req.user.aportador_solidario_nome_completo; - // if (User.isAdmin(req.user.perm) || User.isManager(req.user.perm)) { - // const recuser = await User.findByUsername(idapp, username); - // if (recuser) { - // aportador_solidario_nome_completo = recuser.name + ' ' + recuser.surname; - // } - // } - if (username) { aportador_solidario = await User.getAportadorSolidarioByUsername(idapp, username); aportador_solidario_nome_completo = await User.getNameSurnameByUsername(idapp, username); @@ -59,6 +52,37 @@ router.post('/', authenticate, async (req, res) => { }); +router.post('/downline', authenticate, async (req, res) => { + try { + const idapp = req.body.idapp; + let username = req.body.username; + + if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm)) && (username) !== req.user.username) { + // If without permissions, exit + return res.status(404).send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' }); + } + let aportador_solidario = req.user.aportador_solidario; + let aportador_solidario_nome_completo = req.user.aportador_solidario_nome_completo; + + if (username) { + aportador_solidario = await User.getAportadorSolidarioByUsername(idapp, username); + aportador_solidario_nome_completo = await User.getNameSurnameByUsername(idapp, username); + } else { + username = req.user.username; + } + + const downline = await User.getDownline(idapp, aportador_solidario, username, aportador_solidario_nome_completo); + if (downline) + res.send({ downline }); + else + res.status(400).send(e); + + } catch (e) { + res.status(400).send(e); + } + +}); + router.post('/msgnave', authenticate, async (req, res) => { const idapp = req.body.idapp; diff --git a/src/server/router/index_router.js b/src/server/router/index_router.js index a9b1af2..bd9974e 100755 --- a/src/server/router/index_router.js +++ b/src/server/router/index_router.js @@ -583,6 +583,7 @@ router.patch('/callfunz', authenticate, async (req, res) => { olduseringresso = await ListaIngresso.findOne({ idapp, ind_order: mianavedasost.ind_order }); if (!!olduseringresso) { let fieldsvalue = { + date_deleted: new Date(), deleted: true }; const risul = await ListaIngresso.findByIdAndUpdate(olduseringresso.id, { $set: fieldsvalue }, { new: false }); @@ -591,10 +592,16 @@ router.patch('/callfunz', authenticate, async (req, res) => { } if (!!myuservecchio) { + // Se ha gia delle altre navi, non cancellarlo! + Nave.checkIfMadeGift(idapp, ) + const noncanc = await Nave.findOne({idapp, ind_order: mianavedasost.ind_order, made_gift: true }); + + if (mydata.data.deleteUser && !!mianavedasost && mianavedasost.ind_order > 0) { // Metti Deleted allo User fieldsvalue = { - deleted: true + deleted: true, + date_deleted: new Date(), }; await User.findByIdAndUpdate(myuservecchio.id, { $set: fieldsvalue }); await telegrambot.sendMsgTelegramToTheManagers(idapp, `L\'utente ${myuservecchio.name} ${myuservecchio.surname} (${myuservecchio.username}) è stato cancellato (nascosto) perchè sostituito (da ${req.user.name} ${req.user.surname} )`); @@ -763,7 +770,8 @@ router.delete('/delrec/:table/:id', authenticate, async (req, res) => { if (tablename === 'users') { let fieldsvalue = { - deleted: true + deleted: true, + date_deleted: new Date(), }; const rec = await mytable.findByIdAndUpdate(id, { $set: fieldsvalue }); diff --git a/src/server/router/users_router.js b/src/server/router/users_router.js index b9be6bb..b22b3a6 100755 --- a/src/server/router/users_router.js +++ b/src/server/router/users_router.js @@ -477,31 +477,35 @@ router.post('/dbop', authenticate, async (req, res) => { } else if (mydata.dbop === 'eliminaListeIngressoNascoste') { ris = await ListaIngresso.eliminaListeIngressoNascoste(idapp); ris = { mystr }; + } else if (mydata.dbop === 'RendiVisibileIrecordNascosti') { + ris = await ListaIngresso.RendiVisibileIrecordNascosti(idapp); + ris = { mystr }; } else if (mydata.dbop === 'convNaviTessinListaIngressoRec') { let num = 0; - const arrnavitess = await Nave.find({idapp, num_tess: { $gte: 3 } }); + const arrnavitess = await Nave.find({ idapp, num_tess: { $gte: 3 } }); for (const recnave of arrnavitess) { if (recnave.num_tess === 3 || recnave.num_tess === 5 || recnave.num_tess === 7) { const ind_order = recnave.ind_order; // Prima controlla se ho già 2 record dello stesso ind_order, allora non lo faccio: - const arringr = await ListaIngresso.find({idapp, ind_order}); + const arringr = await ListaIngresso.find({ idapp, ind_order }); let dafare = true; if (arringr.length > 0) { - const arringrtest = await ListaIngresso.find({idapp, ind_order}).distinct('num_tess'); - if (arringr.length !== arringrtest.length){ + const arringrtest = await ListaIngresso.find({ idapp, ind_order }).distinct('num_tess'); + if (arringr.length !== arringrtest.length) { dafare = false; // Ci sono 2 o piu record! pertanto probabilmente l'ho già fatto! } } if (dafare) { - const user = await User.findByOldOrder(idapp, ind_order); + // const user = await User.findByOldOrder(idapp, ind_order); + const user = await User.findByIndOrder(idapp, ind_order); if (!!user) { - let note = recnave.num_tess; + //let note = recnave.num_tess; // Crea record ListaIngresso - const newrecingr = await ListaIngresso.addUserInListaIngresso(idapp, user.username, user.username, user.lang, false, true, recnave.created, note, true); + const newrecingr = await ListaIngresso.addUserInListaIngresso(idapp, user.username, user.username, user.lang, false, true, recnave.created, '', true); const fieldsvalue = { ind_order: newrecingr.ind_order, @@ -517,6 +521,14 @@ router.post('/dbop', authenticate, async (req, res) => { } } + + const arrnavitess2 = await Nave.find({ idapp, num_tess: 2 }); + + for (const recnave of arrnavitess2) { + + + } + ris = { num }; } else if (mydata.dbop === 'initListaIngresso') { @@ -664,7 +676,7 @@ router.post('/dbop', authenticate, async (req, res) => { } else if (mydata.dbop === 'visuPlacca') { mystr = '✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨\n' + - 'ECCO LE NUOVE NAVI DEFINITIVE CHE APRONO DOMANI LA GIFT CHAT !!! DALLA ' + mydata.riga + '.' + mydata.col + ' ALLA ' + mydata.riga + '.' + (parseInt(mydata.col) + 7) +'\n' + + 'ECCO LE NUOVE NAVI DEFINITIVE CHE APRONO DOMANI LA GIFT CHAT !!! DALLA ' + mydata.riga + '.' + mydata.col + ' ALLA ' + mydata.riga + '.' + (parseInt(mydata.col) + 7) + '\n' + 'AUGURI ALLA NUOVA SOGNATRICE !!!\n' + '✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨'; diff --git a/src/server/telegram/telegrambot.js b/src/server/telegram/telegrambot.js index 69188ea..614dc3a 100755 --- a/src/server/telegram/telegrambot.js +++ b/src/server/telegram/telegrambot.js @@ -1226,8 +1226,9 @@ class Telegram { let mystr = ''; const dashboard = await User.getDashboard(this.idapp, user.aportador_solidario, user.username, user.aportador_solidario_name_surname); + const downline = await User.getDownline(this.idapp, user.aportador_solidario, user.username); - let numpersone = (dashboard.downline) ? dashboard.downline.length : 0; + let numpersone = (downline.downline) ? downline.downline.length : 0; let invitati_attivi = dashboard.myself.numinvitatiattivi; mystr = ""; // if (dashboard.aportador) { @@ -1295,7 +1296,7 @@ class Telegram { mystr += tools.get__('INVITATI_LISTA', this.getlang(msg)) + ':\n'; let index = 1; - dashboard.downline.forEach((user) => { + downline.downline.forEach((user) => { mystr += emoji.get('star-struck') + ` ${index}°: `; mystr += (user.qualified) ? emo.CHECK_VERDE : emo.CROSS_ROSSA; mystr += `${user.name} ${user.surname} (${user.username})\n`; @@ -2115,6 +2116,8 @@ class Telegram { } if (blocked) { User.SetTelegramWasBlocked(this.idapp, id); + + // ++Todo: DA FARE ! local_sendMsgTelegramToTheManagers(this.idapp, addtext + text); } return 0; });