Sistemazioni...
This commit is contained in:
@@ -16,6 +16,9 @@ module.exports = {
|
||||
doOtherThingsAfterDeleted: async function (tablename, rec, notifBot, req) {
|
||||
try {
|
||||
let ris = null;
|
||||
|
||||
const { ListaIngresso } = require('../../models/listaingresso');
|
||||
|
||||
if (tablename === 'users') {
|
||||
|
||||
await ListaIngresso.deleteUserInListaIngresso(rec.idapp, rec.username);
|
||||
@@ -42,7 +45,7 @@ module.exports = {
|
||||
ris = await Graduatoria.deleteOne({ idListaIngresso: ObjectID(rec._id) });
|
||||
if (!!ris) {
|
||||
|
||||
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} )` ;
|
||||
let msg = 'Eliminato dalla Graduatoria 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);
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ router.post('/msgnave', authenticate, async (req, res) => {
|
||||
// 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);
|
||||
ris = await telegrambot.sendMsgTelegramToNave(idapp, mydata, res);
|
||||
|
||||
if (ris)
|
||||
res.send({ code: server_constants.RIS_CODE_OK, ris });
|
||||
@@ -123,7 +123,7 @@ router.post('/msgflotta', authenticate, async (req, res) => {
|
||||
try {
|
||||
|
||||
let ris = null;
|
||||
ris = await telegrambot.sendMsgTelegramToNave(idapp, mydata);
|
||||
ris = await telegrambot.sendMsgTelegramToNave(idapp, mydata, res);
|
||||
|
||||
if (ris)
|
||||
res.send({ code: server_constants.RIS_CODE_OK, ris });
|
||||
@@ -190,8 +190,10 @@ 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);
|
||||
if (!!nave._doc.rec) {
|
||||
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);
|
||||
@@ -236,12 +238,14 @@ router.post('/getflotta', authenticate, async (req, res) => {
|
||||
const col_prima = req.body.col_prima;
|
||||
const col_ultima = req.body.col_ultima;
|
||||
|
||||
// const ris2 = await NavePersistente.aggiornaFlottaByNavePersistente(idapp, {riga, col1don: col_prima });
|
||||
|
||||
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 });
|
||||
res.send({ code: server_constants.RIS_CODE_OK, flotta: ris.flotta, arrdonatori: ris.arrdonatori, arrmediatori: ris.arrmediatori });
|
||||
else
|
||||
res.status(400).send(e);
|
||||
|
||||
|
||||
@@ -389,6 +389,7 @@ router.patch('/chval', authenticate, async (req, res) => {
|
||||
|
||||
const mytable = getTableByTableName(mydata.table);
|
||||
const fieldsvalue = mydata.fieldsvalue;
|
||||
const unset = mydata.unset;
|
||||
|
||||
// tools.mylogshow('PATCH CHVAL: ', id, fieldsvalue);
|
||||
|
||||
@@ -416,6 +417,39 @@ router.patch('/chval', authenticate, async (req, res) => {
|
||||
|
||||
let index = 0;
|
||||
|
||||
let recoldnave = null;
|
||||
|
||||
let myuser = null;
|
||||
let mydatamsg = {};
|
||||
|
||||
let flotta = null;
|
||||
let strflotta = '';
|
||||
|
||||
if (mydata.table === 'navi') {
|
||||
if (!!id) {
|
||||
recoldnave = await mytable.findOne({ _id: ObjectID(id) });
|
||||
|
||||
let mypos = {
|
||||
idapp,
|
||||
riga: recoldnave.riga,
|
||||
col: recoldnave.col,
|
||||
numup: 3
|
||||
};
|
||||
tools.getRigaColByPosUp(mypos);
|
||||
mydatamsg = {
|
||||
navemediatore: { riga: mypos.riga, col: mypos.col },
|
||||
};
|
||||
|
||||
if (!!fieldsvalue.riga) {
|
||||
flotta = await Flotta.getFlottaByRigaColDonatore(idapp, fieldsvalue.riga, fieldsvalue.col);
|
||||
if (!!flotta) {
|
||||
strflotta = Flotta.getStrFlotta(flotta);
|
||||
}
|
||||
myuser = await User.findByIndOrder(idapp, recoldnave.ind_order);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await mytable.findByIdAndUpdate(id, { $set: fieldsvalue }).then(async (rec) => {
|
||||
// tools.mylogshow(' REC TO MODIFY: ', rec);
|
||||
if (!rec) {
|
||||
@@ -423,24 +457,14 @@ router.patch('/chval', authenticate, async (req, res) => {
|
||||
} 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 },
|
||||
};
|
||||
mydatamsg.tipomsg = tools.TipoMsg.SEND_MSG_DONO_RICEVUTO_CORRETTAMENTE;
|
||||
const rismsg = await telegrambot.getMsgByTipoMsg(mydatamsg, myuser.lang, myuser, false);
|
||||
addmsg = rismsg.body;
|
||||
}
|
||||
@@ -448,6 +472,29 @@ router.patch('/chval', authenticate, async (req, res) => {
|
||||
|
||||
await mytable.findByIdAndUpdate(id, { $set: { received_gift: true } });
|
||||
}
|
||||
|
||||
if (!!unset) {
|
||||
const risunset = await mytable.findByIdAndUpdate(id, { $unset: unset });
|
||||
if (!!risunset) {
|
||||
if ('date_made_gift' in unset) {
|
||||
addtext = strflotta + ` E' stato annullato l'invio del dono di ${myuser.name} ${myuser.surname} (${myuser.username}) da parte di ${req.user.name} ${req.user.surname} - [Posiz: ${fieldsvalue.riga}.${fieldsvalue.col}]`;
|
||||
telegrambot.sendMsgTelegramToTheManagers(idapp, addtext, false);
|
||||
tools.writeFlottaLog(idapp, addtext, flotta.riga, flotta.col_prima);
|
||||
|
||||
if (!!recoldnave) {
|
||||
if (!!recoldnave.date_made_gift) {
|
||||
// Se l'utente aveva confermato il Dono, allora gli mando un msg che non è stato ricevuto ...
|
||||
mydatamsg.tipomsg = tools.TipoMsg.SEND_MSG_DONO_NON_RICEVUTO;
|
||||
const rismsg = await telegrambot.getMsgByTipoMsg(mydatamsg, myuser.lang, myuser, false);
|
||||
let mymsg = rismsg.body;
|
||||
if (!!mymsg) {
|
||||
await telegrambot.sendMsgTelegram(idapp, myuser.username, mymsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SEND_MSG_DONO_RICEVUTO_CORRETTAMENTE
|
||||
@@ -459,6 +506,9 @@ router.patch('/chval', authenticate, async (req, res) => {
|
||||
await telegrambot.sendMsgTelegram(idapp, mydata.notifBot.un, addmsg);
|
||||
addtext = '[Msg Inviato a ' + mydata.notifBot.un + ']:' + '\n' + mydata.notifBot.txt;
|
||||
telegrambot.sendMsgTelegramToTheManagers(idapp, addtext, true);
|
||||
|
||||
if (!!flotta)
|
||||
tools.writeFlottaLog(idapp, addtext, flotta.riga, flotta.col_prima);
|
||||
}
|
||||
|
||||
if (mydata.table === 'users') {
|
||||
@@ -679,6 +729,7 @@ 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 dall'ultima Nave Temporanea
|
||||
|
||||
miaarrnavi = await Nave.getArrPosizioniByUsername(idapp, username);
|
||||
@@ -704,48 +755,16 @@ router.patch('/callfunz', authenticate, async (req, res) => {
|
||||
if (!!myusernuovo) {
|
||||
if (!!mianavedasost && mianavedasost.ind_order >= 0) {
|
||||
|
||||
// Metti campo 'delete': true su ListaIngresso
|
||||
olduseringresso = await ListaIngresso.findById(mianavedasost.idListaIngresso);
|
||||
if (!!olduseringresso) {
|
||||
let fieldsvalue = {
|
||||
date_deleted: new Date(),
|
||||
deleted: true
|
||||
};
|
||||
const risul = await ListaIngresso.findByIdAndUpdate(mianavedasost.idListaIngresso, { $set: fieldsvalue }, { new: false });
|
||||
if (!!risul) {
|
||||
const myrecuser = await ListaIngresso.getIngrEUserByFilter(idapp, {
|
||||
idapp,
|
||||
username: username_da_sostituire,
|
||||
_id: ObjectID(mianavedasost.idListaIngresso)
|
||||
});
|
||||
// ELIMINO LA LISTAINGRESSO CHE STO SOSTITUENDO (SOLO SE NON VIENE USATA DA ALTRA NAVE!)
|
||||
let eliminatoingr = await ListaIngresso.eliminaListaIngresso(idapp, mianavedasost.ind_order, req, mianavedasost.num_tess);
|
||||
|
||||
if (!!myrecuser) {
|
||||
const risdel = await ListaIngresso.deleteOne({ _id: olduseringresso.id });
|
||||
|
||||
if (!!risdel) {
|
||||
await actions.doOtherThingsAfterDeleted('listaingressos', myrecuser, false, req)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!eliminatoingr){
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, msg: 'La Sostituzione non può avvenire ! Contattare Paolo. (ind_order=' + mianavedasost.ind_order + ')' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!!myuservecchio) {
|
||||
// Se ha gia delle altre navi, non cancellarlo!
|
||||
if (!await Nave.checkIfMadeGift(idapp, myuservecchio.username)) {
|
||||
|
||||
if (mydata.data.deleteUser && !!mianavedasost && mianavedasost.ind_order > 0) {
|
||||
// Metti Deleted allo User
|
||||
fieldsvalue = {
|
||||
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} )`);
|
||||
}
|
||||
}
|
||||
|
||||
if (mydata.data.notifBot) {
|
||||
|
||||
const mydatamsg = {
|
||||
@@ -766,6 +785,20 @@ router.patch('/callfunz', authenticate, async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
// Se ha gia delle altre navi, non cancellarlo!
|
||||
if (!await Nave.checkIfMadeGift(idapp, myuservecchio.username)) {
|
||||
|
||||
if (mydata.data.deleteUser && !!mianavedasost && mianavedasost.ind_order > 0) {
|
||||
// Metti Deleted allo User
|
||||
fieldsvalue = {
|
||||
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} )`);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -791,12 +824,11 @@ router.patch('/callfunz', authenticate, async (req, res) => {
|
||||
}
|
||||
|
||||
// Togliolo dalla Graduatoria!
|
||||
const mygrad = await Graduatoria.findOneAndUpdate({
|
||||
await Graduatoria.findOneAndUpdate({
|
||||
idapp,
|
||||
idListaIngresso: myingr._id
|
||||
}, { $set: { ind_order: -1 } }, { new: false });
|
||||
|
||||
|
||||
// Aggiorna la Nave con il Nuovo
|
||||
fieldsvalue = {
|
||||
ind_order
|
||||
@@ -805,9 +837,9 @@ router.patch('/callfunz', authenticate, async (req, res) => {
|
||||
const dachi = req.user.name + ' ' + req.user.surname;
|
||||
|
||||
return await Nave.findByIdAndUpdate(mianavedasost.id, { $set: fieldsvalue })
|
||||
.then(async (rec) => {
|
||||
.then(async (nave) => {
|
||||
// tools.mylogshow(' REC TO MODIFY: ', rec);
|
||||
if (!rec) {
|
||||
if (!nave) {
|
||||
return res.status(404).send();
|
||||
} else {
|
||||
|
||||
@@ -850,10 +882,11 @@ router.patch('/callfunz', authenticate, async (req, res) => {
|
||||
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 + ']';
|
||||
const msgsost = '[NAVE ' + navepersistente.riga + '.' + navepersistente.col + '] Sostituito ' + myuservecchio.username + ' (' + myuservecchio.name + ' ' + myuservecchio.surname + ') ' + ' con -> ' + myusernuovo.username + ' (' + myusernuovo.name + ' ' + myusernuovo.surname + '' +
|
||||
') [Posiz. ' + nave.riga + '.' + nave.col + ' ind_order=' + nave.ind_order + '] ' + ' [da ' + dachi + ']';
|
||||
tools.writeSostituzioniLog(msgsost);
|
||||
tools.writeFlottaLog(idapp, msgsost, mydatamsg.flotta.riga, mydatamsg.flotta.col_prima);
|
||||
await telegrambot.sendMsgTelegramToTheManagers(idapp, msgsost);
|
||||
await telegrambot.sendMsgTelegramToTheManagers(idapp, msgsost, false);
|
||||
|
||||
// const nomecognomeprima = myuser.name + ' ' + myuser.surname + '(' + myuser.username + ')';
|
||||
// const nomecognomenuovo = await User.getNameSurnameByUsername(idapp,);
|
||||
@@ -894,28 +927,11 @@ router.patch('/callfunz', authenticate, async (req, res) => {
|
||||
|
||||
if (!!myrec) {
|
||||
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 });
|
||||
|
||||
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
|
||||
}
|
||||
const risdel = await ListaIngresso.eliminaListaIngresso(idapp, mydata.ind_order, req, mydata.data.num_tess);
|
||||
|
||||
if (risdel) {
|
||||
return await actions.doOtherThingsAfterDeleted('listaingressos', myrec, false, req)
|
||||
.then((ris) => {
|
||||
|
||||
if (!!ris) {
|
||||
|
||||
// tools.mylog('DELETED Others things ...');
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, msg: '' });
|
||||
}
|
||||
});
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, msg: '' });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -981,7 +997,7 @@ router.delete('/delrec/:table/:id', authenticate, async (req, res) => {
|
||||
notifBot = tools.NotifyIfDelRecord(tablename);
|
||||
let myrec = null;
|
||||
|
||||
if (!User.isAdmin(req.user.perm) || !User.isManager(req.user.perm)) {
|
||||
if (!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm)) {
|
||||
if (tablename === 'users') {
|
||||
|
||||
let fieldsvalue = {
|
||||
|
||||
@@ -136,6 +136,7 @@ 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.revolut = recorig.profile.revolut;
|
||||
user.profile.link_payment = recorig.profile.link_payment;
|
||||
user.profile.note_payment = recorig.profile.note_payment;
|
||||
user.profile.paymenttypes = recorig.profile.paymenttypes;
|
||||
|
||||
Reference in New Issue
Block a user