- 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:
@@ -13,7 +13,7 @@ const tools = require('../../tools/general');
|
||||
const telegrambot = require('../../telegram/telegrambot');
|
||||
|
||||
module.exports = {
|
||||
doOtherThingsAfterDeleted: async function (tablename, rec, notifBot) {
|
||||
doOtherThingsAfterDeleted: async function (tablename, rec, notifBot, req) {
|
||||
try {
|
||||
let ris = null;
|
||||
if (tablename === 'users') {
|
||||
@@ -42,12 +42,13 @@ module.exports = {
|
||||
ris = await Graduatoria.deleteOne({ idListaIngresso: ObjectID(rec._id) });
|
||||
if (!!ris) {
|
||||
|
||||
let msg = 'Eliminato Imbarco di ' + rec.name + ' ' + rec.surname + ' [Index = ' + rec.index + ']';
|
||||
let msg = 'Eliminato Imbarco di ' + rec.name + ' ' + rec.surname + ' (ind_order=' + rec.ind_order + ', num_tess=' + rec.num_tess + ') [Num = ' + rec.index + `] (da ${req.user.name} ${req.user.surname} )` ;
|
||||
await telegrambot.sendMsgTelegramToTheManagers(rec.idapp, msg);
|
||||
tools.writeSostituzioniLog(msg);
|
||||
}
|
||||
|
||||
// Elimina anche la Nave se è temporanea!
|
||||
const arrnave = await Nave.find({ idapp: rec.idapp, ind_order: rec.ind_order });
|
||||
const arrnave = await Nave.find({ idapp: rec.idapp, ind_order: rec.ind_order, num_tess: rec.num_tess });
|
||||
for (const mynave of arrnave) {
|
||||
if (!!mynave) {
|
||||
if (!await Nave.isDefinitiva(rec.idapp, mynave)) {
|
||||
|
||||
@@ -10,7 +10,9 @@ const { authenticate } = require('../middleware/authenticate');
|
||||
const { User } = require('../models/user');
|
||||
|
||||
const { Nave } = require('../models/nave');
|
||||
const { Flotta } = require('../models/flotta');
|
||||
const { NavePersistente } = require('../models/navepersistente');
|
||||
const { MsgTemplate } = require('../models/msg_template');
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
const Subscription = mongoose.model('subscribers');
|
||||
@@ -94,10 +96,11 @@ router.post('/msgnave', authenticate, async (req, res) => {
|
||||
if (mydata.tipomsg === tools.TipoMsg.SEND_MSG_SINGOLO) {
|
||||
let mymsg = '';
|
||||
if (!!mydata.username_mitt) {
|
||||
mymsg = '[' + tools.getres__('MSG_SEND_FROM', res) + ' ' + mydata.username_mitt + ']:' + tools.ACAPO;
|
||||
mymsg = '[' + tools.getres__('MSG_SEND_FROM', res) + ' ' + mydata.username_mitt + ' a ' + mydata.username + ']:' + tools.ACAPO;
|
||||
}
|
||||
mymsg += mydata.msgpar1;
|
||||
ris = await telegrambot.sendMsgTelegram(idapp, mydata.username, mymsg, true, mydata.username_mitt); // Anche a STAFF
|
||||
// ris = await telegrambot.sendMsgTelegram(idapp, mydata.username, mymsg, true, mydata.username_mitt); // Anche a STAFF
|
||||
ris = await telegrambot.sendMsgTelegram(idapp, mydata.username, mymsg, true); // Anche a STAFF
|
||||
} else
|
||||
ris = await telegrambot.sendMsgTelegramToNave(idapp, mydata);
|
||||
|
||||
@@ -113,6 +116,27 @@ router.post('/msgnave', authenticate, async (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.post('/msgflotta', authenticate, async (req, res) => {
|
||||
const idapp = req.body.idapp;
|
||||
let mydata = req.body;
|
||||
|
||||
try {
|
||||
|
||||
let ris = null;
|
||||
ris = await telegrambot.sendMsgTelegramToNave(idapp, mydata);
|
||||
|
||||
if (ris)
|
||||
res.send({ code: server_constants.RIS_CODE_OK, ris });
|
||||
else
|
||||
res.send({ code: server_constants.RIS_CODE_ERR, ris: null });
|
||||
|
||||
|
||||
} catch (e) {
|
||||
res.status(400).send(e);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
router.post('/getnave', authenticate, async (req, res) => {
|
||||
const idapp = req.body.idapp;
|
||||
const riga = req.body.riga;
|
||||
@@ -144,6 +168,9 @@ router.post('/getnave', authenticate, async (req, res) => {
|
||||
router.post('/getnavi', authenticate, async (req, res) => {
|
||||
const idapp = req.body.idapp;
|
||||
|
||||
const { Flotta } = require('../models/flotta');
|
||||
|
||||
|
||||
let arrnavi = await NavePersistente.findAllIdApp(idapp);
|
||||
|
||||
// let arrnavi = await NavePersistente.find({idapp, date_gift_chat_open: { $gte: tools.IncDateNow(-1000 * 3600 * 24 * 7 ) } }).sort({ riga: 1, col: 1 });
|
||||
@@ -163,6 +190,8 @@ router.post('/getnavi', authenticate, async (req, res) => {
|
||||
// }
|
||||
// nave._doc.rec.donatore.navepersistente = await NavePersistente.findByRigaColByDonatore(idapp, riganave, colnave, 0);
|
||||
nave._doc.rec.donatore.navepersistente = await NavePersistente.findOne({ idapp, riga: riganave, col: colnave });
|
||||
if (!!nave._doc.rec.donatore.navepersistente)
|
||||
nave._doc.rec.donatore.flotta = await Flotta.getFlottaByNavePersistente(idapp, nave._doc.rec.donatore.navepersistente);
|
||||
}
|
||||
|
||||
const navi_partenza = await NavePersistente.findAllIdApp(idapp);
|
||||
@@ -176,6 +205,48 @@ router.post('/getnavi', authenticate, async (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.post('/getmsg_templates', authenticate, async (req, res) => {
|
||||
const idapp = req.body.idapp;
|
||||
|
||||
let ris = await MsgTemplate.findAllIdApp(idapp);
|
||||
|
||||
if (!!ris)
|
||||
res.send({ code: server_constants.RIS_CODE_OK, ris });
|
||||
else
|
||||
res.status(400).send(e);
|
||||
|
||||
|
||||
});
|
||||
|
||||
router.post('/getflotte', authenticate, async (req, res) => {
|
||||
const idapp = req.body.idapp;
|
||||
|
||||
let arrflotte = await Flotta.findAllIdApp(idapp);
|
||||
|
||||
if (!!arrflotte)
|
||||
res.send({ code: server_constants.RIS_CODE_OK, arrflotte });
|
||||
else
|
||||
res.status(400).send(e);
|
||||
|
||||
});
|
||||
|
||||
router.post('/getflotta', authenticate, async (req, res) => {
|
||||
const idapp = req.body.idapp;
|
||||
const riga = req.body.riga;
|
||||
const col_prima = req.body.col_prima;
|
||||
const col_ultima = req.body.col_ultima;
|
||||
|
||||
let ris = await Nave.getFlotta(idapp, riga, col_prima, col_ultima);
|
||||
|
||||
ris.flotta._doc.log_attivita = tools.readFlottaLog(idapp, ris.flotta.riga, ris.flotta.col_prima);
|
||||
|
||||
if (!!ris)
|
||||
res.send({ code: server_constants.RIS_CODE_OK, flotta: ris.flotta, arrdonatori: ris.arrdonatori });
|
||||
else
|
||||
res.status(400).send(e);
|
||||
|
||||
});
|
||||
|
||||
router.post('/getdoninavi', authenticate, async (req, res) => {
|
||||
const idapp = req.body.idapp;
|
||||
const ricalcola = req.body.ricalcola;
|
||||
@@ -185,7 +256,7 @@ router.post('/getdoninavi', authenticate, async (req, res) => {
|
||||
if (showall)
|
||||
arrnavi = await NavePersistente.findAllIdApp(idapp);
|
||||
else
|
||||
arrnavi = await NavePersistente.find({idapp, date_gift_chat_open: { $gte: tools.IncDateNow(-1000 * 3600 * 24 * 7 ) } }).sort({ riga: 1, col: 1 });
|
||||
arrnavi = await NavePersistente.find({idapp, date_gift_chat_open: { $gte: tools.IncDateNow(-1000 * 3600 * 24 * 10 ) } }).sort({ riga: 1, col: 1 });
|
||||
|
||||
let test = false;
|
||||
|
||||
@@ -201,6 +272,7 @@ router.post('/getdoninavi', authenticate, async (req, res) => {
|
||||
}
|
||||
} else {
|
||||
// arrnavi = await NavePersistente.findAllIdApp(idapp);
|
||||
let index = 1;
|
||||
for (nave of arrnavi) {
|
||||
if (nave.provvisoria || nave.DoniTotali !== nave.DoniConfermati) {
|
||||
nave._doc.rec = await Nave.getNaveByRigaCol(idapp, nave.riga1don, nave.col1don);
|
||||
@@ -214,8 +286,13 @@ router.post('/getdoninavi', authenticate, async (req, res) => {
|
||||
nave._doc.rec = {};
|
||||
nave._doc.rec.donatore = {};
|
||||
nave._doc.rec.donatore.navepersistente = await NavePersistente.findByRigaColByDonatore(idapp, rigapos, colpos, tools.Placca.SONOFUOCO);
|
||||
index++;
|
||||
}
|
||||
if (index > 8 * 6 ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ris = { arrnavi };
|
||||
|
||||
@@ -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: '' });
|
||||
|
||||
@@ -3,6 +3,7 @@ const router = express.Router();
|
||||
|
||||
const { User } = require('../models/user');
|
||||
const { Nave } = require('../models/nave');
|
||||
const { Flotta } = require('../models/flotta');
|
||||
const { NavePersistente } = require('../models/navepersistente');
|
||||
const { ListaIngresso } = require('../models/listaingresso');
|
||||
const { Graduatoria } = require('../models/graduatoria');
|
||||
@@ -135,7 +136,10 @@ router.post('/', async (req, res) => {
|
||||
user.profile.saw_and_accepted = recorig.profile.saw_and_accepted;
|
||||
user.profile.my_dream = recorig.profile.my_dream;
|
||||
user.profile.email_paypal = recorig.profile.email_paypal;
|
||||
user.profile.link_payment = recorig.profile.link_payment;
|
||||
user.profile.note_payment = recorig.profile.note_payment;
|
||||
user.profile.paymenttypes = recorig.profile.paymenttypes;
|
||||
user.profile.qualified = recorig.profile.qualified;
|
||||
let msgseconda = '!!! REGISTRATA ';
|
||||
if (numero === '2')
|
||||
msgseconda += 'SECONDA';
|
||||
@@ -312,6 +316,13 @@ router.post('/login', (req, res) => {
|
||||
tools.mylogshow(msg);
|
||||
// telegrambot.sendMsgTelegramToTheManagers(body.idapp, msg);
|
||||
res.status(404).send({ code: server_constants.RIS_CODE_LOGIN_ERR });
|
||||
} else if (!!user.subaccount && user.subaccount) {
|
||||
await tools.snooze(1000);
|
||||
// const msg = "Tentativo di Login ERRATO [" + body.username + ' , ' + body.password + ']\n' + '[IP: ' + tools.getiPAddressUser(req) + ']';
|
||||
// tools.mylogshow(msg);
|
||||
// telegrambot.sendMsgTelegramToTheManagers(body.idapp, msg);
|
||||
res.status(404).send({ code: server_constants.RIS_CODE_LOGIN_ERR_SUBACCOUNT });
|
||||
return null;
|
||||
}
|
||||
return user
|
||||
})
|
||||
@@ -364,7 +375,7 @@ router.post('/login', (req, res) => {
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
tools.mylog("ERRORE IN LOGIN: " + e);
|
||||
tools.mylog("ERRORE IN LOGIN: " + e.message);
|
||||
if (!resalreadysent)
|
||||
res.status(400).send({ code: server_constants.RIS_CODE_LOGIN_ERR_GENERIC });
|
||||
});
|
||||
@@ -411,16 +422,7 @@ async function eseguiDbOp(idapp, mydata, locale) {
|
||||
try {
|
||||
|
||||
if (mydata.dbop === 'rigeneraTutto') {
|
||||
|
||||
mydata.dbop = 'delNaviProvvisorie';
|
||||
await eseguiDbOp(idapp, mydata, locale);
|
||||
|
||||
mydata.dbop = 'GeneraGraduatoria';
|
||||
await eseguiDbOp(idapp, mydata, locale);
|
||||
|
||||
mydata.dbop = 'creaNavi';
|
||||
ris = await eseguiDbOp(idapp, mydata, locale);
|
||||
|
||||
await ListaIngresso.Esegui_CronTab(idapp, mydata);
|
||||
} else if (mydata.dbop === 'creaNavi') {
|
||||
const num = await Nave.generaNave(idapp, mydata, false);
|
||||
ris = { num };
|
||||
@@ -439,36 +441,8 @@ async function eseguiDbOp(idapp, mydata, locale) {
|
||||
// ris = { num };
|
||||
} else if (mydata.dbop === 'delNaviProvvisorie') {
|
||||
|
||||
let num = 0;
|
||||
ris = await Nave.delNaviProvvisorie(idapp);
|
||||
|
||||
const arrnavi = await Nave.find({ idapp });
|
||||
|
||||
for (const nave of arrnavi) {
|
||||
let persistente = await NavePersistente.findByRigaColByDonatore(idapp, nave.riga, nave.col, 0);
|
||||
if (!!persistente) {
|
||||
if (persistente.provvisoria) {
|
||||
let ris = await Nave.deleteOne({ _id: nave._id });
|
||||
if (!!ris) {
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Pulisci gli added se era stato cancellato dalla nave
|
||||
await Nave.pulisciNonPresenzeInNave(idapp);
|
||||
|
||||
const data = await Nave.getLastRigaCol(idapp);
|
||||
await Nave.setRiga(idapp, data.riga);
|
||||
await Nave.setCol(idapp, data.col + 1);
|
||||
|
||||
const maxcol = tools.getmaxcol(data.riga);
|
||||
if (data.col === maxcol) {
|
||||
await Nave.setRiga(idapp, data.riga + 1);
|
||||
await Nave.setCol(idapp, 1);
|
||||
}
|
||||
|
||||
ris = { num };
|
||||
} else if (mydata.dbop === 'visuListaNave') {
|
||||
mystr = await Nave.showListaOrd(idapp);
|
||||
ris = { mystr };
|
||||
@@ -494,6 +468,14 @@ async function eseguiDbOp(idapp, mydata, locale) {
|
||||
ris = { mystr };
|
||||
} else if (mydata.dbop === 'visuNaviUtentiEliminati') {
|
||||
ris = await Nave.visuNaviUtentiEliminati(idapp);
|
||||
} else if (mydata.dbop === 'convSubAccount') {
|
||||
ris = await User.convSubAccount(idapp);
|
||||
} else if (mydata.dbop === 'flagUtentiNaviNonPresenti') {
|
||||
ris = await User.flagUtentiNaviNonPresenti(idapp);
|
||||
} else if (mydata.dbop === 'generaFlotte') {
|
||||
ris = await NavePersistente.generaFlotte(idapp);
|
||||
} else if (mydata.dbop === 'addNavePerUtentiNaviNonPresenti') {
|
||||
ris = await User.addNavePerUtentiNaviNonPresenti(idapp);
|
||||
} else if (mydata.dbop === 'creaTessituraeConv') {
|
||||
ris = await ListaIngresso.creaTessituraeConv(idapp);
|
||||
ris = { mystr };
|
||||
@@ -506,6 +488,7 @@ async function eseguiDbOp(idapp, mydata, locale) {
|
||||
} else if (mydata.dbop === 'convNaviTessinListaIngressoRec') {
|
||||
let num = 0;
|
||||
|
||||
|
||||
const arrnavitess = await Nave.find({ idapp, num_tess: { $gte: 3 } });
|
||||
|
||||
for (const recnave of arrnavitess) {
|
||||
@@ -699,7 +682,7 @@ async function eseguiDbOp(idapp, mydata, locale) {
|
||||
} 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' +
|
||||
'NAVI CHE SALPANO DALLA ' + mydata.riga + '.' + mydata.col + ' ALLA ' + mydata.riga + '.' + (parseInt(mydata.col) + 7) + '\n' +
|
||||
'AUGURI ALLA NUOVA SOGNATRICE !!!\n' +
|
||||
'✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user