- Gruppi (3) - lista degli utenti del gruppo

This commit is contained in:
paoloar77
2022-02-05 23:28:15 +01:00
parent daf872fe55
commit 16664f7be7
12 changed files with 387 additions and 107 deletions

83
src/server/models/catgrp.js Executable file
View File

@@ -0,0 +1,83 @@
const mongoose = require('mongoose').set('debug', false)
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
mongoose.level = "F";
const tools = require('../tools/general');
const { ObjectID } = require('mongodb');
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
const CatGrpSchema = new Schema({
_id: {
type: Number,
},
descr: {
type: String,
},
idCatGrp: {
type: Number
},
icon: {
type: String,
},
img: {
type: String,
},
color: {
type: String,
},
theme: {
type: String,
},
});
CatGrpSchema.pre('save', async function (next) {
if (this.isNew) {
const myrec = await CatGrp.findOne().limit(1).sort({_id:-1});
if (!!myrec) {
if (myrec._doc._id === 0)
this._id = 1;
else
this._id = myrec._doc._id + 1;
} else {
this._id = 1;
}
}
next();
});
CatGrpSchema.statics.findAllIdApp = async function (idapp) {
const CatGrp = this;
const query = [
{ $sort: { descr: 1 } }
];
return CatGrp
.aggregate(query)
.then((arrrec) => {
return arrrec
})
};
CatGrpSchema.statics.getFieldsForSearch = function () {
return [{ field: 'descr', type: tools.FieldType.string }]
};
CatGrpSchema.statics.executeQueryTable = function (idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, 0, params);
};
const CatGrp = mongoose.model('CatGrp', CatGrpSchema);
module.exports = { CatGrp };

View File

