Sistemazioni...
This commit is contained in:
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user