Group Page : visibility, some info, members views.
This commit is contained in:
@@ -181,6 +181,7 @@ CitySchema.statics.executeQueryPickup = async function(idapp, params) {
|
||||
|
||||
};
|
||||
|
||||
|
||||
CitySchema.statics.findAllIdApp = async function(idapp) {
|
||||
const myfind = {};
|
||||
|
||||
|
||||
@@ -368,6 +368,54 @@ MyGroupSchema.statics.getGroupsByUsername = async function(idapp, username, req)
|
||||
};
|
||||
};
|
||||
|
||||
MyGroupSchema.statics.extractCitiesName = async function(idapp, id) {
|
||||
|
||||
try {
|
||||
let aggr1 = [
|
||||
{
|
||||
$match: {idapp, _id: id},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'cities',
|
||||
localField: 'idCity',
|
||||
foreignField: '_id',
|
||||
as: 'mycities',
|
||||
},
|
||||
},
|
||||
{
|
||||
'$replaceRoot': {
|
||||
'newRoot': {
|
||||
'$mergeObjects': [
|
||||
{
|
||||
'$arrayElemAt': [
|
||||
'$mycities',
|
||||
0,
|
||||
],
|
||||
},
|
||||
'$$ROOT',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
"mycities.comune": 1,
|
||||
"mycities.prov": 1
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
ris = await this.aggregate(aggr1);
|
||||
|
||||
return ris;
|
||||
}catch (e) {
|
||||
console.error('e', e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
const MyGroup = mongoose.model('MyGroup', MyGroupSchema);
|
||||
|
||||
module.exports = {MyGroup};
|
||||
|
||||
@@ -1925,6 +1925,9 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
|
||||
} else if (cmd === shared_consts.GROUPSCMD.REMOVE_FROM_MYGROUP) {
|
||||
|
||||
// Remove if is also an Admin
|
||||
await MyGroup.removeAdminOfMyGroup(idapp, usernameOrig, groupnameDest);
|
||||
|
||||
ris = await User.removeFromMyGroups(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me
|
||||
console.log('ris', ris);
|
||||
|
||||
@@ -2059,6 +2062,9 @@ UserSchema.statics.getWhatToShow_IfFriends = async function(idapp, username) {
|
||||
'profile.sex': 1,
|
||||
'profile.born_province': 1,
|
||||
'profile.born_country': 1,
|
||||
reported: 1,
|
||||
date_report: 1,
|
||||
username_who_report: 1,
|
||||
date_reg: 1,
|
||||
groups: 1,
|
||||
friends: 1,
|
||||
|
||||
@@ -340,9 +340,14 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
let typeid = 0;
|
||||
let groupnameDest = '';
|
||||
|
||||
if (isnewrec) {
|
||||
// New Record created
|
||||
|
||||
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(params.table)) {
|
||||
typedir = shared_consts.TypeNotifs.TYPEDIR_BACHECA;
|
||||
typeid = (params.table === shared_consts.TABLES_MYGOODS) ? shared_consts.TypeNotifs.ID_BACHECA_NEW_GOOD : shared_consts.TypeNotifs.ID_BACHECA_NEW_SERVICE
|
||||
typeid = (params.table === shared_consts.TABLES_MYGOODS)
|
||||
? shared_consts.TypeNotifs.ID_BACHECA_NEW_GOOD
|
||||
: shared_consts.TypeNotifs.ID_BACHECA_NEW_SERVICE
|
||||
setnotif = true;
|
||||
}
|
||||
|
||||
@@ -358,6 +363,7 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
groupnameDest = myrec ? myrec.groupname : '';
|
||||
setnotif = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (setnotif) {
|
||||
await SendNotif.createNewNotification(req, res, {groupnameDest}, params.table, myrec, typedir, typeid);
|
||||
|
||||
@@ -44,6 +44,14 @@ router.post('/load', authenticate, async (req, res) => {
|
||||
const whatshow = MyGroup.getWhatToShow(idapp, req.user.username);
|
||||
let data = await MyGroup.findOne({idapp, groupname}, whatshow).lean();
|
||||
|
||||
let cities = [];
|
||||
if (data) {
|
||||
cities = await MyGroup.extractCitiesName(idapp, data._id);
|
||||
if (cities && cities.length > 0) {
|
||||
cities = cities[0].mycities;
|
||||
}
|
||||
}
|
||||
|
||||
data = await getGroupRecAdminsInfo(idapp, data);
|
||||
|
||||
const whatshowUsers = await User.getWhatToShow_IfFriends(idapp, req.user.username);
|
||||
@@ -56,9 +64,9 @@ router.post('/load', authenticate, async (req, res) => {
|
||||
},
|
||||
},
|
||||
whatshowUsers,
|
||||
);
|
||||
).lean();
|
||||
|
||||
res.send({mygroup: data, users_in_group});
|
||||
res.send({mygroup: data, users_in_group, cities});
|
||||
|
||||
} catch (e) {
|
||||
console.error('Error in MyGroups', e);
|
||||
|
||||
@@ -192,7 +192,7 @@ myLoad().then(ris => {
|
||||
if (app.get('env') === 'development') {
|
||||
|
||||
app.use(function(err, req, res, next) {
|
||||
console.log('Error: ', err.message);
|
||||
console.log('Server Error: ', err.message);
|
||||
// console.trace();
|
||||
res.status(err.status || 500).send({error: err.message});
|
||||
// res.render('error', {
|
||||
|
||||
@@ -172,6 +172,12 @@ module.exports = {
|
||||
VISIB_ONLY_MANAGER: 2,
|
||||
VISIB_ONLY_ADMIN: 4,
|
||||
|
||||
Visibility_Group: {
|
||||
PRIVATE: 1,
|
||||
HIDDEN: 2,
|
||||
// PASSWORD: 4,
|
||||
},
|
||||
|
||||
BOTTYPE_NONE: 0,
|
||||
BOTTYPE_PAGE: 1,
|
||||
BOTTYPE_LINK: 2,
|
||||
|
||||
Reference in New Issue
Block a user