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

@@ -30,7 +30,7 @@ module.exports = {
return Subscription.deleteOne({ userId: rec._id })
}
} catch (e) {
console.error(e);
console.error(e.message);
return false
}
return true;

View File

@@ -126,7 +126,7 @@ router.delete('/:id/:notify/:idapp', authenticate, (req, res) => {
// res.send({ bookedevent: arrdata[0], eventlist: arrdata[1], operators: arrdata[2], wheres: arrdata[3], contribtype: arrdata[4] });
// })
// .catch((e) => {
// console.log(e);
// console.log(e.message);
// res.status(400).send(e);
// });
//

View File

@@ -22,35 +22,40 @@ const _ = require('lodash');
const { ObjectID } = require('mongodb');
router.post('/', authenticate, async (req, res) => {
const idapp = req.body.idapp;
let username = req.body.username;
try {
const idapp = req.body.idapp;
let username = req.body.username;
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm)) && (username) !== req.user.username) {
// If without permissions, exit
return res.status(404).send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' });
}
let aportador_solidario = req.user.aportador_solidario;
let aportador_solidario_nome_completo = req.user.aportador_solidario_nome_completo;
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm)) && (username) !== req.user.username) {
// If without permissions, exit
return res.status(404).send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' });
}
let aportador_solidario = req.user.aportador_solidario;
let aportador_solidario_nome_completo = req.user.aportador_solidario_nome_completo;
// if (User.isAdmin(req.user.perm) || User.isManager(req.user.perm)) {
// const recuser = await User.findByUsername(idapp, username);
// if (recuser) {
// aportador_solidario_nome_completo = recuser.name + ' ' + recuser.surname;
// }
// }
// if (User.isAdmin(req.user.perm) || User.isManager(req.user.perm)) {
// const recuser = await User.findByUsername(idapp, username);
// if (recuser) {
// aportador_solidario_nome_completo = recuser.name + ' ' + recuser.surname;
// }
// }
if (username) {
aportador_solidario = await User.getAportadorSolidarioByUsername(idapp, username);
aportador_solidario_nome_completo = await User.getNameSurnameByUsername(idapp, username);
} else {
username = req.user.username;
}
if (username) {
aportador_solidario = await User.getAportadorSolidarioByUsername(idapp, username);
aportador_solidario_nome_completo = await User.getNameSurnameByUsername(idapp, username);
} else {
username = req.user.username;
}
const dashboard = await User.getDashboard(idapp, aportador_solidario, username, aportador_solidario_nome_completo);
if (dashboard)
res.send({ dashboard });
else
const dashboard = await User.getDashboard(idapp, aportador_solidario, username, aportador_solidario_nome_completo);
if (dashboard)
res.send({ dashboard });
else
res.status(400).send(e);
} catch (e) {
res.status(400).send(e);
}
});
@@ -188,7 +193,7 @@ router.post('/getdoninavi', authenticate, async (req, res) => {
else
res.status(400).send(e);
} catch (e) {
console.log(e)
console.log(e.message)
}
});
@@ -206,7 +211,7 @@ router.post('/getdata', authenticate, async (req, res) => {
else
res.status(400).send(e);
} catch (e) {
console.log(e)
console.log(e.message)
}
});

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 });
});

View File

@@ -106,7 +106,7 @@ router.get('/:userId/:idapp/:sall', authenticate, (req, res) => {
return MyEvent.findAllByUserIdAndIdApp(userId, idapp, sall).then((recevent) => {
res.send({ recevent });
}).catch((e) => {
console.log(e);
console.log(e.message);
res.status(400).send(e);
});

View File

@@ -207,7 +207,7 @@ async function ImportData(locale, idapp, strdata, settomailchimp) {
return ris
} catch (e) {
console.err(e);
console.err(e.message);
}
}

View File

@@ -128,7 +128,7 @@ router.get('/', (req, res) => {
}).then((objprojects) => {
res.send({ projects: objprojects.arrproj });
}).catch((e) => {
console.log(e);
console.log(e.message);
res.status(400).send(e);
});
});
@@ -159,7 +159,7 @@ router.get('/:userId', authenticate, (req, res) => {
res.send({ projects: objprojects.arrproj });
}).catch((e) => {
console.log(e);
console.log(e.message);
res.status(400).send(e);
});

View File

@@ -97,7 +97,7 @@ async function SendMsgTo(idapp, username, params) {
}
})
.catch(e => {
console.error(e);
console.error(e.message);
})
}
}

View File

@@ -77,7 +77,7 @@ router.post('/', authenticate, (req, res) => {
})
});
}).catch((e) => {
console.log(e);
console.log(e.message);
// res.status(400).send(e);
return res.send({ code: server_constants.RIS_CODE_ERR, msg: '' });
})
@@ -106,7 +106,7 @@ router.get('/:username/:lastdataread/:idapp', authenticate, (req, res) => {
// });
}).catch((e) => {
console.log(e);
console.log(e.message);
res.status(400).send(e);
});

