- aggiunto Elena come admin di tutti i circuiti ...

shared_consts.USER_ADMIN_CIRCUITS
This commit is contained in:
Surya Paolo
2025-10-27 13:34:06 +01:00
parent 8f54cd2791
commit 38c13eef28
5 changed files with 119 additions and 97 deletions

View File

@@ -20,19 +20,18 @@ const _ = require('lodash');
const { ObjectId } = require('mongodb');
async function getCircuitRecAdminsInfo(idapp, data) {
try {
if (data && data.admins) {
for (const admin of data.admins) {
const myuser = await User.findOne({ idapp, username: admin.username }, { 'profile.img': 1 }).lean();
if (myuser && myuser.profile)
admin.profile = { img: myuser.profile.img };
if (myuser && myuser.profile) admin.profile = { img: myuser.profile.img };
}
if (data.admins.length === 0) {
data.admins.push({username: shared_consts.USER_ADMIN_CIRCUITS})
for (const admin of shared_consts.USER_ADMIN_CIRCUITS) {
data.admins.push({ username: admin });
}
}
}
} catch (e) {
console.error(e);
@@ -48,7 +47,6 @@ router.post('/load', authenticate, async (req, res) => {
const usernameOrig = req.user.username;
try {
const { SendNotif } = require('../models/sendnotif');
const { Movement } = require('../models/movement');
@@ -80,7 +78,7 @@ router.post('/load', authenticate, async (req, res) => {
if (data === null) {
data = null;
}
const users_in_circuit = await Circuit.getUsersSingleCircuit(idapp, req.user.username, data.name, data._id);
data = await getCircuitRecAdminsInfo(idapp, data);
@@ -94,11 +92,23 @@ router.post('/load', authenticate, async (req, res) => {
}
let arrrecnotifcoins = null;
const arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(req.user.username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.QualiNotifs.OTHERS);
const arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(
req.user.username,
lastdr,
idapp,
shared_consts.LIMIT_NOTIF_FOR_USER,
shared_consts.QualiNotifs.OTHERS
);
if (User.isAdminById(req.user.id)) {
arrrecnotifcoins = await SendNotif.findAllNotifCoinsAllIdAndIdApp(idapp);
} else {
arrrecnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(req.user.username, lastdr, idapp, shared_consts.LIMIT_NOTIFCOINS_FOR_USER, shared_consts.QualiNotifs.CIRCUITS);
arrrecnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(
req.user.username,
lastdr,
idapp,
shared_consts.LIMIT_NOTIFCOINS_FOR_USER,
shared_consts.QualiNotifs.CIRCUITS
);
}
/// E' QUIIII !!!!
const useraccounts = await Account.getUserAccounts(idapp, req.user.username);
@@ -106,14 +116,12 @@ router.post('/load', authenticate, async (req, res) => {
await User.setLastCircuitOpened(idapp, req.user.username, path);
res.send({ circuit: data, users_in_circuit, arrrecnotif, arrrecnotifcoins, useraccounts });
} catch (e) {
console.error('Error in Circuits', e);
return res.status(400).send(e);
}
const ris = null;
});
module.exports = router;