Add to the Circuit

Remove to the Circuit
Revoke request
Users Admins
This commit is contained in:
paoloar77
2022-09-02 02:25:38 +02:00
parent f55d69b7fe
commit 6bee366547
20 changed files with 598 additions and 274 deletions

View File

@@ -45,23 +45,24 @@ router.post('/load', authenticate, async (req, res) => {
const whatshow = Circuit.getWhatToShow(idapp, req.user.username);
let data = await Circuit.findOne({idapp, path}, whatshow).lean();
let cities = [];
const whatshowUsers = await User.getWhatToShow_IfFriends(idapp, req.user.username);
let users_in_circuit = [];
if (data && data.circuitId) {
if (data) {
users_in_circuit = await User.find(
{
idapp,
circuitId: data.circuitId,
'profile.mycircuits': {
$elemMatch: {circuitname: {$eq: data.name}},
},
},
whatshowUsers,
).lean();
}
data = await getCircuitRecAdminsInfo(idapp, data);
const whatshowUsers = await User.getWhatToShow_IfFriends(idapp, req.user.username);
res.send({circuit: data, users_in_circuit});
} catch (e) {

View File

@@ -276,7 +276,7 @@ router.post('/settable', authenticate, async (req, res) => {
}
if (shared_consts.TABLES_USER_INCLUDE_MY.includes(params.table)) {
if (mydata.admins.length <= 0) {
if (!mydata.admins || mydata.admins.length <= 0) {
// Aggiungi solo se non esistono Admin:
mydata.admins = [];
const indfind = mydata.admins.findIndex(
@@ -321,6 +321,16 @@ router.post('/settable', authenticate, async (req, res) => {
if (alreadyexist) {
return res.send({code: server_constants.RIS_CODE_REC_ALREADY_EXIST_NAME});
}
} else if (params.table === shared_consts.TAB_MYCIRCUITS && isnewrec) {
// Controlla se esiste già con lo stesso nome
let alreadyexist = await Circuit.findOne({idapp, name: mydata.name});
if (alreadyexist) {
return res.send({code: server_constants.RIS_CODE_REC_ALREADY_EXIST_CODE});
}
alreadyexist = await Circuit.findOne({idapp, path: mydata.path});
if (alreadyexist) {
return res.send({code: server_constants.RIS_CODE_REC_ALREADY_EXIST_NAME});
}
}
if (shared_consts.TABLES_UPDATE_LASTMODIFIED.includes(params.table)) {
@@ -343,6 +353,7 @@ router.post('/settable', authenticate, async (req, res) => {
let typedir = 0;
let typeid = 0;
let groupnameDest = '';
let circuitnameDest = '';
if (isnewrec) {
// New Record created
@@ -367,10 +378,16 @@ router.post('/settable', authenticate, async (req, res) => {
groupnameDest = myrec ? myrec.groupname : '';
setnotif = true;
}
if (shared_consts.TABLES_CIRCUITS_NOTIFICATION.includes(params.table)) {
typedir = shared_consts.TypeNotifs.TYPEDIR_CIRCUITS;
typeid = shared_consts.TypeNotifs.ID_GROUP_NEW_REC;
circuitnameDest = myrec ? myrec.name : '';
setnotif = true;
}
}
if (setnotif) {
await SendNotif.createNewNotification(req, res, {groupnameDest}, params.table, myrec, typedir, typeid);
await SendNotif.createNewNotification(req, res, {groupnameDest, circuitnameDest}, params.table, myrec, typedir, typeid);
}
if (params.table === shared_consts.TAB_MYGROUPS && isnewrec) {
@@ -381,6 +398,13 @@ router.post('/settable', authenticate, async (req, res) => {
shared_consts.GROUPSCMD.SETGROUP, true, req.user.username).then((ris) => {
return res.send(myrec);
});
} else if (params.table === shared_consts.TAB_MYCIRCUITS && isnewrec) {
// nuovo Record:
// aggiungi il creatore al Circuito stesso
return User.setCircuitCmd(mydata.idapp, req.user.username, myrec.name,
shared_consts.CIRCUITCMD.SET, true, req.user.username).then((ris) => {
return res.send(myrec);
});
}
@@ -1000,6 +1024,9 @@ router.delete('/delrec/:table/:id', authenticate, async (req, res) => {
if (tablename === shared_consts.TAB_MYGROUPS) {
// Se è un gruppo, allora cancella anche tutti i suoi riferimenti
User.removeAllUsersFromMyGroups(rec.idapp, rec.groupname);
} else if (tablename === shared_consts.TAB_MYCIRCUITS) {
// Se è un gruppo, allora cancella anche tutti i suoi riferimenti
User.removeAllUsersFromMyCircuits(rec.idapp, rec.name);
}
tools.refreshAllTablesInMem(rec.idapp, tablename, true, rec.username);
@@ -1198,7 +1225,7 @@ function load(req, res, version) {
let myuserextra = null;
if (req.user) {
// askedfriends = User.getAskedFriendsByUsername(idapp, req.user.username);
myuserextra = User.addExtraInfo(idapp, req.user);
myuserextra = User.addExtraInfo(idapp, req.user, req);
}
return Promise.all([
@@ -1345,7 +1372,7 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate, async (req, res) => {
if (!arrcfgrec)
return res.status(404).send();
// ++Todo: Add to Log Stat ....
// ++Add to Log Stat ....
// const sall = '0';

View File

@@ -716,7 +716,7 @@ router.post('/circuits/cmd', authenticate, (req, res) => {
const idapp = req.body.idapp;
const locale = req.body.locale;
const usernameOrig = req.body.usernameOrig;
const name = req.body.name;
const circuitname = req.body.circuitname;
const cmd = req.body.cmd;
const value = req.body.value;
@@ -728,12 +728,12 @@ router.post('/circuits/cmd', authenticate, (req, res) => {
}
}*/
return User.setCircuitCmd(idapp, usernameOrig, name, cmd, value, usernameLogged).
return User.setCircuitCmd(idapp, usernameOrig, circuitname, cmd, value, usernameLogged).
then((ris) => {
res.send(ris);
}).
catch((e) => {
tools.mylog('ERRORE IN groups/cmd: ' + e.message);
tools.mylog('ERRORE IN circuits/cmd: ' + e.message);
res.status(400).send();
});