View File

@@ -10,6 +10,8 @@ const { authenticate } = require('../middleware/authenticate');
const mongoose = require('mongoose');
const { User } = require('../models/user');
const { Nave } = require('../models/nave');
const { ListaIngresso } = require('../models/listaingresso');
const _ = require('lodash');
@@ -24,6 +26,8 @@ router.post('/load', async (req, res) => {
let datastat = {
num_reg: await User.getUsersRegistered(idapp),
num_passeggeri: await Nave.getTotInLista(idapp) + await ListaIngresso.getTotInLista(idapp),
num_imbarcati: await ListaIngresso.getTotInLista(idapp),
email_non_verif: await User.getEmailNotVerified(idapp),
num_teleg_attivo: await User.getUsersTelegramAttivo(idapp),
num_teleg_pending: await User.getUsersTelegramPending(idapp),
@@ -35,8 +39,11 @@ router.post('/load', async (req, res) => {
arr_nations: await User.findAllDistinctNationality(idapp),
numreg_untilday: await User.calcnumRegUntilDay(idapp),
reg_daily: await User.calcRegDaily(idapp),
reg_weekly: await User.calcRegWeekly(idapp),
lastsreg: await User.getLastUsers(idapp),
checkuser: await User.checkUser(idapp, username),
// navi_partite: await Nave.getNaviPartite(idapp),
// navi_in_partenza: await Nave.getNaviInPartenza(idapp),
};

View File

@@ -135,7 +135,7 @@ router.get('/:userId', authenticate, (req, res) => {
res.send({ todos: objtodos.arrtodos, categories: objtodos.arrcategories });
}).catch((e) => {
console.log(e);
console.log(e.message);
res.status(400).send(e);
});
@@ -185,7 +185,7 @@ router.get('/', (req, res) => {
res.send({ todos: objtodos.arrtodos, categories: objtodos.arrcategories });
}).catch((e) => {
console.log(e);
console.log(e.message);
res.status(400).send(e);
});

View File

@@ -141,12 +141,13 @@ router.post('/', async (req, res) => {
user.ind_order = lastindorder + 1;
const numero = user.name.slice(-1);
if ((numero === '2') || (numero === '3') || (numero === '4')) {
if ((numero === '2') || (numero === '3') || (numero === '4') || (numero === '5') || (numero === '6')) {
recorig = await User.findByCellAndNameSurname(user.idapp, user.profile.cell, user.name.slice(0, -1), user.surname);
if (!!recorig) {
user.profile.teleg_id = recorig.profile.teleg_id;
user.profile.saw_zoom_presentation = recorig.profile.saw_zoom_presentation;
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.paymenttypes = recorig.profile.paymenttypes;
let msgseconda = '!!! REGISTRATA ';
@@ -465,7 +466,7 @@ router.post('/dbop', authenticate, async (req, res) => {
} else if (mydata.dbop === 'visuListaNave') {
mystr = await Nave.showListaOrd(idapp);
ris = { mystr };
} else if (mydata.dbop === 'visuUtentiNonInNavi') {
} else if (mydata.dbop === 'visuStat') {
ris = await User.visuUtentiNonInNavi(idapp);
} else if (mydata.dbop === 'pulisciNonPresenzeInNave') {
mystr = await Nave.pulisciNonPresenzeInNave(idapp);
@@ -616,12 +617,34 @@ router.post('/dbop', authenticate, async (req, res) => {
ris = { num };
} else if (mydata.dbop === 'visuPlacca') {
const rec = {};
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' +
'AUGURI ALLA NUOVA SOGNATRICE !!!\n' +
'✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨';
const visu_nave_Bot = await Settings.getValDbSettings(idapp, 'VISU_NAVE_BOT');
for (let ind = 0; ind < 8; ind++) {
mystr += await Nave.getNavePos(idapp, parseInt(mydata.riga), parseInt(mydata.col) + ind, false);
mystr += tools.ACAPO;
if (visu_nave_Bot && ind === 3) {
await telegrambot.sendMsgTelegramToTheAdmin(idapp, mystr, true);
mystr = '';
}
}
if (visu_nave_Bot)
await telegrambot.sendMsgTelegramToTheAdmin(idapp, mystr, true);
ris = { mystr };
/*const rec = {};
const placca = await Nave.getPlaccaPerDonatore(idapp, parseInt(mydata.riga), parseInt(mydata.col), false, rec);
telegrambot.sendMsgTelegramToTheAdmin(idapp, placca);
ris = { placca };
ris = { placca };*/
} else if (mydata.dbop === 'visuNave') {
mystr = await Nave.getNavePos(idapp, parseInt(mydata.riga), parseInt(mydata.col));
@@ -652,7 +675,7 @@ router.post('/dbop', authenticate, async (req, res) => {
res.send(ris);
} catch (e) {
console.log(e);
console.log(e.message);
}
}
);