|
|
|
|
@@ -34,7 +34,7 @@ const Product = require('../models/product');
|
|
|
|
|
const Variant = require('../models/variant');
|
|
|
|
|
const TypedError = require('../modules/ErrorHandler');
|
|
|
|
|
|
|
|
|
|
const { MyGroup } = require('../models/mygroup');
|
|
|
|
|
const {MyGroup} = require('../models/mygroup');
|
|
|
|
|
|
|
|
|
|
const mongoose = require('mongoose').set('debug', false);
|
|
|
|
|
const Subscription = mongoose.model('subscribers');
|
|
|
|
|
@@ -192,7 +192,8 @@ router.post('/', async (req, res) => {
|
|
|
|
|
|
|
|
|
|
recuser = await User.findByCellAndNameSurname(user.idapp, user.profile.cell,
|
|
|
|
|
user.name, user.surname);
|
|
|
|
|
if (recuser && user.name !== '' && user.surname !== '' && user.profile.cell !== '') {
|
|
|
|
|
if (recuser && user.name !== '' && user.surname !== '' &&
|
|
|
|
|
user.profile.cell !== '') {
|
|
|
|
|
console.log('UTENTE GIA ESISTENTE:\n');
|
|
|
|
|
console.log(user);
|
|
|
|
|
// User already registered!
|
|
|
|
|
@@ -211,16 +212,20 @@ router.post('/', async (req, res) => {
|
|
|
|
|
// nomeaportador_corretto = recextra.aportador_solidario_originale_name_surname;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const id_aportador = await User.getIdByUsername(user.idapp, user.aportador_solidario);
|
|
|
|
|
const id_aportador = await User.getIdByUsername(user.idapp,
|
|
|
|
|
user.aportador_solidario);
|
|
|
|
|
|
|
|
|
|
if (!id_aportador && tools.getAskToVerifyReg(body.idapp)) {
|
|
|
|
|
// Si sta tentando di registrare una persona sotto che non corrisponde!
|
|
|
|
|
let msg = 'Il link di registrazione non sembra risultare valido.<br>invitante: ' + user.aportador_solidario + '<br>username: ' + user.username;
|
|
|
|
|
let msg = 'Il link di registrazione non sembra risultare valido.<br>invitante: ' +
|
|
|
|
|
user.aportador_solidario + '<br>username: ' + user.username;
|
|
|
|
|
|
|
|
|
|
await telegrambot.sendMsgTelegramToTheManagers(user.idapp, msg);
|
|
|
|
|
res.status(400).send({ code: server_constants.RIS_CODE_USER_APORTADOR_NOT_VALID, msg: '' });
|
|
|
|
|
res.status(400).
|
|
|
|
|
send({
|
|
|
|
|
code: server_constants.RIS_CODE_USER_APORTADOR_NOT_VALID,
|
|
|
|
|
msg: '',
|
|
|
|
|
});
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -335,12 +340,17 @@ router.post('/profile', authenticate, (req, res) => {
|
|
|
|
|
|
|
|
|
|
//++Todo: controlla che tipo di dati ha il permesso di leggere
|
|
|
|
|
|
|
|
|
|
return User.getUserProfileByUsername(idapp, username, req.user.username, false, req.user.perm).then((ris) => {
|
|
|
|
|
res.send(ris);
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
tools.mylog('ERRORE IN Profile: ' + e.message);
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
});
|
|
|
|
|
return User.getUserProfileByUsername(idapp, username, req.user.username, false, req.user.perm).
|
|
|
|
|
then((ris) => {
|
|
|
|
|
|
|
|
|
|
return User.getFriendsByUsername(idapp, req.user.username).then((friends) => {
|
|
|
|
|
res.send({user: ris, friends });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
tools.mylog('ERRORE IN Profile: ' + e.message);
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@@ -498,7 +508,6 @@ router.post('/groups', authenticate, (req, res) => {
|
|
|
|
|
idapp = req.body.idapp;
|
|
|
|
|
locale = req.body.locale;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return MyGroup.getGroupsByUsername(idapp, username, req).then((ris) => {
|
|
|
|
|
res.send(ris);
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
@@ -520,16 +529,19 @@ router.post('/friends/cmd', authenticate, (req, res) => {
|
|
|
|
|
if (!User.isAdmin(req.user.perm) || !User.isManager(req.user.perm)) {
|
|
|
|
|
// If without permissions, exit
|
|
|
|
|
if (usernameOrig !== usernameLogged) {
|
|
|
|
|
return res.status(404).send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
|
|
|
|
|
return res.status(404).
|
|
|
|
|
send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return User.setFriendsCmd(idapp, usernameOrig, usernameDest, cmd, value).then((ris) => {
|
|
|
|
|
res.send(ris);
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
tools.mylog('ERRORE IN Friends/cmd: ' + e.message);
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
});
|
|
|
|
|
return User.setFriendsCmd(idapp, usernameOrig, usernameDest, cmd, value).
|
|
|
|
|
then((ris) => {
|
|
|
|
|
res.send(ris);
|
|
|
|
|
}).
|
|
|
|
|
catch((e) => {
|
|
|
|
|
tools.mylog('ERRORE IN Friends/cmd: ' + e.message);
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@@ -545,16 +557,19 @@ router.post('/groups/cmd', authenticate, (req, res) => {
|
|
|
|
|
if (!User.isAdmin(req.user.perm) || !User.isManager(req.user.perm)) {
|
|
|
|
|
// If without permissions, exit
|
|
|
|
|
if (usernameOrig !== usernameLogged) {
|
|
|
|
|
return res.status(404).send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
|
|
|
|
|
return res.status(404).
|
|
|
|
|
send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return User.setGroupsCmd(idapp, usernameOrig, groupnameDest, cmd, value).then((ris) => {
|
|
|
|
|
res.send(ris);
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
tools.mylog('ERRORE IN groups/cmd: ' + e.message);
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
});
|
|
|
|
|
return User.setGroupsCmd(idapp, usernameOrig, groupnameDest, cmd, value).
|
|
|
|
|
then((ris) => {
|
|
|
|
|
res.send(ris);
|
|
|
|
|
}).
|
|
|
|
|
catch((e) => {
|
|
|
|
|
tools.mylog('ERRORE IN groups/cmd: ' + e.message);
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@@ -892,10 +907,10 @@ async function eseguiDbOp(idapp, mydata, locale) {
|
|
|
|
|
await mytable.DuplicateAllRecords(idapporig, idappdest).
|
|
|
|
|
then((numrec) => {
|
|
|
|
|
// tools.mylogshow(' REC TO MODIFY: ', rec);
|
|
|
|
|
numrectot += numrec
|
|
|
|
|
numrectot += numrec;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}catch (e){
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log('e', e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|