- Nuovo Sistema di Flotte per Tutor.

X - Mettere anche la email del sognatore, per chi è abituato ad inviarla in quel modo...
X - Controllare che sul sito compaiano le informazioni del Sognatore...
This commit is contained in:
Paolo Arena
2020-06-08 13:31:05 +02:00
parent 140e181fcc
commit c939be279e
21 changed files with 2037 additions and 254 deletions

View File

@@ -30,6 +30,7 @@ const _ = require('lodash');
const { User } = require('../models/user');
const { Nave } = require('../models/nave');
const { Flotta } = require('../models/flotta');
const { NavePersistente } = require('../models/navepersistente');
// const { ExtraList } = require('../models/extralist');
const { Booking } = require('../models/booking');
@@ -49,6 +50,7 @@ const { MailingList } = require('../models/mailinglist');
const { Settings } = require('../models/settings');
const { SendMsg } = require('../models/sendmsg');
const { Permission } = require('../models/permission');
const { MsgTemplate } = require('../models/msg_template');
const tools = require('../tools/general');
@@ -220,6 +222,10 @@ function getTableByTableName(tablename) {
mytable = MailingList;
else if (tablename === 'navi')
mytable = Nave;
else if (tablename === 'flotte')
mytable = Flotta;
else if (tablename === 'msg_templates')
mytable = MsgTemplate;
else if (tablename === 'navepersistente')
mytable = NavePersistente;
else if (tablename === 'listaingressos')
@@ -285,6 +291,9 @@ router.post('/gettable', authenticate, (req, res) => {
async function checkIfSbloccatiRequisiti(idapp, allData, id) {
if (!allData.myuser)
return false;
if (await Nave.checkIfNaveExist(idapp, allData.myuser.username)) {
// Se già sei dentro la Nave, allora sei OK
return true;
@@ -298,22 +307,27 @@ async function checkIfSbloccatiRequisiti(idapp, allData, id) {
if (userlista.length === 0) {
// Se non sono ancora dentro alla lista, allora controllo
if (!allData.precDataUser.is7req && is7req) {
// ORA HAI I 7 REQUISITI !
// const msgtext = telegrambot.getCiao(idapp, allData.myuser.username, allData.myuser.lang) + tools.gettranslate('HAI_I_7_REQUISITI', allData.myuser.lang);
// telegrambot.sendMsgTelegram(idapp, allData.myuser.username, msgtext, true); // Anche a STAFF
if (!!allData.precDataUser) {
if ((!allData.precDataUser.is7req && is7req) && !await User.isUserAlreadyQualified(idapp, allData.myuser.username)) {
await User.setUserQualified(idapp, allData.myuser.username);
// ORA HAI I 7 REQUISITI !
// const msgtext = telegrambot.getCiao(idapp, allData.myuser.username, allData.myuser.lang) + tools.gettranslate('HAI_I_7_REQUISITI', allData.myuser.lang);
// telegrambot.sendMsgTelegram(idapp, allData.myuser.username, msgtext, true); // Anche a STAFF
if (tools.isAbilitaNave(idapp)) {
// Aggiungilo alla ListaIngresso
risingr = await ListaIngresso.addUserInListaIngresso(idapp, allData.myuser.username, allData.myuser.aportador_iniziale, allData.myuser.lang, true, false);
}
}
}
if (!allData.precDataUser.is9req && is9req) {
// ORA HAI I 9 REQUISITI !
const msgtext = telegrambot.getCiao(idapp, allData.myuser.username, allData.myuser.lang) + tools.gettranslate('HAI_I_9_REQUISITI', allData.myuser.lang);
telegrambot.sendMsgTelegram(idapp, allData.myuser.username, msgtext, false); // Anche a STAFF
if (!!allData.precDataUser) {
if ((!allData.precDataUser.is9req && is9req) && !await User.isUserAlreadyQualified_2Invitati(idapp, allData.myuser.username)) {
await User.setUserQualified_2Invitati(idapp, allData.myuser.username);
// ORA HAI I 9 REQUISITI !
const msgtext = telegrambot.getCiao(idapp, allData.myuser.username, allData.myuser.lang) + tools.gettranslate('HAI_I_9_REQUISITI', allData.myuser.lang);
telegrambot.sendMsgTelegram(idapp, allData.myuser.username, msgtext, false); // Anche a STAFF
}
}
// CHECK APORTADOR SOLIDARIO:
@@ -391,7 +405,10 @@ router.patch('/chval', authenticate, async (req, res) => {
if (camporequisiti) {
allData = {};
allData.myuser = await User.getUserById(idapp, id);
allData.precDataUser = await getInfoUser(idapp, allData.myuser.username);
if (!!allData.myuser)
allData.precDataUser = await getInfoUser(idapp, allData.myuser.username);
else
allData.precDataUser = null;
// allData.useraportador = await ListaIngresso.getUserByInvitante_Username(idapp, allData.myuser.aportador_solidario);
// allData.precDataAportador = await getInfoUser(idapp, allData.myuser.aportador_solidario);
}
@@ -404,9 +421,42 @@ router.patch('/chval', authenticate, async (req, res) => {
if (!rec) {
return res.status(404).send();
} else {
let addmsg = '';
if (mydata.table === 'navi' && ('made_gift' in fieldsvalue)) {
if (fieldsvalue['made_gift'] && !rec.received_gift) {
if (mydata.tipomsg) {
let mypos = {
idapp,
riga: rec.riga,
col: rec.col,
numup: 3
};
tools.getRigaColByPosUp(mypos);
const myuser = await User.findByIndOrder(idapp, rec.ind_order);
if (!!myuser) {
const mydatamsg = {
tipomsg: tools.TipoMsg.SEND_MSG_DONO_RICEVUTO_CORRETTAMENTE,
navemediatore: { riga: mypos.riga, col: mypos.col },
};
const rismsg = await telegrambot.getMsgByTipoMsg(mydatamsg, myuser.lang, myuser, false);
addmsg = rismsg.body;
}
}
await mytable.findByIdAndUpdate(id, { $set: { received_gift: true } });
}
}
// SEND_MSG_DONO_RICEVUTO_CORRETTAMENTE
if (mydata.notifBot) {
// Send Notification to the BOT
await telegrambot.sendMsgTelegram(idapp, mydata.notifBot.un, mydata.notifBot.txt);
if (!!addmsg)
await telegrambot.sendMsgTelegram(idapp, mydata.notifBot.un, addmsg);
addtext = '[Msg Inviato a ' + mydata.notifBot.un + ']:' + '\n' + mydata.notifBot.txt;
telegrambot.sendMsgTelegramToTheManagers(idapp, addtext, true);
}
@@ -417,6 +467,12 @@ router.patch('/chval', authenticate, async (req, res) => {
}
}
if (mydata.table === 'flotte') {
if (('date_start' in fieldsvalue) || ('date_close' in fieldsvalue)) {
await NavePersistente.changeField(idapp, rec, fieldsvalue);
}
}
if (mydata.table === 'users') {
if ('aportador_solidario' in fieldsvalue) {
ind_order_ingr = mydata.ind_order_ingr;
@@ -446,7 +502,13 @@ router.patch('/chval', authenticate, async (req, res) => {
return false;
}
} else if ('deleted' in fieldsvalue) {
await telegrambot.sendMsgTelegramToTheManagers(idapp, `L\'utente ${rec.name} ${rec.surname} (${rec.username}) è stato cancellato (nascosto) da ${req.user.name} ${req.user.surname}`);
let msg = '';
if (fieldsvalue.deleted)
msg = 'cancellato (nascosto)';
else
msg = 'Ripristinato';
await telegrambot.sendMsgTelegramToTheManagers(idapp, `L\'utente ${rec.name} ${rec.surname} (${rec.username}) è stato ${msg} da ${req.user.name} ${req.user.surname}`);
}
}
@@ -475,6 +537,13 @@ router.patch('/chval', authenticate, async (req, res) => {
// return false;
}
}
if ('note' in fieldsvalue) {
// Aggiornalo anche in Graduatorie
await Graduatoria.findOneAndUpdate({
idapp,
idListaIngresso: id
}, { $set: { note: fieldsvalue.note } }, { new: false })
}
}
if (tools.ModificheConsentite(mydata.table, fieldsvalue)) {
@@ -496,7 +565,10 @@ router.patch('/chval', authenticate, async (req, res) => {
} else if (mydata.table === 'navi') {
if ('made_gift' in fieldsvalue) {
if (!!fieldsvalue.riga) {
await Nave.ricalcolaNave(idapp, null, fieldsvalue.riga, fieldsvalue.col, true, index)
const navepers = await Nave.ricalcolaNave(idapp, null, fieldsvalue.riga, fieldsvalue.col, true, index);
if (!!navepers)
await NavePersistente.aggiornaFlottaByNavePersistente(idapp, navepers);
}
}
}
@@ -539,8 +611,29 @@ router.patch('/askfunz', authenticate, async (req, res) => {
if (!!userfree)
return res.send({ code: server_constants.RIS_CODE_OK, out: userfree });
/*} else if (mydata.myfunc === shared_consts.CallFunz.GET_VALBYTABLE) {
const mytable = getTableByTableName(mydata.table);
const coltoshow = {
[mydata.coltoshow]: 1
};
const ris = await mytable.findOne({ _id: id }, coltoshow);
return ris;
} else if (mydata.myfunc === shared_consts.CallFunz.SET_VALBYTABLE) {
const mytable = getTableByTableName(mydata.table);
const value = mydata.value;
const coltoset = {
[mydata.coltoshow]: value
};
const ris = await mytable.findOneAndUpdate({ _id: id }, { $set: coltoset }, { new: false });
if (!!ris)
return res.send({ code: server_constants.RIS_CODE_OK });*/
}
return res.send({ code: server_constants.RIS_CODE_ERR });
});
router.patch('/callfunz', authenticate, async (req, res) => {
@@ -586,10 +679,11 @@ router.patch('/callfunz', authenticate, async (req, res) => {
if (!!myusernuovo) {
if (!mydata.data.AddImbarco && !!mianavedasost && mianavedasost.ind_order > 0) {
// Controlla prima se è in una Nave Temporanea, allora lo elimina dalla PRIMA Nave Temporanea
// Controlla prima se è in una Nave Temporanea, allora lo elimina dall'ultima Nave Temporanea
miaarrnavi = await Nave.getArrPosizioniByUsername(idapp, username);
if (miaarrnavi) {
miaarrnavi = miaarrnavi.reverse(); // parto dall'ultima
for (const mianave of miaarrnavi) {
let persistente = await NavePersistente.findByRigaColByDonatore(idapp, mianave.riga, mianave.col, 0);
if (persistente.provvisoria) {
@@ -629,7 +723,7 @@ router.patch('/callfunz', authenticate, async (req, res) => {
const risdel = await ListaIngresso.deleteOne({ _id: olduseringresso.id });
if (!!risdel) {
await actions.doOtherThingsAfterDeleted('listaingressos', myrecuser, false)
await actions.doOtherThingsAfterDeleted('listaingressos', myrecuser, false, req)
}
}
}
@@ -651,6 +745,28 @@ router.patch('/callfunz', authenticate, async (req, res) => {
await telegrambot.sendMsgTelegramToTheManagers(idapp, `L\'utente ${myuservecchio.name} ${myuservecchio.surname} (${myuservecchio.username}) è stato cancellato (nascosto) perchè sostituito (da ${req.user.name} ${req.user.surname} )`);
}
}
if (mydata.data.notifBot) {
const mydatamsg = {
tipomsg: tools.TipoMsg.SEND_MSG_A_UTENTE_SOSTITUITO,
navemediatore: { riga: navepersistente.riga, col: navepersistente.col },
};
mydatamsg.flotta = await Flotta.getFlottaByNavePersistente(idapp, navepersistente);
const rismsg = await telegrambot.getMsgByTipoMsg(mydatamsg, myuservecchio.lang, myuservecchio, false);
if (!!rismsg) {
let messaggio = rismsg.body;
mytitle = rismsg.title;
if (!!messaggio) {
await telegrambot.sendMsgTelegram(idapp, myusernuovo.username, messaggio);
}
}
}
}
@@ -681,7 +797,6 @@ router.patch('/callfunz', authenticate, async (req, res) => {
}, { $set: { ind_order: -1 } }, { new: false });
// Aggiorna la Nave con il Nuovo
fieldsvalue = {
ind_order
@@ -695,31 +810,50 @@ router.patch('/callfunz', authenticate, async (req, res) => {
if (!rec) {
return res.status(404).send();
} else {
// Send Notification to the BOT
let messaggio = tools.get__('SPOSTATO', req.user.lang);
if (!!navepersistente.date_start) {
messaggio += tools.ACAPO + tools.get__('DATA_PART_NAVE', req.user.lang) + tools.getstrDateLong(navepersistente.date_gift_chat_open) + tools.ACAPO;
}
if (!!navepersistente.link_chat) {
messaggio += tools.ACAPO + '👉🏻👉🏻 <strong><a href="' + navepersistente.link_chat + '">' + tools.get__('ENTRA_GIFT_CHAT', req.user.lang) + '</a></strong> ' + tools.ACAPO;
}
const mydatamsg = {
tipomsg: tools.TipoMsg.SEND_MSG_EFFETTUA_IL_DONO,
navemediatore: { riga: navepersistente.riga, col: navepersistente.col },
};
const myplacca = await Nave.getNavePos(idapp, navepersistente.riga, navepersistente.col);
messaggio += tools.ACAPO + myplacca;
mydatamsg.flotta = await Flotta.getFlottaByNavePersistente(idapp, navepersistente);
const mymsg = mydata.notifBot.txt + ' ' + myusernuovo.name + ' ' + myusernuovo.surname + ' [da ' + dachi + ']' + tools.ACAPO + 'Inviato messaggio: ' + messaggio;
const rismsg = await telegrambot.getMsgByTipoMsg(mydatamsg, myusernuovo.lang, myusernuovo, false);
if (mydata.data.notifBot && !!navepersistente.link_chat) {
let messaggio = rismsg.body;
mytitle = rismsg.title;
// const myplacca = await Nave.getNavePos(idapp, navepersistente.riga, navepersistente.col);
// messaggio += tools.ACAPO + myplacca;
let testostaff = '';
if (mydata.notifBot)
testostaff = mydata.notifBot.txt;
const mymsg = testostaff + ' ' + myusernuovo.name + ' ' + myusernuovo.surname + ' [da ' + dachi + ']' + tools.ACAPO + 'Inviato messaggio: ' + messaggio;
if (mydata.data.notifBot) {
await telegrambot.sendMsgTelegram(idapp, myusernuovo.username, messaggio);
await telegrambot.sendMsgTelegramToTheManagers(idapp, mymsg);
await telegrambot.sendMsgTelegram(idapp, req.user.username, mydata.notifBot.txt);
await telegrambot.sendMsgTelegram(idapp, req.user.username, myplacca);
if (mydata.data.inviaemail) {
await sendemail.sendEmail_ByText(myusernuovo.lang, myusernuovo.email, myusernuovo, idapp, {
emailbody: messaggio,
emailtitle: mytitle
});
}
await telegrambot.sendMsgTelegramToTheManagers(idapp, testostaff);
await telegrambot.sendMsgTelegram(idapp, req.user.username, testostaff);
// await telegrambot.sendMsgTelegram(idapp, req.user.username, myplacca);
} else {
tools.writeManagersLog(mymsg);
}
tools.writeManagersLog(mymsg);
const msgsost = '[NAVE ' + navepersistente.riga + '.' + navepersistente.col + '] Sostituito ' + myuservecchio.username + ' (' + myuservecchio.name + ' ' + myuservecchio.surname + ') ' + ' con -> ' + myusernuovo.username + ' (' + myusernuovo.name + ' ' + myusernuovo.surname + ') ' + ' [da ' + dachi + ']';
tools.writeSostituzioniLog(msgsost);
tools.writeFlottaLog(idapp, msgsost, mydatamsg.flotta.riga, mydatamsg.flotta.col_prima);
await telegrambot.sendMsgTelegramToTheManagers(idapp, msgsost);
// const nomecognomeprima = myuser.name + ' ' + myuser.surname + '(' + myuser.username + ')';
// const nomecognomenuovo = await User.getNameSurnameByUsername(idapp,);
@@ -728,7 +862,7 @@ router.patch('/callfunz', authenticate, async (req, res) => {
}
}).catch((e) => {
tools.mylogserr('Error patch USER: ', e);
tools.mylogserr('Error patch USER: ', e.message);
res.status(400).send();
})
}
@@ -759,15 +893,28 @@ router.patch('/callfunz', authenticate, async (req, res) => {
const myrec = await ListaIngresso.getIngrEUserByFilter(idapp, { idapp, _id: ObjectID(mydata.data.id) });
if (!!myrec) {
const risdel = await ListaIngresso.deleteOne({ _id: mydata.data.id });
const myingr = await ListaIngresso.find({ _id: mydata.data.id });
// Controlla se ci sono 2 navi
const arrnavi = await Nave.find({ idapp, ind_order: mydata.ind_order });
if (!!risdel) {
return await actions.doOtherThingsAfterDeleted('listaingressos', myrec, false)
let risdel = false;
if (arrnavi.length === 1) {
// Solo 1 nave da cancellare, quindi cancello anche l'ingresso
risdel = await ListaIngresso.deleteOne({ _id: mydata.data.id });
} else {
// non cancellare la listaingresso (perchè con lo stesso ind_order ho piu navi !
risdel = true
}
if (risdel) {
return await actions.doOtherThingsAfterDeleted('listaingressos', myrec, false, req)
.then((ris) => {
if (!!ris)
// tools.mylog('DELETED Others things ...');
if (!!ris) {
// tools.mylog('DELETED Others things ...');
return res.send({ code: server_constants.RIS_CODE_OK, msg: '' });
}
});
}
}
@@ -871,7 +1018,7 @@ router.delete('/delrec/:table/:id', authenticate, async (req, res) => {
if (cancellato) {
// Do extra things after deleted
return actions.doOtherThingsAfterDeleted(tablename, myrec, notifBot);
return actions.doOtherThingsAfterDeleted(tablename, myrec, notifBot, req);
}
res.send({ code: server_constants.RIS_CODE_ERR, msg: '' });