|
|
|
|
@@ -5,23 +5,23 @@ const tools = require('../tools/general');
|
|
|
|
|
|
|
|
|
|
const server_constants = require('../tools/server_constants');
|
|
|
|
|
|
|
|
|
|
const {authenticate} = require('../middleware/authenticate');
|
|
|
|
|
const { authenticate } = require('../middleware/authenticate');
|
|
|
|
|
|
|
|
|
|
const mongoose = require('mongoose').set('debug', false);
|
|
|
|
|
|
|
|
|
|
const {User} = require('../models/user');
|
|
|
|
|
const {MyGroup} = require('../models/mygroup');
|
|
|
|
|
const { User } = require('../models/user');
|
|
|
|
|
const { MyGroup } = require('../models/mygroup');
|
|
|
|
|
|
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
|
|
|
|
const {ObjectID} = require('mongodb');
|
|
|
|
|
const { ObjectID } = require('mongodb');
|
|
|
|
|
|
|
|
|
|
async function getGroupRecAdminsInfo(idapp, data) {
|
|
|
|
|
|
|
|
|
|
if (data && data.admins) {
|
|
|
|
|
for (const admin of data.admins) {
|
|
|
|
|
const myuser = await User.findOne({idapp, username: admin.username}, {'profile.img': 1}).lean();
|
|
|
|
|
admin.profile = {img: myuser.profile.img};
|
|
|
|
|
const myuser = await User.findOne({ idapp, username: admin.username }, { 'profile.img': 1 }).lean();
|
|
|
|
|
admin.profile = { img: myuser.profile.img };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -35,14 +35,33 @@ router.post('/load', authenticate, async (req, res) => {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
const {SendNotif} = require('../models/sendnotif');
|
|
|
|
|
const { SendNotif } = require('../models/sendnotif');
|
|
|
|
|
const { Circuit } = require('../models/circuit');
|
|
|
|
|
const { Account } = require('../models/account');
|
|
|
|
|
|
|
|
|
|
// Check if ìs a Notif to read
|
|
|
|
|
const idnotif = req.body['idnotif'] ? req.body['idnotif'] : '';
|
|
|
|
|
SendNotif.setNotifAsRead(idapp, usernameOrig, idnotif);
|
|
|
|
|
|
|
|
|
|
const whatshow = MyGroup.getWhatToShow(idapp, req.user.username);
|
|
|
|
|
let data = await MyGroup.findOne({idapp, groupname}, whatshow).lean();
|
|
|
|
|
let data = await MyGroup.findOne({ idapp, groupname }, whatshow).lean();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
if (data.mycircuits) {
|
|
|
|
|
for (let i = 0; i < data.mycircuits.length; i++) {
|
|
|
|
|
const mycirc = await Circuit.findOne({ idapp, name: data.mycircuits[i].circuitname }).lean();
|
|
|
|
|
data.mycircuits[i] = mycirc;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (data.mycircuits) {
|
|
|
|
|
for (let i = 0; i < data.mycircuits.length; i++) {
|
|
|
|
|
const mycirc = await Circuit.findOne({ idapp, name: data.mycircuits[i].circuitname }).lean();
|
|
|
|
|
if (mycirc)
|
|
|
|
|
data.mycircuits[i].account = await Account.getAccountByUsernameAndCircuitId(idapp, '', mycirc._id, true, groupname);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let cities = [];
|
|
|
|
|
if (data) {
|
|
|
|
|
@@ -57,16 +76,16 @@ router.post('/load', authenticate, async (req, res) => {
|
|
|
|
|
const whatshowUsers = await User.getWhatToShow_IfFriends(idapp, req.user.username);
|
|
|
|
|
|
|
|
|
|
const users_in_group = await User.find(
|
|
|
|
|
{
|
|
|
|
|
idapp,
|
|
|
|
|
'profile.mygroups': {
|
|
|
|
|
$elemMatch: {groupname: {$eq: groupname}},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
idapp,
|
|
|
|
|
'profile.mygroups': {
|
|
|
|
|
$elemMatch: { groupname: { $eq: groupname } },
|
|
|
|
|
},
|
|
|
|
|
whatshowUsers,
|
|
|
|
|
},
|
|
|
|
|
whatshowUsers,
|
|
|
|
|
).lean();
|
|
|
|
|
|
|
|
|
|
res.send({mygroup: data, users_in_group, cities});
|
|
|
|
|
res.send({ mygroup: data, users_in_group, cities });
|
|
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('Error in MyGroups', e);
|
|
|
|
|
|