Add to the Circuit
Remove to the Circuit Revoke request Users Admins
This commit is contained in:
@@ -41,12 +41,16 @@ const AccountSchema = new Schema({
|
||||
saldo: {
|
||||
type: Number,
|
||||
},
|
||||
deleted: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
});
|
||||
|
||||
AccountSchema.statics.findAllIdApp = async function(idapp) {
|
||||
const Account = this;
|
||||
|
||||
const myfind = {idapp};
|
||||
const myfind = {idapp, deleted: false};
|
||||
|
||||
return await Account.find(myfind, (err, arrrec) => {
|
||||
return arrrec;
|
||||
@@ -79,7 +83,7 @@ AccountSchema.statics.getFieldsForSearch = function() {
|
||||
|
||||
AccountSchema.statics.executeQueryTable = function(idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, 0, params);
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
AccountSchema.statics.getAccountsByUsername = async function(idapp, username) {
|
||||
@@ -93,7 +97,7 @@ AccountSchema.statics.getAccountsByUsername = async function(idapp, username) {
|
||||
'username': username,
|
||||
};
|
||||
|
||||
return await Account.find(myquery);
|
||||
return await Account.find(myquery).lean();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ mongoose.level = 'F';
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
const {User} = require('./user');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
@@ -49,9 +48,6 @@ const CircuitSchema = new Schema({
|
||||
systemUserId: {
|
||||
type: String,
|
||||
},
|
||||
founderUserId: {
|
||||
type: String,
|
||||
},
|
||||
totCircolante: {
|
||||
type: Number,
|
||||
},
|
||||
@@ -149,6 +145,16 @@ const CircuitSchema = new Schema({
|
||||
},
|
||||
});
|
||||
|
||||
CircuitSchema.pre('save', async function(next) {
|
||||
if (this.isNew) {
|
||||
|
||||
this.date_created = new Date();
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
|
||||
CircuitSchema.statics.findAllIdApp = async function(idapp) {
|
||||
const Circuit = this;
|
||||
|
||||
@@ -186,7 +192,7 @@ CircuitSchema.statics.getFieldsForSearch = function() {
|
||||
|
||||
CircuitSchema.statics.executeQueryTable = function(idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, 0, params);
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getWhatToShow = function(idapp, username) {
|
||||
@@ -201,18 +207,23 @@ CircuitSchema.statics.getWhatToShow = function(idapp, username) {
|
||||
longdescr: 1,
|
||||
regulation: 1,
|
||||
systemUserId: 1,
|
||||
founderUserId: 1,
|
||||
createdBy: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
nome_valuta: 1,
|
||||
symbol: 1,
|
||||
abbrev: 1,
|
||||
data_costituz: 1,
|
||||
img_logo: 1,
|
||||
admins: 1,
|
||||
req_users: 1,
|
||||
refused_users: 1,
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
// Rimuovi dagli Admin del Circuito
|
||||
MyGroupSchema.statics.removeAdminOfMyCircuit = async function(idapp, username, name) {
|
||||
CircuitSchema.statics.removeAdminOfMyCircuit = async function(idapp, username, name) {
|
||||
|
||||
return Circuit.updateOne({idapp, name},
|
||||
{$pull: {admins: {username: {$in: [username]}}}});
|
||||
@@ -236,6 +247,12 @@ CircuitSchema.statics.getWhatToShow_Unknown = function(idapp, username) {
|
||||
abbrev: 1,
|
||||
data_costituz: 1,
|
||||
img_logo: 1,
|
||||
admins: 1,
|
||||
createdBy: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
req_users: 1,
|
||||
refused_users: 1,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -247,20 +264,29 @@ CircuitSchema.statics.getCircuitsByUsername = async function(idapp, username, re
|
||||
|
||||
const whatToShow = this.getWhatToShow(idapp, username);
|
||||
const whatToShow_Unknown = this.getWhatToShow_Unknown(idapp, username);
|
||||
// const arrUsernameCircuits = await User.getUsernameCircuitsByUsername(idapp,
|
||||
// username);
|
||||
// const arrUsernameCircuits = await User.getUsernameCircuitsByUsername(idapp, username);
|
||||
// const arrUsernameReqCircuits = await MyCircuit.getUsernameReqCircuitsByCircuitname(idapp, username);
|
||||
|
||||
let listUserAccounts = await Account.getAccountsByUsername(idapp, username);
|
||||
|
||||
const manage_mycircuits = await Circuit.find({
|
||||
idapp,
|
||||
'admins': {
|
||||
$elemMatch: {username: {$eq: username}},
|
||||
},
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
{deleted: {$exists: true, $eq: false}}],
|
||||
}).lean();
|
||||
|
||||
let listcircuits = await Circuit.find({
|
||||
idapp,
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
{deleted: {$exists: true, $eq: false}}],
|
||||
}, whatToShow_Unknown);
|
||||
}, whatToShow_Unknown).lean();
|
||||
|
||||
let listSentRequestCircuits = await Circuit.find({
|
||||
let asked_circuits = await Circuit.find({
|
||||
idapp,
|
||||
'req_users': {
|
||||
$elemMatch: {username: {$eq: username}},
|
||||
@@ -268,9 +294,9 @@ CircuitSchema.statics.getCircuitsByUsername = async function(idapp, username, re
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
{deleted: {$exists: true, $eq: false}}],
|
||||
}, whatToShow_Unknown);
|
||||
}, whatToShow_Unknown).lean();
|
||||
|
||||
let listRefusedCircuits = await Circuit.find({
|
||||
let refused_circuits = await Circuit.find({
|
||||
idapp,
|
||||
'refused_users': {
|
||||
$elemMatch: {username: {$eq: username}},
|
||||
@@ -278,29 +304,78 @@ CircuitSchema.statics.getCircuitsByUsername = async function(idapp, username, re
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
{deleted: {$exists: true, $eq: false}}],
|
||||
}, whatToShow_Unknown);
|
||||
}, whatToShow_Unknown).lean();
|
||||
|
||||
return {
|
||||
listUserAccounts,
|
||||
listcircuits,
|
||||
listSentRequestCircuits,
|
||||
listRefusedCircuits,
|
||||
asked_circuits,
|
||||
refused_circuits,
|
||||
manage_mycircuits,
|
||||
mycircuits: req.user.profile.mycircuits,
|
||||
};
|
||||
|
||||
} catch (e) {
|
||||
console.log('Error', e);
|
||||
console.log('Error getCircuitsByUsername', e);
|
||||
}
|
||||
|
||||
return {
|
||||
listUsersCircuit: [],
|
||||
listRequestUsersCircuit: [],
|
||||
listTrusted: [],
|
||||
listSentRequestCircuits: [],
|
||||
listRefusedCircuits: [],
|
||||
asked_circuits: [],
|
||||
refused_circuits: [],
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getInfoCircuitByName = async function(idapp, name) {
|
||||
|
||||
const whatToShow = this.getWhatToShow(idapp, '');
|
||||
|
||||
const myfind = {
|
||||
idapp,
|
||||
name,
|
||||
};
|
||||
|
||||
try {
|
||||
return await Circuit.findOne(myfind, whatToShow).lean();
|
||||
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.deleteCircuit = async function(idapp, usernameOrig, name) {
|
||||
console.log('Circuito ' + name + ' rimosso da ' + usernameOrig);
|
||||
return Circuit.findOneAndRemove({idapp, name});
|
||||
};
|
||||
|
||||
// Rimuovo la Richiesta del Circuito
|
||||
CircuitSchema.statics.removeReqCircuit = async function(idapp, username, name) {
|
||||
|
||||
return Circuit.updateOne({idapp, name},
|
||||
{$pull: {req_users: {username: {$in: [username]}}}});
|
||||
};
|
||||
|
||||
// Aggiungi agli utenti Rifiutati del Circuito
|
||||
CircuitSchema.statics.refuseReqCircuit = async function(idapp, username, name) {
|
||||
|
||||
return Circuit.updateOne({idapp, name},
|
||||
{
|
||||
$push:
|
||||
{
|
||||
refused_users: {
|
||||
username,
|
||||
date: new Date(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
const Circuit = mongoose.model('Circuit', CircuitSchema);
|
||||
|
||||
module.exports = {Circuit};
|
||||
|
||||
@@ -266,6 +266,7 @@ MyBachecaSchema.statics.getMyRecById = function(idapp, id) {
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
@@ -323,6 +324,7 @@ MyBachecaSchema.statics.getMyRecById = function(idapp, id) {
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
@@ -380,6 +382,7 @@ MyBachecaSchema.statics.getMyRecById = function(idapp, id) {
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
@@ -437,6 +440,7 @@ MyBachecaSchema.statics.getMyRecById = function(idapp, id) {
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
@@ -494,6 +498,7 @@ MyBachecaSchema.statics.getMyRecById = function(idapp, id) {
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
|
||||
@@ -170,6 +170,7 @@ MyGoodSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
surname: 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
@@ -263,6 +264,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
@@ -319,6 +321,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
@@ -376,6 +379,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
@@ -432,6 +436,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
@@ -488,6 +493,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
|
||||
@@ -332,7 +332,7 @@ MyGroupSchema.statics.getInfoGroupByGroupname = async function(idapp, groupname)
|
||||
return null;
|
||||
}
|
||||
|
||||
return rec;
|
||||
return ris;
|
||||
|
||||
};
|
||||
|
||||
@@ -348,8 +348,7 @@ MyGroupSchema.statics.getGroupsByUsername = async function(idapp, username, req)
|
||||
|
||||
const whatToShow = this.getWhatToShow(idapp, username);
|
||||
const whatToShow_Unknown = this.getWhatToShow_Unknown(idapp, username);
|
||||
const arrUsernameGroups = await User.getUsernameGroupsByUsername(idapp,
|
||||
username);
|
||||
const arrUsernameGroups = await User.getUsernameGroupsByUsername(idapp, username);
|
||||
// const arrUsernameReqGroups = await MyGroup.getUsernameReqGroupsByGroupname(idapp, username);
|
||||
|
||||
let listUsersGroup = await User.find({
|
||||
|
||||
@@ -170,6 +170,7 @@ MyHospSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
surname: 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
@@ -259,6 +260,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
@@ -311,6 +313,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
@@ -363,6 +366,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
@@ -415,6 +419,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
@@ -467,6 +472,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
|
||||
@@ -171,6 +171,7 @@ MySkillSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
surname: 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
@@ -263,6 +264,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
@@ -318,6 +320,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
@@ -373,6 +376,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
@@ -430,6 +434,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
@@ -485,6 +490,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
|
||||
@@ -219,7 +219,7 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
|
||||
tag = 'remgroup';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_REFUSED) {
|
||||
newdescr = i18n.__('GROUPS_REFUSED', userorig, recnotif.paramsObj.groupnameDest, recnotif.paramsObj.username_action);
|
||||
tag = 'addgroup';
|
||||
tag = 'refgroup';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_REQUEST_TO_ENTER) {
|
||||
newdescr = i18n.__('GROUP_REQUEST_TO_ENTER', userorig, recnotif.paramsObj.groupnameDest, recnotif.paramsObj.singleadmin_username);
|
||||
tag = 'reqgroups';
|
||||
@@ -249,6 +249,59 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
|
||||
}
|
||||
tag = 'removeadmingrp';
|
||||
}
|
||||
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS) {
|
||||
tag = 'circuit';
|
||||
recnotif.openUrl = '/circuit/' + recnotif.paramsObj.path;
|
||||
if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_NEW_REC) {
|
||||
newdescr = i18n.__('CIRCUIT_CREATED', userorig, recnotif.paramsObj.circuitnameDest);
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_ACCEPTED) {
|
||||
if (recnotif.paramsObj.isAdmin) {
|
||||
newdescr = i18n.__('ACCETTATO_NOTIFICA_ADMINS_CIRCUIT', userorig, recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.username_action);
|
||||
recnotif.openUrl = '/my/' + userorig;
|
||||
} else {
|
||||
newdescr = i18n.__('CIRCUIT_ACCEPTED', userorig, recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.username_action);
|
||||
}
|
||||
tag = 'addcircuit';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_REMOVED) {
|
||||
if (recnotif.paramsObj.username_action === recnotif.paramsObj.usernameDest && userorig === recnotif.paramsObj.usernameDest) {
|
||||
newdescr = i18n.__('CIRCUIT_EXIT_USER_TO_ME', recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.username_action);
|
||||
} else if (userorig === recnotif.paramsObj.usernameDest) {
|
||||
newdescr = i18n.__('CIRCUIT_REMOVED_TO_ME', recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.username_action);
|
||||
} else if (userorig === recnotif.paramsObj.username_action) {
|
||||
newdescr = i18n.__('CIRCUIT_EXIT_USER', userorig, recnotif.paramsObj.circuitnameDest);
|
||||
recnotif.openUrl = '/my/' + userorig;
|
||||
} else {
|
||||
newdescr = i18n.__('CIRCUIT_REMOVED', userorig, recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.username_action);
|
||||
}
|
||||
|
||||
tag = 'remcircuit';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_REFUSED) {
|
||||
newdescr = i18n.__('CIRCUIT_REFUSED', userorig, recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.username_action);
|
||||
tag = 'refcircuit';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_REQUEST_TO_ENTER) {
|
||||
newdescr = i18n.__('CIRCUIT_REQUEST_TO_ENTER', userorig, recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.singleadmin_username);
|
||||
tag = 'reqcircuits';
|
||||
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_DELETE_USER) {
|
||||
newdescr = i18n.__('CIRCUIT_ELIMINATO', userorig, recnotif.paramsObj.username_action);
|
||||
tag = 'deletecircuit';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_ADDED_ADMIN) {
|
||||
if (userorig === recnotif.paramsObj.usernameDest) {
|
||||
newdescr = i18n.__('CIRCUIT_ADDED_ADMIN_YOU', recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.username_action);
|
||||
} else {
|
||||
newdescr = i18n.__('CIRCUIT_ADDED_ADMIN', userorig, recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.username_action);
|
||||
recnotif.openUrl = '/my/' + userorig;
|
||||
}
|
||||
tag = 'addadmingrp';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_REMOVED_ADMIN) {
|
||||
if (userorig === recnotif.paramsObj.usernameDest) {
|
||||
newdescr = i18n.__('CIRCUITS_REMOVED_ADMIN_YOU', recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.username_action);
|
||||
} else {
|
||||
newdescr = i18n.__('CIRCUITS_REMOVED_ADMIN', userorig, recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.username_action);
|
||||
recnotif.openUrl = '/my/' + userorig;
|
||||
}
|
||||
tag = 'removeadmincircuit';
|
||||
}
|
||||
}
|
||||
|
||||
recnotif.tag = recnotif.tag ? recnotif.tag : tag;
|
||||
@@ -371,26 +424,35 @@ sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysa
|
||||
}
|
||||
} else if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS) {
|
||||
typeidsearch = shared_consts.TypeNotifs.ID_GROUP_NEW_REC;
|
||||
dest = myrecnotif.dest;
|
||||
if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_ACCEPTED) {
|
||||
typeidsearch = shared_consts.TypeNotifs.ID_GROUP_REQUEST_TO_ENTER;
|
||||
newstatus = shared_consts.GroupsNotifs.STATUS_GROUPS_ACCEPTED;
|
||||
dest = myrecnotif.dest;
|
||||
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_REFUSED) {
|
||||
typeidsearch = shared_consts.TypeNotifs.ID_GROUP_REQUEST_TO_ENTER;
|
||||
newstatus = shared_consts.GroupsNotifs.STATUS_GROUPS_REFUSED;
|
||||
dest = myrecnotif.dest;
|
||||
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_REMOVED) {
|
||||
typeidsearch = shared_consts.TypeNotifs.ID_GROUP_REQUEST_TO_ENTER;
|
||||
newstatus = shared_consts.GroupsNotifs.STATUS_GROUPS_REMOVED;
|
||||
dest = myrecnotif.dest;
|
||||
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_BLOCK_USER) {
|
||||
typeidsearch = shared_consts.TypeNotifs.ID_GROUP_REQUEST_TO_ENTER;
|
||||
newstatus = shared_consts.GroupsNotifs.STATUS_GROUPS_BLOCKED;
|
||||
dest = myrecnotif.dest;
|
||||
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_DELETE_USER) {
|
||||
typeidsearch = shared_consts.TypeNotifs.ID_GROUP_REQUEST_TO_ENTER;
|
||||
newstatus = shared_consts.GroupsNotifs.STATUS_GROUPS_DELETED;
|
||||
dest = myrecnotif.dest;
|
||||
}
|
||||
} else if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS) {
|
||||
typeidsearch = shared_consts.TypeNotifs.ID_CIRCUIT_NEW_REC;
|
||||
dest = myrecnotif.dest;
|
||||
if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_ACCEPTED) {
|
||||
typeidsearch = shared_consts.TypeNotifs.ID_CIRCUIT_REQUEST_TO_ENTER;
|
||||
newstatus = shared_consts.CircuitsNotif.STATUS_ACCEPTED;
|
||||
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_REFUSED) {
|
||||
typeidsearch = shared_consts.TypeNotifs.ID_CIRCUIT_REQUEST_TO_ENTER;
|
||||
newstatus = shared_consts.CircuitsNotif.STATUS_REFUSED;
|
||||
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_REMOVED) {
|
||||
newstatus = shared_consts.CircuitsNotif.STATUS_REMOVED;
|
||||
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_BLOCK_USER) {
|
||||
newstatus = shared_consts.CircuitsNotif.STATUS_BLOCKED;
|
||||
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_DELETE_USER) {
|
||||
newstatus = shared_consts.CircuitsNotif.STATUS_DELETED;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -481,7 +543,11 @@ sendNotifSchema.statics.getExtraParam = function(myrecnotif, paramsObj) {
|
||||
out.paramsObj = paramsObj;
|
||||
out.options = paramsObj.options ? paramsObj.options : [];
|
||||
out.typesend = paramsObj.typesend ? paramsObj.typesend : 0;
|
||||
out.extrafield = paramsObj.groupnameDest ? paramsObj.groupnameDest : '';
|
||||
if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS) {
|
||||
out.extrafield = paramsObj.circuitnameDest ? paramsObj.circuitnameDest : '';
|
||||
} else if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS) {
|
||||
out.extrafield = paramsObj.groupnameDest ? paramsObj.groupnameDest : '';
|
||||
}
|
||||
|
||||
return myrecnotif;
|
||||
};
|
||||
@@ -515,11 +581,11 @@ sendNotifSchema.statics.createNewNotifToSingleUser = async function(req, res, pa
|
||||
|
||||
try {
|
||||
let myrecnotif = new SendNotif(this.getDefaultRec(req));
|
||||
myrecnotif = this.getExtraParam(myrecnotif, paramsObj);
|
||||
|
||||
myrecnotif.typedir = typedir;
|
||||
myrecnotif.typeid = typeid;
|
||||
|
||||
myrecnotif = this.getExtraParam(myrecnotif, paramsObj);
|
||||
|
||||
await SendNotif.sendToSingleUserDest(myrecnotif, req, res, onlysave);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -14,6 +14,7 @@ const {Graduatoria} = require('../models/graduatoria');
|
||||
// const { ExtraList } = require('../models/extralist');
|
||||
|
||||
const {MyGroup} = require('../models/mygroup');
|
||||
const {Circuit} = require('../models/circuit');
|
||||
|
||||
const {Account} = require('../models/account');
|
||||
|
||||
@@ -371,6 +372,13 @@ const UserSchema = new mongoose.Schema({
|
||||
date: {type: Date},
|
||||
}], // username
|
||||
|
||||
mycircuits: [
|
||||
{
|
||||
_id: false,
|
||||
circuitname: {type: String},
|
||||
date: {type: Date},
|
||||
}], // username
|
||||
|
||||
notifs: [
|
||||
{
|
||||
_id: false,
|
||||
@@ -1583,7 +1591,14 @@ UserSchema.statics.getUsernameGroupsByUsername = async function(
|
||||
idapp, username) {
|
||||
|
||||
return this.getArrUsernameFromFieldByUsername(idapp, username, 'profile',
|
||||
'groups');
|
||||
'mygroups');
|
||||
|
||||
};
|
||||
UserSchema.statics.getUsernameCircuitsByUsername = async function(
|
||||
idapp, username) {
|
||||
|
||||
return this.getArrUsernameFromFieldByUsername(idapp, username, 'profile',
|
||||
'mycircuits');
|
||||
|
||||
};
|
||||
|
||||
@@ -1600,6 +1615,12 @@ UserSchema.statics.removeFromMyGroups = async function(
|
||||
return User.updateOne({idapp, username},
|
||||
{$pull: {'profile.mygroups': {groupname: {$in: [groupnameDest]}}}});
|
||||
};
|
||||
// Rimuovo il Gruppo
|
||||
UserSchema.statics.removeFromCircuits = async function(idapp, username, circuitname) {
|
||||
return User.updateOne({idapp, username},
|
||||
{$pull: {'profile.mycircuits': {circuitname: {$in: [circuitname]}}}});
|
||||
|
||||
};
|
||||
|
||||
// Rimuovo il Gruppo per Tutti gli Utenti
|
||||
UserSchema.statics.removeAllUsersFromMyGroups = async function(idapp, groupnameDest) {
|
||||
@@ -1607,6 +1628,12 @@ UserSchema.statics.removeAllUsersFromMyGroups = async function(idapp, groupnameD
|
||||
{$pull: {'profile.mygroups': {groupname: {$in: [groupnameDest]}}}});
|
||||
};
|
||||
|
||||
// Rimuovo il Circuito per Tutti gli Utenti
|
||||
UserSchema.statics.removeAllUsersFromMyCircuits = async function(idapp, circuitname) {
|
||||
return User.updateMany({idapp},
|
||||
{$pull: {'profile.mycircuits': {circuitname: {$in: [circuitname]}}}});
|
||||
};
|
||||
|
||||
// Rimuovo la Richiesta di Amicizia
|
||||
UserSchema.statics.removeReqFriend = async function(
|
||||
idapp, username, usernameDest) {
|
||||
@@ -1871,6 +1898,18 @@ UserSchema.statics.ifAlreadyInGroup = async function(idapp, usernameOrig, groupn
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.ifAlreadyInCircuit = async function(idapp, usernameOrig, circuitname) {
|
||||
|
||||
// Controllo se è stato già inserito
|
||||
return User.findOne({
|
||||
idapp,
|
||||
username: usernameOrig,
|
||||
'profile.mycircuits': {
|
||||
$elemMatch: {circuitname: {$eq: circuitname}},
|
||||
},
|
||||
}).lean();
|
||||
};
|
||||
|
||||
UserSchema.statics.countUsersInGroup = async function(idapp, groupnameDest) {
|
||||
|
||||
// Controllo se è stato già inserito
|
||||
@@ -1883,6 +1922,19 @@ UserSchema.statics.countUsersInGroup = async function(idapp, groupnameDest) {
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.countUsersInCircuit = async function(idapp, circuitname) {
|
||||
|
||||
// Controllo se è stato già inserito
|
||||
return User.countDocuments({
|
||||
idapp,
|
||||
'profile.mycircuits': {
|
||||
$elemMatch: {circuitname: {$eq: name}},
|
||||
},
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameDest, cmd, value, username_action) {
|
||||
|
||||
let ris = null;
|
||||
@@ -1984,6 +2036,12 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
|
||||
ris = await MyGroup.removeReqGroup(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me
|
||||
|
||||
} else if (cmd === shared_consts.GROUPSCMD.REFUSE_REQ_GROUP) {
|
||||
|
||||
ris = await MyGroup.removeReqGroup(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me
|
||||
|
||||
ris = await MyGroup.refuseReqGroup(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me
|
||||
|
||||
} else if (cmd === shared_consts.GROUPSCMD.BLOCK_GROUP) {
|
||||
|
||||
await User.removeFromMyGroups(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me
|
||||
@@ -2019,19 +2077,19 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
return ris;
|
||||
};
|
||||
|
||||
UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, name, cmd, value, username_action) {
|
||||
UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitname, cmd, value, username_action) {
|
||||
|
||||
let ris = null;
|
||||
let update = {};
|
||||
try {
|
||||
if (cmd === shared_consts.CIRCUITCMD.SET) {
|
||||
const foundIfAlreadyCircuit = await this.ifAlreadyInCircuit(idapp, usernameOrig, name);
|
||||
const foundIfAlreadyCircuit = await this.ifAlreadyInCircuit(idapp, usernameOrig, circuitname);
|
||||
|
||||
if (!foundIfAlreadyCircuit) {
|
||||
update = {
|
||||
$push: {
|
||||
'profile.mycircuits': {
|
||||
circuitname: name,
|
||||
circuitname,
|
||||
date: new Date(),
|
||||
},
|
||||
},
|
||||
@@ -2040,31 +2098,31 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, name, cmd
|
||||
|
||||
// Elimina la richiesta:
|
||||
update = {$pull: {req_users: {username: {$in: [usernameOrig]}}}};
|
||||
await Circuit.updateOne({idapp, groupname: name}, update);
|
||||
await Circuit.updateOne({idapp, name: circuitname}, update);
|
||||
|
||||
// Elimina eventualmente se era bloccato:
|
||||
update = {$pull: {refused_users: {username: {$in: [usernameOrig]}}}};
|
||||
await Circuit.updateOne({idapp, groupname: name}, update);
|
||||
await Circuit.updateOne({idapp, name: circuitname}, update);
|
||||
} else {
|
||||
ris = false;
|
||||
}
|
||||
if (ris) {
|
||||
// Invia una notifica alla persona e agli Admin
|
||||
tools.sendNotificationByGroupname(idapp, usernameOrig, name, cmd, value, true, username_action);
|
||||
ris = await Circuit.getInfoGroupByGroupname(idapp, name);
|
||||
tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, value, true, username_action);
|
||||
ris = await Circuit.getInfoCircuitByName(idapp, circuitname);
|
||||
}
|
||||
} else if (cmd === shared_consts.GROUPSCMD.REQGROUP) {
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REQ) {
|
||||
// Aggiungo la richiesta di Gruppo a me
|
||||
const foundIfAlreadyAskGroup = await Circuit.findOne({
|
||||
const foundIfAlreadyAskCircuit = await Circuit.findOne({
|
||||
idapp,
|
||||
groupname: name,
|
||||
name: circuitname,
|
||||
'req_users': {
|
||||
$elemMatch: {username: {$eq: usernameOrig}},
|
||||
},
|
||||
});
|
||||
|
||||
if (value) {
|
||||
if (!foundIfAlreadyAskGroup) {
|
||||
if (!foundIfAlreadyAskCircuit) {
|
||||
update = {
|
||||
$push: {
|
||||
'req_users': {
|
||||
@@ -2073,83 +2131,70 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, name, cmd
|
||||
},
|
||||
},
|
||||
};
|
||||
ris = await Circuit.updateOne({idapp, groupname: name},
|
||||
update);
|
||||
ris = await Circuit.updateOne({idapp, name: circuitname}, update);
|
||||
}
|
||||
if (ris) {
|
||||
// Invia una notifica alla persona
|
||||
await tools.sendNotificationByGroupname(idapp, usernameOrig, name, cmd, true, true, username_action);
|
||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, true, true, username_action);
|
||||
}
|
||||
} else {
|
||||
if (foundIfAlreadyAskGroup) {
|
||||
ris = await this.removeFromCircuits(idapp, usernameOrig, name); // Rimuovo il Gruppo da me
|
||||
if (foundIfAlreadyAskCircuit) {
|
||||
ris = await this.removeFromCircuits(idapp, usernameOrig, circuitname); // Rimuovo il Gruppo da me
|
||||
|
||||
// Invia una notifica alla persona
|
||||
await tools.sendNotificationByGroupname(idapp, usernameOrig, name, cmd, false, true, username_action);
|
||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action);
|
||||
}
|
||||
}
|
||||
|
||||
if (ris) {
|
||||
ris = await Circuit.getInfoGroupByGroupname(idapp, name);
|
||||
}
|
||||
ris = await Circuit.getInfoCircuitByName(idapp, circuitname);
|
||||
|
||||
} else if (cmd === shared_consts.GROUPSCMD.REMOVE_FROM_CIRCUIT) {
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REMOVE_FROM_MYLIST) {
|
||||
|
||||
// Remove if is also an Admin
|
||||
await Circuit.removeAdminOfMyCircuit(idapp, usernameOrig, name);
|
||||
await Circuit.removeAdminOfMyCircuit(idapp, usernameOrig, circuitname);
|
||||
|
||||
ris = await User.removeFromCircuits(idapp, usernameOrig, name); // Rimuovo l'Amicizia da me
|
||||
ris = await this.removeFromCircuits(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
||||
console.log('ris', ris);
|
||||
|
||||
// Invia una notifica alla persona
|
||||
await tools.sendNotificationByGroupname(idapp, usernameOrig, name, cmd, false, true, username_action);
|
||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action);
|
||||
|
||||
} else if (cmd === shared_consts.GROUPSCMD.DELETE_GROUP) {
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.DELETE) {
|
||||
|
||||
ris = await User.removeFromCircuits(idapp, usernameOrig, name); // Rimuovo l'Amicizia da me
|
||||
ris = await this.removeFromCircuits(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
||||
|
||||
if (ris) {
|
||||
// Invia una notifica alla persona e agli Admin
|
||||
await tools.sendNotificationByGroupname(idapp, usernameOrig, name, cmd, false, true, username_action);
|
||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action);
|
||||
|
||||
}
|
||||
ris = await Circuit.deleteGroup(idapp, usernameOrig, name); // Rimuovo l'Amicizia da me
|
||||
console.log('ris', ris);
|
||||
ris = await Circuit.deleteCircuit(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
||||
|
||||
} else if (cmd === shared_consts.GROUPSCMD.CANCEL_REQ_GROUP) {
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.CANCEL_REQ) {
|
||||
|
||||
ris = await Circuit.removeReqGroup(idapp, usernameOrig, name); // Rimuovo l'Amicizia da me
|
||||
ris = await Circuit.removeReqCircuit(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
||||
|
||||
} else if (cmd === shared_consts.GROUPSCMD.BLOCK_GROUP) {
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REFUSE_REQ) {
|
||||
|
||||
await User.removeFromCircuits(idapp, usernameOrig, name); // Rimuovo l'Amicizia da me
|
||||
ris = await Circuit.removeReqCircuit(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
||||
|
||||
// Blocco il Gruppo
|
||||
ris = await Circuit.updateOne({idapp, groupname: name}, {
|
||||
$set: {
|
||||
blocked: true,
|
||||
username_who_block: usernameOrig,
|
||||
date_blocked: new Date(),
|
||||
},
|
||||
});
|
||||
//++Todo: Send Notification to Admin and Group's manager
|
||||
tools.sendNotificationByGroupname(idapp, usernameOrig, name, cmd, false, true, username_action);
|
||||
ris = await Circuit.refuseReqCircuit(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
||||
|
||||
} else if (cmd === shared_consts.GROUPSCMD.ADDADMIN_OFCIRCUIT) {
|
||||
ris = await Circuit.addToAdminOfCircuit(idapp, usernameOrig, name); // Rimuovo la richiesta di entrare nel gruppo
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.ADDADMIN) {
|
||||
ris = await Circuit.addToAdminOfCircuit(idapp, usernameOrig, circuitname); // Rimuovo la richiesta di entrare nel gruppo
|
||||
|
||||
// Invia una notifica alla persona
|
||||
await tools.sendNotificationByGroupname(idapp, usernameOrig, name, cmd, false, true, username_action);
|
||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action);
|
||||
|
||||
} else if (cmd === shared_consts.GROUPSCMD.REMOVEADMIN_OFCIRCUIT) {
|
||||
ris = await Circuit.removeAdminOfCircuit(idapp, usernameOrig, name); // Rimuovo la richiesta di entrare nel gruppo
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REMOVEADMIN) {
|
||||
ris = await Circuit.removeAdminOfCircuit(idapp, usernameOrig, circuitname); // Rimuovo la richiesta di entrare nel gruppo
|
||||
|
||||
// Invia una notifica alla persona
|
||||
await tools.sendNotificationByGroupname(idapp, usernameOrig, name, cmd, false, true, username_action);
|
||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action);
|
||||
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error: ', e);
|
||||
console.error('Error setCircuitCmd: ', e);
|
||||
}
|
||||
|
||||
return ris;
|
||||
@@ -3635,7 +3680,7 @@ UserSchema.statics.DbOp = async function(idapp, mydata) {
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.addExtraInfo = async function(idapp, recUser) {
|
||||
UserSchema.statics.addExtraInfo = async function(idapp, recUser, req) {
|
||||
|
||||
try {
|
||||
const listSentMyRequestFriends = await User.find({
|
||||
@@ -3694,15 +3739,11 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser) {
|
||||
? listManageGroups
|
||||
: [];
|
||||
|
||||
// UserAccounts
|
||||
|
||||
const listUserAccounts = await Account.getAccountsByUsername(idapp, recUser.username);
|
||||
|
||||
recUser._doc.profile.listUserAccounts = listUserAccounts
|
||||
? listUserAccounts
|
||||
: [];
|
||||
// Circuit
|
||||
|
||||
const circuitobj = await Circuit.getCircuitsByUsername(idapp, recUser.username, req);
|
||||
|
||||
recUser._doc.profile = {...recUser._doc.profile, ...circuitobj};
|
||||
|
||||
return recUser._doc;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user