- Gruppi (3) - lista degli utenti del gruppo
This commit is contained in:
83
src/server/models/catgrp.js
Executable file
83
src/server/models/catgrp.js
Executable 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 };
|
||||
@@ -3,6 +3,8 @@ const Schema = mongoose.Schema;
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = 'F';
|
||||
|
||||
@@ -24,7 +26,7 @@ const MyGroupSchema = new Schema({
|
||||
descr: {
|
||||
type: String,
|
||||
},
|
||||
idSector: {
|
||||
idCatGrp: {
|
||||
type: Number,
|
||||
},
|
||||
userId: {
|
||||
@@ -52,12 +54,20 @@ const MyGroupSchema = new Schema({
|
||||
link_telegram: {
|
||||
type: String,
|
||||
},
|
||||
visibility: {
|
||||
note: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
visibility: [
|
||||
{
|
||||
type: Number,
|
||||
},
|
||||
],
|
||||
pwd_cryp: {
|
||||
type: String,
|
||||
},
|
||||
admins: [
|
||||
{
|
||||
_id: false,
|
||||
username: {type: String},
|
||||
date: {type: Date},
|
||||
},
|
||||
@@ -93,6 +103,14 @@ MyGroupSchema.statics.getFieldsForSearch = function() {
|
||||
|
||||
MyGroupSchema.statics.executeQueryTable = function(idapp, params) {
|
||||
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);
|
||||
};
|
||||
|
||||
@@ -103,42 +121,43 @@ MyGroupSchema.statics.findAllIdApp = async function(idapp) {
|
||||
};
|
||||
|
||||
// Rimuovo la Richiesta del Gruppo
|
||||
MyGroupSchema.statics.removeReqGroup = async function(
|
||||
idapp, username, groupnameDest) {
|
||||
const {User} = require('../models/user');
|
||||
MyGroupSchema.statics.removeReqGroup = async function(idapp, username, groupnameDest) {
|
||||
|
||||
return User.updateOne({idapp, username: username},
|
||||
{$pull: {'profile.req_groups': {groupname: {$in: [groupnameDest]}}}});
|
||||
return MyGroup.updateOne({idapp, groupname: groupnameDest},
|
||||
{$pull: {req_users: {username: {$in: [username]}}}});
|
||||
};
|
||||
|
||||
function getWhatToShow(idapp, username) {
|
||||
// ++Todo: MyGroup what to show
|
||||
MyGroupSchema.statics.getWhatToShow = function (idapp, username) {
|
||||
// FOR ME, PERMIT ALL
|
||||
return {
|
||||
groupname: 1,
|
||||
title: 1,
|
||||
descr: 1,
|
||||
visibility: 1,
|
||||
idSector: 1,
|
||||
idCatGrp: 1,
|
||||
userId: 1,
|
||||
photos: 1,
|
||||
idCity: 1,
|
||||
website: 1,
|
||||
link_telegram: 1,
|
||||
note: 1,
|
||||
admins: 1,
|
||||
blocked: 1,
|
||||
req_users: 1,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
function getWhatToShow_Unknown(idapp, username) {
|
||||
MyGroupSchema.statics.getWhatToShow_Unknown = function (idapp, username) {
|
||||
return {
|
||||
groupname: 1,
|
||||
title: 1,
|
||||
descr: 1,
|
||||
photos: 1,
|
||||
visibility: 1,
|
||||
idSector: 1,
|
||||
idCatGrp: 1,
|
||||
idCity: 1,
|
||||
note: 1,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -170,10 +189,9 @@ MyGroupSchema.statics.getUsernameReqGroupsByGroupname = async function(
|
||||
|
||||
};
|
||||
|
||||
MyGroupSchema.statics.getInfoGroupByGroupname = async function(
|
||||
idapp, groupname) {
|
||||
MyGroupSchema.statics.getInfoGroupByGroupname = async function(idapp, groupname) {
|
||||
|
||||
const whatToShow = getWhatToShow(idapp, groupname);
|
||||
const whatToShow = this.getWhatToShow(idapp, groupname);
|
||||
|
||||
return MyGroup.findOne({
|
||||
idapp,
|
||||
@@ -187,8 +205,8 @@ MyGroupSchema.statics.getGroupsByUsername = async function(idapp, username) {
|
||||
try {
|
||||
const {User} = require('../models/user');
|
||||
|
||||
const whatToShow = getWhatToShow(idapp, username);
|
||||
const whatToShow_Unknown = getWhatToShow_Unknown(idapp, username);
|
||||
const whatToShow = this.getWhatToShow(idapp, username);
|
||||
const whatToShow_Unknown = this.getWhatToShow_Unknown(idapp, username);
|
||||
const arrUsernameGroups = await User.getUsernameGroupsByUsername(idapp,
|
||||
username);
|
||||
// const arrUsernameReqGroups = await MyGroup.getUsernameReqGroupsByGroupname(idapp, username);
|
||||
|
||||
@@ -64,6 +64,7 @@ const MySkillSchema = new Schema({
|
||||
}],
|
||||
note: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
subTitle: {
|
||||
type: String,
|
||||
|
||||
@@ -342,7 +342,7 @@ const UserSchema = new mongoose.Schema({
|
||||
username: {type: String},
|
||||
date: {type: Date},
|
||||
}], // username
|
||||
groups: [
|
||||
mygroups: [
|
||||
{
|
||||
_id: false,
|
||||
groupname: {type: String},
|
||||
@@ -1314,7 +1314,7 @@ UserSchema.statics.removeFriend = async function(idapp, username, usernameDest)
|
||||
// Rimuovo il Gruppo
|
||||
UserSchema.statics.removeFromMyGroups = async function(idapp, username, groupnameDest) {
|
||||
return User.updateOne({idapp, username},
|
||||
{$pull: {'profile.groups': {groupname: {$in: [groupnameDest]}}}});
|
||||
{$pull: {'profile.mygroups': {groupname: {$in: [groupnameDest]}}}});
|
||||
};
|
||||
|
||||
// Rimuovo la Richiesta di Amicizia
|
||||
@@ -1463,11 +1463,11 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
let update = {};
|
||||
try {
|
||||
if (cmd === shared_consts.GROUPSCMD.SETGROUP) {
|
||||
// Aggiungo l'Amicizia a me
|
||||
// Controllo se è stato già inserito
|
||||
const foundIfAlreadyGroup = await User.findOne({
|
||||
idapp,
|
||||
username: usernameOrig,
|
||||
'profile.groups': {
|
||||
'profile.mygroups': {
|
||||
$elemMatch: {groupname: {$eq: groupnameDest}},
|
||||
},
|
||||
});
|
||||
@@ -1475,7 +1475,7 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
if (!foundIfAlreadyGroup) {
|
||||
update = {
|
||||
$push: {
|
||||
'profile.groups': {
|
||||
'profile.mygroups': {
|
||||
groupname: groupnameDest,
|
||||
date: new Date(),
|
||||
},
|
||||
@@ -1483,8 +1483,11 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
};
|
||||
ris = await User.updateOne({idapp, username: usernameOrig}, update);
|
||||
|
||||
update = {$pull: {'profile.req_groups': {groupname: {$in: [groupnameDest]}}}};
|
||||
ris = await User.updateOne({idapp, username: usernameOrig}, update);
|
||||
// Elimina la richiesta:
|
||||
update = {$pull: {req_users: {username: {$in: [usernameOrig]}}}};
|
||||
ris = await MyGroup.updateOne({idapp, groupname: groupnameDest}, update);
|
||||
} else {
|
||||
ris = false;
|
||||
}
|
||||
|
||||
if (ris) {
|
||||
@@ -1495,7 +1498,7 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
const foundIfAlreadyAskGroup = await MyGroup.findOne({
|
||||
idapp,
|
||||
groupname: groupnameDest,
|
||||
'req_groups': {
|
||||
'req_users': {
|
||||
$elemMatch: { username: {$eq: usernameOrig}},
|
||||
},
|
||||
});
|
||||
@@ -1504,31 +1507,33 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
if (!foundIfAlreadyAskGroup) {
|
||||
update = {
|
||||
$push: {
|
||||
'profile.req_groups': {
|
||||
'req_users': {
|
||||
username: usernameOrig,
|
||||
date: new Date(),
|
||||
},
|
||||
},
|
||||
};
|
||||
ris = await User.updateOne({idapp, username: groupnameDest}, update);
|
||||
ris = await MyGroup.updateOne({idapp, groupname: groupnameDest}, update);
|
||||
}
|
||||
if (ris) {
|
||||
// Invia una notifica alla persona
|
||||
tools.sendNotificationByGroupName(idapp, groupnameDest, cmd, true);
|
||||
tools.sendNotificationByGroupname(idapp, groupnameDest, cmd, true);
|
||||
}
|
||||
} else {
|
||||
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) {
|
||||
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) {
|
||||
|
||||
@@ -1536,10 +1541,10 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
|
||||
} 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
|
||||
ris = await MyGroup.updateOne({idapp, username: groupnameDest}, {
|
||||
ris = await MyGroup.updateOne({idapp, groupname: groupnameDest}, {
|
||||
$set: {
|
||||
blocked: true,
|
||||
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
|
||||
tools.sendNotificationByGroupname(idapp, groupnameDest, cmd, true);
|
||||
|
||||
}
|
||||
} 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) {
|
||||
|
||||
const whatToShow = getWhatToShow(idapp, username);
|
||||
@@ -2935,17 +2961,32 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser) {
|
||||
|
||||
recUser._doc.profile.asked_friends = listSentMyRequestFriends ? listSentMyRequestFriends : [];
|
||||
|
||||
const listSentMyRequestGroups = await User.find({
|
||||
const listSentMyRequestGroups = await MyGroup.find({
|
||||
idapp,
|
||||
'profile.req_groups': {
|
||||
'req_users': {
|
||||
$elemMatch: {username: {$eq: recUser.username}},
|
||||
},
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
{deleted: {$exists: true, $eq: false}}],
|
||||
}, {username: 1});
|
||||
}, MyGroup.getWhatToShow_Unknown());
|
||||
|
||||
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){
|
||||
console.error('Err', e);
|
||||
}
|
||||
|
||||
72
src/server/populate/catgrps.js
Normal file
72
src/server/populate/catgrps.js
Normal 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",
|
||||
},
|
||||
]
|
||||
}
|
||||
@@ -34,6 +34,10 @@ module.exports = {
|
||||
const { Sector } = require('../models/sector');
|
||||
this.insertIntoDb('sectors', Sector)
|
||||
|
||||
// CatGrps
|
||||
const { CatGrp } = require('../models/catgrp');
|
||||
this.insertIntoDb('catgrps', CatGrp)
|
||||
|
||||
// Skills (Competenze)
|
||||
const { Skill } = require('../models/skill');
|
||||
this.insertIntoDb('skills', Skill)
|
||||
|
||||
@@ -50,6 +50,7 @@ const {StatusSkill} = require('../models/statusSkill');
|
||||
const {City} = require('../models/city');
|
||||
const {Province} = require('../models/province');
|
||||
const {Sector} = require('../models/sector');
|
||||
const {CatGrp} = require('../models/catgrp');
|
||||
const {Level} = require('../models/level');
|
||||
const Pickup = require('../models/pickup');
|
||||
const {Newstosent} = require('../models/newstosent');
|
||||
@@ -315,6 +316,8 @@ function getTableByTableName(tablename) {
|
||||
mytable = Province;
|
||||
else if (tablename === 'sectors')
|
||||
mytable = Sector;
|
||||
else if (tablename === 'catgrps')
|
||||
mytable = CatGrp;
|
||||
else if (tablename === 'levels')
|
||||
mytable = Level;
|
||||
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 (!mydata.userId)
|
||||
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 (!mydata.admins) {
|
||||
mydata.admins = [];
|
||||
} else {
|
||||
const arrnew = [];
|
||||
/*const arrnew = [];
|
||||
for (const username of mydata.admins) {
|
||||
arrnew.push({username});
|
||||
}
|
||||
mydata.admins = arrnew;
|
||||
|
||||
*/
|
||||
}
|
||||
const indfind = mydata.admins.findIndex((rec) => (rec.username === req.user.username));
|
||||
|
||||
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.value_str = tools.cryptdata(fieldsvalue.value_str);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (mydata.table === shared_consts.TAB_SITES) {
|
||||
@@ -1089,6 +1103,7 @@ function load(req, res, version) {
|
||||
let subSkills = SubSkill.findAllIdApp(idapp);
|
||||
let statusSkills = StatusSkill.findAllIdApp(idapp);
|
||||
let sectors = Sector.findAllIdApp(idapp);
|
||||
let catgrps = CatGrp.findAllIdApp(idapp);
|
||||
let cities = City.findAllIdApp(idapp);
|
||||
let cart = null;
|
||||
let orderscart = null;
|
||||
@@ -1145,7 +1160,9 @@ function load(req, res, version) {
|
||||
sectors,
|
||||
statusSkills,
|
||||
cities,
|
||||
myuserextra]).then((arrdata) => {
|
||||
myuserextra,
|
||||
catgrps,
|
||||
]).then((arrdata) => {
|
||||
// console.table(arrdata);
|
||||
let myuser = req.user;
|
||||
if (myuser) {
|
||||
@@ -1216,6 +1233,8 @@ function load(req, res, version) {
|
||||
sectors: arrdata[27],
|
||||
statusSkills: arrdata[28],
|
||||
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);
|
||||
|
||||
if (ris) {
|
||||
if (tools.isFileExists(resized_img)) {
|
||||
tools.delete(newname, false, () => {});
|
||||
|
||||
tools.move(resized_img, newname, (err) => {
|
||||
|
||||
if (err)
|
||||
console.error('err', err);
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('newname', e);
|
||||
}
|
||||
|
||||
@@ -5,34 +5,45 @@ 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 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');
|
||||
|
||||
router.post('/load', authenticate, async (req, res) => {
|
||||
const idapp = req.body.idapp;
|
||||
const groupname = req.body.groupname;
|
||||
|
||||
try{
|
||||
data = await MyGroup.findOne({idapp, groupname}).lean();
|
||||
try {
|
||||
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) {
|
||||
console.error('Error in MyGroups');
|
||||
const users_in_group = await User.find(
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
const ris = null
|
||||
|
||||
const ris = null;
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ var mongoose = require('mongoose').set('debug', false);
|
||||
const Subscription = mongoose.model('subscribers');
|
||||
|
||||
const _ = require('lodash');
|
||||
const { MySkill } = require('../models/myskill');
|
||||
var { User } = require('../models/user');
|
||||
const {MySkill} = require('../models/myskill');
|
||||
var {User} = require('../models/user');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
|
||||
@@ -23,7 +23,8 @@ router.post('/page', authenticate, function(req, res, next) {
|
||||
let idSkill = req.body.idSkill;
|
||||
let idapp = req.body.idapp;
|
||||
|
||||
return MySkill.getMySkillByIdkill(idapp, idSkill).then((ris) => {
|
||||
return MySkill.getMySkillByIdkill(idapp, idSkill).
|
||||
then((ris) => {
|
||||
|
||||
if (ris) {
|
||||
res.send(ris);
|
||||
@@ -36,9 +37,13 @@ router.post('/page', authenticate, function(req, res, next) {
|
||||
*/
|
||||
|
||||
} else {
|
||||
res.status(400).send(e);
|
||||
res.status(400).send();
|
||||
}
|
||||
});
|
||||
}).catch((e) => {
|
||||
console.error('Err', e);
|
||||
res.status(400).send(e);
|
||||
})
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -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);
|
||||
}).catch((e) => {
|
||||
tools.mylog('ERRORE IN groups/cmd: ' + e.message);
|
||||
|
||||
@@ -120,6 +120,8 @@ const textlang = {
|
||||
'MSG_SEND_FROM': 'Msg Inviato da',
|
||||
'ZOOM_CONFERMATO': 'Sei stato confermato ad aver visto la Video Conferenza di Benvenuto!',
|
||||
'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: {},
|
||||
es: {
|
||||
@@ -851,8 +853,13 @@ module.exports = {
|
||||
|
||||
const arrusernameAdmins = group.admins;
|
||||
|
||||
for (const username of arrusernameAdmins) {
|
||||
const user = await User.get
|
||||
for (const arradmins of arrusernameAdmins) {
|
||||
try {
|
||||
if (arradmins.username) {
|
||||
const user = await User.findOne({idapp, username: arradmins.username},
|
||||
{_id: 1, lang: 1});
|
||||
if (user) {
|
||||
|
||||
let userId = user._id;
|
||||
let lang = user.lang;
|
||||
|
||||
@@ -862,26 +869,38 @@ module.exports = {
|
||||
let tag = '';
|
||||
let actions = [];
|
||||
if (cmd) {
|
||||
if (cmd === shared_consts.FRIENDSCMD.REQFRIEND) {
|
||||
descr = printf(this.get__('RICHIESTA_AMICIZIA', lang), username);
|
||||
openUrl = '/my/' + username;
|
||||
tag = 'reqfriends';
|
||||
if (cmd === shared_consts.GROUPSCMD.REQGROUP) {
|
||||
descr = printf(this.get__('RICHIESTA_GRUPPO', lang), groupname,
|
||||
arradmins.username);
|
||||
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) {
|
||||
this.sendNotificationToUser(userId, title, descr, openUrl, '', tag,
|
||||
this.sendNotificationToUser(userId, title, descr, openUrl, '',
|
||||
tag,
|
||||
actions);
|
||||
}
|
||||
|
||||
if (telegram) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (e){
|
||||
console.error('sendNotificationByGroupname', e);
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
@@ -63,10 +63,14 @@ module.exports = {
|
||||
TAB_PHONES: 'phones',
|
||||
TAB_SETTINGS: 'settings',
|
||||
TAB_SITES: 'sites',
|
||||
TAB_MYGROUPS: 'mygroups',
|
||||
TAB_MYBOTS: 'mybots',
|
||||
|
||||
KEY_TO_CRYPTED: ['PWD_FROM'],
|
||||
SITES_KEY_TO_CRYPTED: ['email_pwd'],
|
||||
MYGROUPS_KEY_TO_CRYPTED: 'pwd',
|
||||
|
||||
SUFFIX_CRYPTED: ['_cryp'],
|
||||
|
||||
TablePickup: ['countries', 'phones'],
|
||||
|
||||
@@ -84,8 +88,8 @@ module.exports = {
|
||||
TABLES_USER_INCLUDE_MY: ['mygroups'],
|
||||
TABLES_UPDATE_LASTMODIFIED: ['myskills', 'mybots', 'mygroups'],
|
||||
|
||||
TABLES_PERM_CHANGE_FOR_USERS: ['myskills'],
|
||||
TABLES_PERM_NEWREC: ['skills', 'subskills'],
|
||||
TABLES_PERM_CHANGE_FOR_USERS: ['myskills', 'mygroups'],
|
||||
TABLES_PERM_NEWREC: ['skills', 'subskills', 'mygroups'],
|
||||
|
||||
VISIB_ALL: 0,
|
||||
VISIB_ONLYIF_VERIFIED: 1,
|
||||
|
||||
Reference in New Issue
Block a user