@@ -3,6 +3,8 @@ const Schema = mongoose.Schema;
const tools = require('../tools/general'); const tools = require('../tools/general');
const shared_consts = require('../tools/shared_nodejs');
mongoose.Promise = global.Promise; mongoose.Promise = global.Promise;
mongoose.level = 'F'; mongoose.level = 'F';
@@ -24,7 +26,7 @@ const MyGroupSchema = new Schema({
descr: { descr: {
type: String, type: String,
}, },
idSector: { idCatGrp: {
type: Number, type: Number,
}, },
userId: { userId: {
@@ -52,12 +54,20 @@ const MyGroupSchema = new Schema({
link_telegram: { link_telegram: {
type: String, type: String,
}, },
visibility: { note: {
type: String,
default: '',
},
visibility: [
{
type: Number, type: Number,
}, },
],
pwd_cryp: {
type: String,
},
admins: [ admins: [
{ {
_id: false,
username: {type: String}, username: {type: String},
date: {type: Date}, date: {type: Date},
}, },
@@ -93,6 +103,14 @@ MyGroupSchema.statics.getFieldsForSearch = function() {
MyGroupSchema.statics.executeQueryTable = function(idapp, params) { MyGroupSchema.statics.executeQueryTable = function(idapp, params) {
params.fieldsearch = this.getFieldsForSearch(); params.fieldsearch = this.getFieldsForSearch();
if (params.options) {
if (tools.isBitActive(params.options,
shared_consts.OPTIONS_SEARCH_USER_ONLY_FULL_WORDS)) {
params.fieldsearch = User.getFieldsForSearchUserFriend();
}
}
return tools.executeQueryTable(this, idapp, params); return tools.executeQueryTable(this, idapp, params);
}; };
@@ -103,42 +121,43 @@ MyGroupSchema.statics.findAllIdApp = async function(idapp) {
}; };
// Rimuovo la Richiesta del Gruppo // Rimuovo la Richiesta del Gruppo
MyGroupSchema.statics.removeReqGroup = async function( MyGroupSchema.statics.removeReqGroup = async function(idapp, username, groupnameDest) {
idapp, username, groupnameDest) {
const {User} = require('../models/user');
return User.updateOne({idapp, username: username}, return MyGroup.updateOne({idapp, groupname: groupnameDest},
{$pull: {'profile.req_groups': {groupname: {$in: [groupnameDest]}}}}); {$pull: {req_users: {username: {$in: [username]}}}});
}; };
function getWhatToShow(idapp, username) { MyGroupSchema.statics.getWhatToShow = function (idapp, username) {
// ++Todo: MyGroup what to show // FOR ME, PERMIT ALL
return { return {
groupname: 1, groupname: 1,
title: 1, title: 1,
descr: 1, descr: 1,
visibility: 1, visibility: 1,
idSector: 1, idCatGrp: 1,
userId: 1, userId: 1,
photos: 1, photos: 1,
idCity: 1, idCity: 1,
website: 1, website: 1,
link_telegram: 1, link_telegram: 1,
note: 1,
admins: 1, admins: 1,
blocked: 1, blocked: 1,
req_users: 1,
}; };
} }
function getWhatToShow_Unknown(idapp, username) { MyGroupSchema.statics.getWhatToShow_Unknown = function (idapp, username) {
return { return {
groupname: 1, groupname: 1,
title: 1, title: 1,
descr: 1, descr: 1,
photos: 1, photos: 1,
visibility: 1, visibility: 1,
idSector: 1, idCatGrp: 1,
idCity: 1, idCity: 1,
note: 1,
}; };
} }
@@ -170,10 +189,9 @@ MyGroupSchema.statics.getUsernameReqGroupsByGroupname = async function(
}; };
MyGroupSchema.statics.getInfoGroupByGroupname = async function( MyGroupSchema.statics.getInfoGroupByGroupname = async function(idapp, groupname) {
idapp, groupname) {
const whatToShow = getWhatToShow(idapp, groupname); const whatToShow = this.getWhatToShow(idapp, groupname);
return MyGroup.findOne({ return MyGroup.findOne({
idapp, idapp,
@@ -187,8 +205,8 @@ MyGroupSchema.statics.getGroupsByUsername = async function(idapp, username) {
try { try {
const {User} = require('../models/user'); const {User} = require('../models/user');
const whatToShow = getWhatToShow(idapp, username); const whatToShow = this.getWhatToShow(idapp, username);
const whatToShow_Unknown = getWhatToShow_Unknown(idapp, username); const whatToShow_Unknown = this.getWhatToShow_Unknown(idapp, username);
const arrUsernameGroups = await User.getUsernameGroupsByUsername(idapp, const arrUsernameGroups = await User.getUsernameGroupsByUsername(idapp,
username); username);
// const arrUsernameReqGroups = await MyGroup.getUsernameReqGroupsByGroupname(idapp, username); // const arrUsernameReqGroups = await MyGroup.getUsernameReqGroupsByGroupname(idapp, username);

View File

@@ -64,6 +64,7 @@ const MySkillSchema = new Schema({
}], }],
note: { note: {
type: String, type: String,
default: '',
}, },
subTitle: { subTitle: {
type: String, type: String,

View File

@@ -342,7 +342,7 @@ const UserSchema = new mongoose.Schema({
username: {type: String}, username: {type: String},
date: {type: Date}, date: {type: Date},
}], // username }], // username
groups: [ mygroups: [
{ {
_id: false, _id: false,
groupname: {type: String}, groupname: {type: String},
@@ -1314,7 +1314,7 @@ UserSchema.statics.removeFriend = async function(idapp, username, usernameDest)
// Rimuovo il Gruppo // Rimuovo il Gruppo
UserSchema.statics.removeFromMyGroups = async function(idapp, username, groupnameDest) { UserSchema.statics.removeFromMyGroups = async function(idapp, username, groupnameDest) {
return User.updateOne({idapp, username}, return User.updateOne({idapp, username},
{$pull: {'profile.groups': {groupname: {$in: [groupnameDest]}}}}); {$pull: {'profile.mygroups': {groupname: {$in: [groupnameDest]}}}});
}; };
// Rimuovo la Richiesta di Amicizia // Rimuovo la Richiesta di Amicizia
@@ -1463,11 +1463,11 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
let update = {}; let update = {};
try { try {
if (cmd === shared_consts.GROUPSCMD.SETGROUP) { if (cmd === shared_consts.GROUPSCMD.SETGROUP) {
// Aggiungo l'Amicizia a me // Controllo se è stato già inserito
const foundIfAlreadyGroup = await User.findOne({ const foundIfAlreadyGroup = await User.findOne({
idapp, idapp,
username: usernameOrig, username: usernameOrig,
'profile.groups': { 'profile.mygroups': {
$elemMatch: {groupname: {$eq: groupnameDest}}, $elemMatch: {groupname: {$eq: groupnameDest}},
}, },
}); });
@@ -1475,7 +1475,7 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
if (!foundIfAlreadyGroup) { if (!foundIfAlreadyGroup) {
update = { update = {
$push: { $push: {
'profile.groups': { 'profile.mygroups': {
groupname: groupnameDest, groupname: groupnameDest,
date: new Date(), date: new Date(),
}, },
@@ -1483,8 +1483,11 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
}; };
ris = await User.updateOne({idapp, username: usernameOrig}, update); ris = await User.updateOne({idapp, username: usernameOrig}, update);
update = {$pull: {'profile.req_groups': {groupname: {$in: [groupnameDest]}}}}; // Elimina la richiesta:
ris = await User.updateOne({idapp, username: usernameOrig}, update); update = {$pull: {req_users: {username: {$in: [usernameOrig]}}}};
ris = await MyGroup.updateOne({idapp, groupname: groupnameDest}, update);
} else {
ris = false;
} }
if (ris) { if (ris) {
@@ -1495,7 +1498,7 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
const foundIfAlreadyAskGroup = await MyGroup.findOne({ const foundIfAlreadyAskGroup = await MyGroup.findOne({
idapp, idapp,
groupname: groupnameDest, groupname: groupnameDest,
'req_groups': { 'req_users': {
$elemMatch: { username: {$eq: usernameOrig}}, $elemMatch: { username: {$eq: usernameOrig}},
}, },
}); });
@@ -1504,31 +1507,33 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
if (!foundIfAlreadyAskGroup) { if (!foundIfAlreadyAskGroup) {
update = { update = {
$push: { $push: {
'profile.req_groups': { 'req_users': {
username: usernameOrig, username: usernameOrig,
date: new Date(), date: new Date(),
}, },
}, },
}; };
ris = await User.updateOne({idapp, username: groupnameDest}, update); ris = await MyGroup.updateOne({idapp, groupname: groupnameDest}, update);
} }
if (ris) { if (ris) {
// Invia una notifica alla persona // Invia una notifica alla persona
tools.sendNotificationByGroupName(idapp, groupnameDest, cmd, true); tools.sendNotificationByGroupname(idapp, groupnameDest, cmd, true);
} }
} else { } else {
if (foundIfAlreadyAskGroup) { if (foundIfAlreadyAskGroup) {
ris = await this.removeFromMyGroups(idapp, groupnameDest, usernameOrig); // Rimuovo l'Amicizia da me ris = await this.removeFromMyGroups(idapp, usernameOrig, groupnameDest); // Rimuovo il Gruppo da me
} }
} }
if (ris) { if (ris) {
ris = await User.getInfoAskGroupByUsername(idapp, groupnameDest); ris = await MyGroup.getInfoGroupByGroupname(idapp, groupnameDest);
} }
} else if (cmd === shared_consts.GROUPSCMD.REMOVE_FROM_MYGROUPS) { } else if (cmd === shared_consts.GROUPSCMD.REMOVE_FROM_MYGROUP) {
ris = await this.removeFromMyGroups(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me ris = await User.removeFromMyGroups(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me
console.log('ris', ris);
} else if (cmd === shared_consts.GROUPSCMD.CANCEL_REQ_GROUP) { } else if (cmd === shared_consts.GROUPSCMD.CANCEL_REQ_GROUP) {
@@ -1536,10 +1541,10 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
} else if (cmd === shared_consts.GROUPSCMD.BLOCK_GROUP) { } else if (cmd === shared_consts.GROUPSCMD.BLOCK_GROUP) {
await this.removeFromMyGroups(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me await User.removeFromMyGroups(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me
// Blocco il Gruppo // Blocco il Gruppo
ris = await MyGroup.updateOne({idapp, username: groupnameDest}, { ris = await MyGroup.updateOne({idapp, groupname: groupnameDest}, {
$set: { $set: {
blocked: true, blocked: true,
username_who_block: usernameOrig, username_who_block: usernameOrig,
@@ -1547,6 +1552,7 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
}, },
}); });
//++Todo: Send Notification to Admin and Group's manager //++Todo: Send Notification to Admin and Group's manager
tools.sendNotificationByGroupname(idapp, groupnameDest, cmd, true);
} }
} catch (e) { } catch (e) {
@@ -1601,6 +1607,26 @@ function getWhatToShow_Unknown(idapp, username) {
} }
UserSchema.statics.getWhatToShow_IfFriends = async function(idapp, username) {
return {
username: 1,
aportador_solidario: 1,
name: 1,
// deleted: 1,
// sospeso: 1,
verified_email: 1,
verified_by_aportador: 1,
'profile.img': 1,
'profile.sex': 1,
'profile.born_province': 1,
'profile.born_country': 1,
date_reg: 1,
groups: 1,
friends: 1,
};
};
UserSchema.statics.getInfoFriendByUsername = async function(idapp, username) { UserSchema.statics.getInfoFriendByUsername = async function(idapp, username) {
const whatToShow = getWhatToShow(idapp, username); const whatToShow = getWhatToShow(idapp, username);
@@ -2935,17 +2961,32 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser) {
recUser._doc.profile.asked_friends = listSentMyRequestFriends ? listSentMyRequestFriends : []; recUser._doc.profile.asked_friends = listSentMyRequestFriends ? listSentMyRequestFriends : [];
const listSentMyRequestGroups = await User.find({ const listSentMyRequestGroups = await MyGroup.find({
idapp, idapp,
'profile.req_groups': { 'req_users': {
$elemMatch: {username: {$eq: recUser.username}}, $elemMatch: {username: {$eq: recUser.username}},
}, },
$or: [ $or: [
{deleted: {$exists: false}}, {deleted: {$exists: false}},
{deleted: {$exists: true, $eq: false}}], {deleted: {$exists: true, $eq: false}}],
}, {username: 1}); }, MyGroup.getWhatToShow_Unknown());
recUser._doc.profile.asked_groups = listSentMyRequestGroups ? listSentMyRequestGroups : []; recUser._doc.profile.asked_groups = listSentMyRequestGroups ? listSentMyRequestGroups : [];
const listManageGroups = await MyGroup.find({
idapp,
'admins': {
$elemMatch: {username: {$eq: recUser.username}},
},
$or: [
{deleted: {$exists: false}},
{deleted: {$exists: true, $eq: false}}],
});
recUser._doc.profile.manage_mygroups = listManageGroups ? listManageGroups : [];
}catch (e){ }catch (e){
console.error('Err', e); console.error('Err', e);
} }

View File

@@ -0,0 +1,72 @@
module.exports = {
list: [
{
_id: 1,
descr: "Abitare",
},
{
_id: 2,
descr: "Arte",
},
{
_id: 3,
descr: "Alimentazione",
},
{
_id: 4,
descr: "Artigianato",
},
{
_id: 5,
descr: "Assistenza Legale",
},
{
_id: 6,
descr: "Benessere e Salute",
},
{
_id: 7,
descr: "Gruppi Locali",
},
{
_id: 8,
descr: "Istruzione",
},
{
_id: 2,
descr: "Arte",
},
{
_id: 9,
descr: "Mobilità",
},
{
_id: 10,
descr: "Sport",
},
{
_id: 11,
descr: "Servizi",
},
{
_id: 12,
descr: "Tecnologia",
},
{
_id: 13,
descr: "Turismo",
},
{
_id: 14,
descr: "Ecovillaggi",
},
{
_id: 15,
descr: "Feste",
},
{
_id: 16,
descr: "Altro",
},
]
}

View File

@@ -34,6 +34,10 @@ module.exports = {
const { Sector } = require('../models/sector'); const { Sector } = require('../models/sector');
this.insertIntoDb('sectors', Sector) this.insertIntoDb('sectors', Sector)
// CatGrps
const { CatGrp } = require('../models/catgrp');
this.insertIntoDb('catgrps', CatGrp)
// Skills (Competenze) // Skills (Competenze)
const { Skill } = require('../models/skill'); const { Skill } = require('../models/skill');
this.insertIntoDb('skills', Skill) this.insertIntoDb('skills', Skill)

View File

@@ -50,6 +50,7 @@ const {StatusSkill} = require('../models/statusSkill');
const {City} = require('../models/city'); const {City} = require('../models/city');
const {Province} = require('../models/province'); const {Province} = require('../models/province');
const {Sector} = require('../models/sector'); const {Sector} = require('../models/sector');
const {CatGrp} = require('../models/catgrp');
const {Level} = require('../models/level'); const {Level} = require('../models/level');
const Pickup = require('../models/pickup'); const Pickup = require('../models/pickup');
const {Newstosent} = require('../models/newstosent'); const {Newstosent} = require('../models/newstosent');
@@ -315,6 +316,8 @@ function getTableByTableName(tablename) {
mytable = Province; mytable = Province;
else if (tablename === 'sectors') else if (tablename === 'sectors')
mytable = Sector; mytable = Sector;
else if (tablename === 'catgrps')
mytable = CatGrp;
else if (tablename === 'levels') else if (tablename === 'levels')
mytable = Level; mytable = Level;
else if (shared_consts.TablePickup.includes(tablename)) else if (shared_consts.TablePickup.includes(tablename))
@@ -351,6 +354,7 @@ router.post('/settable', authenticate, (req, res) => {
} }
if (shared_consts.TABLES_USER_ID.includes(params.table)) { if (shared_consts.TABLES_USER_ID.includes(params.table)) {
if (!mydata.userId)
mydata.userId = req.user._id; mydata.userId = req.user._id;
} }
@@ -360,20 +364,31 @@ router.post('/settable', authenticate, (req, res) => {
} }
} }
if (params.table === shared_consts.TAB_MYGROUPS) {
if (shared_consts.MYGROUPS_KEY_TO_CRYPTED in mydata) {
if (mydata[shared_consts.MYGROUPS_KEY_TO_CRYPTED]) {
mydata[shared_consts.MYGROUPS_KEY_TO_CRYPTED + shared_consts.SUFFIX_CRYPTED] = tools.cryptdata(mydata[shared_consts.MYGROUPS_KEY_TO_CRYPTED]);
}
}
}
if (shared_consts.TABLES_USER_INCLUDE_MY.includes(params.table)) { if (shared_consts.TABLES_USER_INCLUDE_MY.includes(params.table)) {
if (!mydata.admins) { if (!mydata.admins) {
mydata.admins = []; mydata.admins = [];
} else { } else {
const arrnew = []; /*const arrnew = [];
for (const username of mydata.admins) { for (const username of mydata.admins) {
arrnew.push({username}); arrnew.push({username});
} }
mydata.admins = arrnew; mydata.admins = arrnew;
*/
} }
const indfind = mydata.admins.findIndex((rec) => (rec.username === req.user.username)); const indfind = mydata.admins.findIndex((rec) => (rec.username === req.user.username));
if (indfind < 0) { if (indfind < 0) {
mydata.admins.push({_id: new ObjectID(), username: req.user.username}); mydata.admins.push({username: req.user.username});
} }
} }
@@ -634,7 +649,6 @@ router.patch('/chval', authenticate, async (req, res) => {
fieldsvalue.crypted = true; fieldsvalue.crypted = true;
fieldsvalue.value_str = tools.cryptdata(fieldsvalue.value_str); fieldsvalue.value_str = tools.cryptdata(fieldsvalue.value_str);
} }
} }
if (mydata.table === shared_consts.TAB_SITES) { if (mydata.table === shared_consts.TAB_SITES) {
@@ -1089,6 +1103,7 @@ function load(req, res, version) {
let subSkills = SubSkill.findAllIdApp(idapp); let subSkills = SubSkill.findAllIdApp(idapp);
let statusSkills = StatusSkill.findAllIdApp(idapp); let statusSkills = StatusSkill.findAllIdApp(idapp);
let sectors = Sector.findAllIdApp(idapp); let sectors = Sector.findAllIdApp(idapp);
let catgrps = CatGrp.findAllIdApp(idapp);
let cities = City.findAllIdApp(idapp); let cities = City.findAllIdApp(idapp);
let cart = null; let cart = null;
let orderscart = null; let orderscart = null;
@@ -1145,7 +1160,9 @@ function load(req, res, version) {
sectors, sectors,
statusSkills, statusSkills,
cities, cities,
myuserextra]).then((arrdata) => { myuserextra,
catgrps,
]).then((arrdata) => {
// console.table(arrdata); // console.table(arrdata);
let myuser = req.user; let myuser = req.user;
if (myuser) { if (myuser) {
@@ -1216,6 +1233,8 @@ function load(req, res, version) {
sectors: arrdata[27], sectors: arrdata[27],
statusSkills: arrdata[28], statusSkills: arrdata[28],
cities: arrdata[29], cities: arrdata[29],
// myuser arrdata[30]
catgrps: arrdata[31],
}); });
} }
@@ -1425,12 +1444,15 @@ function uploadFile(req, res, version) {
const ris = await resizer(newname, setup_image_compress); const ris = await resizer(newname, setup_image_compress);
if (ris) { if (ris) {
if (tools.isFileExists(resized_img)) {
tools.delete(newname, false, () => {}); tools.delete(newname, false, () => {});
tools.move(resized_img, newname, (err) => { tools.move(resized_img, newname, (err) => {
if (err)
console.error('err', err);
}); });
} }
}
} catch (e) { } catch (e) {
console.error('newname', e); console.error('newname', e);
} }

View File

@@ -5,34 +5,45 @@ const tools = require('../tools/general');
const server_constants = require('../tools/server_constants'); 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 mongoose = require('mongoose').set('debug', false);
const { User } = require('../models/user'); const {User} = require('../models/user');
const { MyGroup } = require('../models/mygroup'); const {MyGroup} = require('../models/mygroup');
const _ = require('lodash'); const _ = require('lodash');
const { ObjectID } = require('mongodb'); const {ObjectID} = require('mongodb');
router.post('/load', authenticate, async (req, res) => { router.post('/load', authenticate, async (req, res) => {
const idapp = req.body.idapp; const idapp = req.body.idapp;
const groupname = req.body.groupname; const groupname = req.body.groupname;
try{ try {
data = await MyGroup.findOne({idapp, groupname}).lean(); const whatshow = MyGroup.getWhatToShow(idapp, req.user.username);
const data = await MyGroup.findOne({idapp, groupname}, whatshow).lean();
res.send(data); const whatshowUsers = await User.getWhatToShow_IfFriends(idapp, req.user.username);
}catch (e) { const users_in_group = await User.find(
console.error('Error in MyGroups'); {
idapp,
'profile.mygroups': {
$elemMatch: {groupname: {$eq: groupname}},
}
},
whatshowUsers
);
res.send({mygroup: data, users_in_group});
} catch (e) {
console.error('Error in MyGroups', e);
return res.status(400).send(e); return res.status(400).send(e);
} }
const ris = null const ris = null;
}); });

View File

@@ -13,8 +13,8 @@ var mongoose = require('mongoose').set('debug', false);
const Subscription = mongoose.model('subscribers'); const Subscription = mongoose.model('subscribers');
const _ = require('lodash'); const _ = require('lodash');
const { MySkill } = require('../models/myskill'); const {MySkill} = require('../models/myskill');
var { User } = require('../models/user'); var {User} = require('../models/user');
const {ObjectID} = require('mongodb'); const {ObjectID} = require('mongodb');
@@ -23,7 +23,8 @@ router.post('/page', authenticate, function(req, res, next) {
let idSkill = req.body.idSkill; let idSkill = req.body.idSkill;
let idapp = req.body.idapp; let idapp = req.body.idapp;
return MySkill.getMySkillByIdkill(idapp, idSkill).then((ris) => { return MySkill.getMySkillByIdkill(idapp, idSkill).
then((ris) => {
if (ris) { if (ris) {
res.send(ris); res.send(ris);
@@ -36,9 +37,13 @@ router.post('/page', authenticate, function(req, res, next) {
*/ */
} else { } else {
res.status(400).send(e); res.status(400).send();
} }
}); }).catch((e) => {
console.error('Err', e);
res.status(400).send(e);
})
}); });

View File

@@ -549,7 +549,7 @@ router.post('/groups/cmd', authenticate, (req, res) => {
} }
} }
return MyGroup.setGroupsCmd(idapp, usernameOrig, groupnameDest, cmd, value).then((ris) => { return User.setGroupsCmd(idapp, usernameOrig, groupnameDest, cmd, value).then((ris) => {
res.send(ris); res.send(ris);
}).catch((e) => { }).catch((e) => {
tools.mylog('ERRORE IN groups/cmd: ' + e.message); tools.mylog('ERRORE IN groups/cmd: ' + e.message);

View File

@@ -120,6 +120,8 @@ const textlang = {
'MSG_SEND_FROM': 'Msg Inviato da', 'MSG_SEND_FROM': 'Msg Inviato da',
'ZOOM_CONFERMATO': 'Sei stato confermato ad aver visto la Video Conferenza di Benvenuto!', 'ZOOM_CONFERMATO': 'Sei stato confermato ad aver visto la Video Conferenza di Benvenuto!',
'RICHIESTA_AMICIZIA': 'Richiesta d\'Amicizia da parte di %s', 'RICHIESTA_AMICIZIA': 'Richiesta d\'Amicizia da parte di %s',
'RICHIESTA_GRUPPO': 'Richiesta di entrare nel Gruppo %s da parte di %s',
'RICHIESTA_BLOCCO_GRUPPO': 'Richiesta di bloccare il Gruppo %s da parte di %s',
}, },
si: {}, si: {},
es: { es: {
@@ -851,8 +853,13 @@ module.exports = {
const arrusernameAdmins = group.admins; const arrusernameAdmins = group.admins;
for (const username of arrusernameAdmins) { for (const arradmins of arrusernameAdmins) {
const user = await User.get try {
if (arradmins.username) {
const user = await User.findOne({idapp, username: arradmins.username},
{_id: 1, lang: 1});
if (user) {
let userId = user._id; let userId = user._id;
let lang = user.lang; let lang = user.lang;
@@ -862,26 +869,38 @@ module.exports = {
let tag = ''; let tag = '';
let actions = []; let actions = [];
if (cmd) { if (cmd) {
if (cmd === shared_consts.FRIENDSCMD.REQFRIEND) { if (cmd === shared_consts.GROUPSCMD.REQGROUP) {
descr = printf(this.get__('RICHIESTA_AMICIZIA', lang), username); descr = printf(this.get__('RICHIESTA_GRUPPO', lang), groupname,
openUrl = '/my/' + username; arradmins.username);
tag = 'reqfriends'; openUrl = '/grp/' + groupname;
tag = 'reqgroups';
} else if (cmd === shared_consts.GROUPSCMD.BLOCK_USER) {
descr = printf(this.get__('RICHIESTA_BLOCCO_GRUPPO', lang),
groupname, arradmins.username);
openUrl = '/grp/' + groupname;
tag = 'blockgroups';
} }
} }
if (userId) { if (userId) {
this.sendNotificationToUser(userId, title, descr, openUrl, '', tag, this.sendNotificationToUser(userId, title, descr, openUrl, '',
tag,
actions); actions);
} }
if (telegram) { if (telegram) {
const telegrambot = require('../telegram/telegrambot'); const telegrambot = require('../telegram/telegrambot');
const idtelegram = await User.TelegIdByUsername(idapp, username); const idtelegram = await User.TelegIdByUsername(idapp, arradmins.username);
await telegrambot.sendMsgTelegramByIdTelegram(idapp, idtelegram, descr); await telegrambot.sendMsgTelegramByIdTelegram(idapp, idtelegram, descr);
} }
} }
}
}catch (e){
console.error('sendNotificationByGroupname', e);
}
}
}, },

View File

@@ -63,10 +63,14 @@ module.exports = {
TAB_PHONES: 'phones', TAB_PHONES: 'phones',
TAB_SETTINGS: 'settings', TAB_SETTINGS: 'settings',
TAB_SITES: 'sites', TAB_SITES: 'sites',
TAB_MYGROUPS: 'mygroups',
TAB_MYBOTS: 'mybots', TAB_MYBOTS: 'mybots',
KEY_TO_CRYPTED: ['PWD_FROM'], KEY_TO_CRYPTED: ['PWD_FROM'],
SITES_KEY_TO_CRYPTED: ['email_pwd'], SITES_KEY_TO_CRYPTED: ['email_pwd'],
MYGROUPS_KEY_TO_CRYPTED: 'pwd',
SUFFIX_CRYPTED: ['_cryp'],
TablePickup: ['countries', 'phones'], TablePickup: ['countries', 'phones'],
@@ -84,8 +88,8 @@ module.exports = {
TABLES_USER_INCLUDE_MY: ['mygroups'], TABLES_USER_INCLUDE_MY: ['mygroups'],
TABLES_UPDATE_LASTMODIFIED: ['myskills', 'mybots', 'mygroups'], TABLES_UPDATE_LASTMODIFIED: ['myskills', 'mybots', 'mygroups'],
TABLES_PERM_CHANGE_FOR_USERS: ['myskills'], TABLES_PERM_CHANGE_FOR_USERS: ['myskills', 'mygroups'],
TABLES_PERM_NEWREC: ['skills', 'subskills'], TABLES_PERM_NEWREC: ['skills', 'subskills', 'mygroups'],
VISIB_ALL: 0, VISIB_ALL: 0,
VISIB_ONLYIF_VERIFIED: 1, VISIB_ONLYIF_VERIFIED: 1,