Aggiornamenti 2

This commit is contained in:
Paolo Arena
2020-05-04 19:34:41 +02:00
parent 2549d43447
commit 7d0538f7ae
29 changed files with 698 additions and 221 deletions

View File

@@ -55,6 +55,8 @@ const tools = require('../tools/general');
const server_constants = require('../tools/server_constants');
const actions = require('./api/actions');
const shared_consts = require('../tools/shared_nodejs');
UserCost = {
FIELDS_REQUISITI: ['verified_email',
'profile.teleg_id',
@@ -97,7 +99,7 @@ router.post(process.env.LINKVERIF_REG, (req, res) => {
}
}
}).catch((e) => {
console.log(e);
console.log(e.message);
res.status(400).send();
});
@@ -126,7 +128,7 @@ router.post(process.env.LINK_REQUEST_NEWPASSWORD, (req, res) => {
});
}
}).catch((e) => {
console.log(e);
console.log(e.message);
res.status(400).send();
res.send({ code: server_constants.RIS_CODE_ERR, msg: e });
});
@@ -166,7 +168,7 @@ router.post(process.env.LINK_UPDATE_PWD, (req, res) => {
})
}
}).catch((e) => {
console.log(e);
console.log(e.message);
res.status(400).send();
});
@@ -251,7 +253,7 @@ router.post('/settable', authenticate, (req, res) => {
return res.send(rec);
}).catch((e) => {
console.log(e);
console.log(e.message);
res.status(400).send(e);
});
@@ -270,7 +272,7 @@ router.post('/gettable', authenticate, (req, res) => {
return res.send(ris);
}).catch((e) => {
console.log(e);
console.log(e.message);
res.status(400).send(e);
});
@@ -370,7 +372,7 @@ router.patch('/chval', authenticate, async (req, res) => {
// tools.mylogshow('PATCH CHVAL: ', id, fieldsvalue);
// If I change my record...
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) && !User.isTutor(req.user.perm)) && !(req.user._id.toString() === id) && !tools.ModificheConsentite(mydata.table, fieldsvalue)) {
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) && !User.isTraduttrici(req.user.perm) && !User.isTutor(req.user.perm)) && !(req.user._id.toString() === id) && !tools.ModificheConsentite(mydata.table, fieldsvalue)) {
// If without permissions, exit
return res.status(404).send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' });
}
@@ -408,6 +410,23 @@ router.patch('/chval', authenticate, async (req, res) => {
}
}
if (mydata.table === 'users') {
if ('aportador_solidario' in fieldsvalue) {
const myuserfound = await User.findByUsername(idapp, fieldsvalue.aportador_solidario, false);
if (!!myuserfound) {
if (!!myuserfound._id && !myuserfound.deleted) {
fieldsvalue.aportador_solidario = await User.getUsernameById(idapp, myuserfound._id);
//Aggiorna record !
await mytable.findByIdAndUpdate(id, { $set: fieldsvalue });
}
} else {
res.send({ code: server_constants.RIS_CODE_ERR, msg: 'Non aggiornato' });
res.status(400).send();
return false;
}
}
}
if (tools.ModificheConsentite(mydata.table, fieldsvalue)) {
let msg = '';
if (mydata.table === 'users') {
@@ -454,17 +473,25 @@ router.patch('/callfunz', authenticate, async (req, res) => {
const mydata = req.body.data;
try {
// If I change my record...
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) && !User.isTutor(req.user.perm)) && !(req.user._id.toString() === id) && !tools.ModificheConsentite(mydata.table, fieldsvalue)) {
// If without permissions, exit
return res.status(404).send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' });
let entra = false;
if (mydata.myfunc === shared_consts.CallFunz.AGGIUNGI_NUOVO_IMBARCO ||
mydata.myfunc === shared_consts.CallFunz.CANCELLA_IMBARCO) {
entra = true
}
if (!entra) {
// If I change my record...
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) && !User.isTutor(req.user.perm)) && !(req.user._id.toString() === id) && !tools.ModificheConsentite(mydata.table, fieldsvalue)) {
// If without permissions, exit
return res.status(404).send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' });
}
}
const myuser = await User.findOne({ idapp, ind_order });
let rimosso = 0;
if (mydata.myfunc === 345) { // SOSTITUISCI
if (mydata.myfunc === shared_consts.CallFunz.SOSTITUISCI) { // SOSTITUISCI
mianavedasost = await Nave.findOne({ idapp, riga: mydata.data.riga, col: mydata.data.col });
// Sostituisci l'Utente
@@ -524,7 +551,7 @@ router.patch('/callfunz', authenticate, async (req, res) => {
if (!rec) {
return res.status(404).send();
} else {
if (mydata.notifBot) {
if (mydata.notifBot && !!navepersistente.link_chat) {
// Send Notification to the BOT
let messaggio = 'Sei stato Spostato in una Nuova Nave !';
@@ -557,9 +584,29 @@ router.patch('/callfunz', authenticate, async (req, res) => {
res.status(400).send();
})
}
} else if (mydata.myfunc === shared_consts.CallFunz.AGGIUNGI_NUOVO_IMBARCO) {
// Ottieni il prossimo Numero di Tessitura
let num_tess = await Nave.getNextNumTess(idapp, ind_order);
let listaingr = await ListaIngresso.find({ idapp, ind_order }).sort({ num_tess: 1 });
const trovato = listaingr.find((rec) => rec.num_tess === num_tess);
if (trovato) {
num_tess = listaingr.slice(-1)[0].num_tess + 2;
}
ris = await ListaIngresso.addUserInListaIngresso(idapp, ind_order, myuser.lang, true, num_tess);
arrimbarchi = await ListaIngresso.findAllByIndOrder(idapp, ind_order);
return res.send({ code: server_constants.RIS_CODE_OK, arrimbarchi });
} else if (mydata.myfunc === shared_consts.CallFunz.CANCELLA_IMBARCO) {
await ListaIngresso.remove({ idapp, ind_order, num_tess: mydata.data.num_tess });
return res.send({ code: server_constants.RIS_CODE_OK });
}
} catch (e) {
console.log(e);
console.log(e.message);
res.status(400).send();
}
});
@@ -644,7 +691,7 @@ router.delete('/delrec/:table/:id', authenticate, async (req, res) => {
tools.mylog('DELETED ', rec._id);
}).catch((e) => {
console.log(e);
console.log(e.message);
res.status(400).send();
});
}
@@ -719,7 +766,7 @@ router.post('/duprec/:table/:id', authenticate, (req, res) => {
});
}).catch((e) => {
console.error(e);
console.error(e.message);
res.status(400).send();
});
})
@@ -800,7 +847,7 @@ router.get('/loadsite/:userId/:idapp/:sall', authenticate_noerror, (req, res) =>
});
})
.catch((e) => {
console.log(e);
console.log(e.message);
res.status(400).send(e);
});
@@ -850,7 +897,7 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate, async (req, res) => {
});
}).catch((e) => {
console.log(e);
console.log(e.message);
res.status(400).send({ code: server_constants.RIS_CODE_ERR, msg: e });
});