- L'utente entra direttamente sul circuito, con fido a zero.
++Abilitazione Fido utente (per admin).
This commit is contained in:
@@ -56,12 +56,15 @@ const AccountSchema = new Schema({
|
||||
},
|
||||
importo_iniziale: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
saldo: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
totTransato: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
regulation_ok: {
|
||||
type: Boolean,
|
||||
@@ -202,7 +205,7 @@ AccountSchema.pre('save', async function (next) {
|
||||
next();
|
||||
});
|
||||
|
||||
AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp, username, circuitId, createifnotexist, groupname = '', contocom = "") {
|
||||
AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp, username, circuitId, createifnotexist, confido, groupname = '', contocom = "") {
|
||||
const Account = this;
|
||||
|
||||
try {
|
||||
@@ -263,6 +266,9 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp,
|
||||
}
|
||||
}
|
||||
|
||||
if (!confido) {
|
||||
myaccount.fidoConcesso = 0;
|
||||
}
|
||||
|
||||
return await myaccount.save();
|
||||
}
|
||||
@@ -277,14 +283,52 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp,
|
||||
|
||||
};
|
||||
|
||||
AccountSchema.statics.createAccount = async function (idapp, username, circuitName, groupname = '', contocom = '') {
|
||||
AccountSchema.statics.isExistAccountByUsernameAndCircuitId = async function (idapp, username, circuitId, groupname = '', contocom = "") {
|
||||
const Account = this;
|
||||
|
||||
try {
|
||||
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
if (username === undefined)
|
||||
return false;
|
||||
|
||||
let myquery = {
|
||||
idapp,
|
||||
circuitId,
|
||||
};
|
||||
|
||||
if (groupname) {
|
||||
myquery.groupname = groupname;
|
||||
} else if (contocom) {
|
||||
myquery.contocom = contocom;
|
||||
} else {
|
||||
myquery.username = username;
|
||||
}
|
||||
|
||||
let mycircuit = await Circuit.getCircuitById(circuitId);
|
||||
|
||||
if (mycircuit) {
|
||||
let myaccount = await Account.findOne(myquery);
|
||||
return !!myaccount
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
} catch (e) {
|
||||
console.error('error', e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
AccountSchema.statics.createAccount = async function (idapp, username, circuitName, confido, groupname = '', contocom = '') {
|
||||
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
try {
|
||||
mycircuit = await Circuit.findOne({ name: circuitName }, { _id: 1 });
|
||||
if (mycircuit) {
|
||||
return await Account.getAccountByUsernameAndCircuitId(idapp, username, mycircuit._id, true, groupname, contocom);
|
||||
return await Account.getAccountByUsernameAndCircuitId(idapp, username, mycircuit._id, true, confido, groupname, contocom);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -337,6 +381,11 @@ AccountSchema.statics.getUserAccounts = async function (idapp, username) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$group:
|
||||
{ _id: "$extrarec.notifIdToUpdate", result: { $first: "$$ROOT" } }
|
||||
},
|
||||
|
||||
],
|
||||
},
|
||||
},
|
||||
@@ -349,8 +398,9 @@ AccountSchema.statics.getUserAccounts = async function (idapp, username) {
|
||||
if (ris) {
|
||||
for (const account of ris) {
|
||||
const pendingtransactions = await SendNotif.getSumPendingTransactions(idapp, username, account.circuit.name);
|
||||
const saldopending = pendingtransactions.reduce((sum, rec) => sum + rec.extrarec.qty, 0);
|
||||
const saldopending = pendingtransactions.reduce((sum, rec) => sum + rec.result.extrarec.qty, 0);
|
||||
account.saldo -= saldopending;
|
||||
account.totTransato = account.totTransato || 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -403,6 +453,10 @@ AccountSchema.statics.getGroupAccounts = async function (idapp, groupname) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$group:
|
||||
{ _id: "$extrarec.notifIdToUpdate", result: { $first: "$$ROOT" } }
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
@@ -415,7 +469,7 @@ AccountSchema.statics.getGroupAccounts = async function (idapp, groupname) {
|
||||
if (ris) {
|
||||
for (const account of ris) {
|
||||
const pendingtransactions = await SendNotif.getSumPendingTransactions(idapp, '', account.circuit.name, groupname);
|
||||
const saldopending = pendingtransactions.reduce((sum, rec) => sum + rec.extrarec.qty, 0);
|
||||
const saldopending = pendingtransactions.reduce((sum, rec) => sum + rec.result.extrarec.qty, 0);
|
||||
account.saldo -= saldopending;
|
||||
}
|
||||
}
|
||||
@@ -472,6 +526,16 @@ AccountSchema.statics.SetMinMaxPersonali = async function (idapp, valmin, valmax
|
||||
|
||||
};
|
||||
|
||||
AccountSchema.statics.updateFido = async function (idapp, username, circuitId, fido) {
|
||||
|
||||
let paramstoupdate = {
|
||||
fidoConcesso: fido,
|
||||
};
|
||||
const risult = await Account.updateOne({ idapp, username, circuitId }, { $set: paramstoupdate });
|
||||
|
||||
return risult;
|
||||
};
|
||||
|
||||
AccountSchema.statics.addToPeopleOfMyAccount = async function (idapp, username, circuitId, person_username, perm) {
|
||||
|
||||
return await Account.updateOne({ idapp, username, circuitId },
|
||||
|
||||
@@ -505,59 +505,6 @@ CircuitSchema.statics.deleteCircuit = async function (idapp, usernameOrig, name)
|
||||
return await Circuit.findOneAndRemove({ idapp, name });
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getUserCircuits = async function (idapp, username) {
|
||||
|
||||
try {
|
||||
let aggr1 = [
|
||||
{
|
||||
$match: {
|
||||
idapp, username,
|
||||
$or: [
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'circuits',
|
||||
localField: 'circuitId',
|
||||
foreignField: '_id',
|
||||
as: 'circuit',
|
||||
},
|
||||
},
|
||||
{
|
||||
'$replaceRoot': {
|
||||
'newRoot': {
|
||||
'$mergeObjects': [
|
||||
{
|
||||
'$arrayElemAt': [
|
||||
'$circuit',
|
||||
0,
|
||||
],
|
||||
},
|
||||
'$$ROOT',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
/*
|
||||
{
|
||||
$project: {
|
||||
"circuit.name": 1,
|
||||
},
|
||||
},
|
||||
|
||||
*/
|
||||
];
|
||||
|
||||
ris = await this.aggregate(aggr1);
|
||||
|
||||
return ris;
|
||||
} catch (e) {
|
||||
console.error('e', e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getUsersSingleCircuit = async function (idapp, username, circuitname, circuitId) {
|
||||
|
||||
@@ -676,8 +623,16 @@ CircuitSchema.statics.sendCoins = async function (onlycheck, idapp, usernameOrig
|
||||
if (circuittable) {
|
||||
const myqty = Math.abs(extrarec.qty);
|
||||
|
||||
const accountdestTable = await Account.getAccountByUsernameAndCircuitId(idapp, extrarec.dest, circuittable._id, true, extrarec.groupdest, extrarec.contoComDest);
|
||||
const accountorigTable = await Account.getAccountByUsernameAndCircuitId(idapp, usernameOrig, circuittable._id, true, extrarec.grouporig, extrarec.contoComOrig);
|
||||
const esisteDest = await Account.isExistAccountByUsernameAndCircuitId(idapp, extrarec.dest, circuittable._id, extrarec.groupdest, extrarec.contoComDest);
|
||||
|
||||
if (!esisteDest) {
|
||||
// Fallo entrare anche sul Circuito (oltre ad aver creato l'Account).
|
||||
await this.addCircuitToUser(idapp, usernameOrig, circuitname, false, extrarec.groupdest, extrarec.contoComDest);
|
||||
}
|
||||
|
||||
const accountdestTable = await Account.getAccountByUsernameAndCircuitId(idapp, extrarec.dest, circuittable._id, true, false, extrarec.groupdest, extrarec.contoComDest);
|
||||
const accountorigTable = await Account.getAccountByUsernameAndCircuitId(idapp, usernameOrig, circuittable._id, true, true, extrarec.grouporig, extrarec.contoComOrig);
|
||||
|
||||
|
||||
const circolantePrec = this.getCircolanteSingolaTransaz(accountorigTable, accountdestTable);
|
||||
|
||||
@@ -903,6 +858,19 @@ CircuitSchema.statics.SetDefMinMaxCollettivi = async function (idapp, valmin, va
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.AbilitaTuttiCircuiti = async function (idapp) {
|
||||
|
||||
ris = await Circuit.updateMany({ idapp },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
transactionsEnabled: true
|
||||
}
|
||||
});
|
||||
|
||||
return ris;
|
||||
};
|
||||
|
||||
// Imposta a tutti i Conti Personali, i seguenti minimi e massimi
|
||||
CircuitSchema.statics.SetDefMinMaxPersonali = async function (idapp, valmin, valmax) {
|
||||
|
||||
@@ -932,14 +900,14 @@ CircuitSchema.statics.createCircuitIfNotExist = async function (req, idapp, prov
|
||||
if (!circuit && nomeprovincia) {
|
||||
const circ = new Circuit({
|
||||
idapp,
|
||||
name: 'RIS ' + nomeprovincia,
|
||||
name: 'Circuito RIS ' + nomeprovincia,
|
||||
path: 'ris' + tools.convertSpaces_ToUScore(nomeprovincia.toLowerCase()),
|
||||
strProv: province,
|
||||
photos: [],
|
||||
admins: [],
|
||||
color: '#ff5500',
|
||||
deperimento: false,
|
||||
transactionsEnabled: false,
|
||||
transactionsEnabled: true, // Abilita cmq il circuito dall'inizio
|
||||
status: shared_consts.CIRCUIT_STATUS.FASE1_CREAZIONE_GRUPPO,
|
||||
symbol: 'RIS',
|
||||
fido_scoperto_default: 100,
|
||||
@@ -960,13 +928,13 @@ CircuitSchema.statics.createCircuitIfNotExist = async function (req, idapp, prov
|
||||
// nuovo Circuito:
|
||||
await User.setCircuitCmd(idapp, useradmin, myrec.name,
|
||||
shared_consts.CIRCUITCMD.CREATE, true, useradmin, myrec).then((ris) => {
|
||||
|
||||
|
||||
});
|
||||
|
||||
// aggiungi il creatore al Circuito stesso
|
||||
await User.setCircuitCmd(idapp, useradmin, myrec.name,
|
||||
shared_consts.CIRCUITCMD.SET, true, useradmin, myrec).then((ris) => {
|
||||
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
@@ -981,6 +949,32 @@ CircuitSchema.statics.createCircuitIfNotExist = async function (req, idapp, prov
|
||||
return myrec;
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getListCircuitsByUsername = async function (idapp, username, groupname) {
|
||||
|
||||
let mystr = '';
|
||||
const { User } = require('../models/user');
|
||||
const myuser = await User.getUserByUsername(idapp, username);
|
||||
|
||||
const useraccounts = await Account.getUserAccounts(idapp, username);
|
||||
|
||||
for (let account of useraccounts) {
|
||||
if (myuser.profile.mycircuits.find((rec) => (rec.circuitname === account.circuit.name))) {
|
||||
mystr += '\n👉🏻 ' + account.circuit.name + '\n';
|
||||
mystr += '[Saldo: ' + account.saldo + ' RIS, ';
|
||||
mystr += ' Fido: ' + account.fidoConcesso + ' RIS, ';
|
||||
mystr += ' Transato: ' + account.totTransato + ' RIS]';
|
||||
}
|
||||
}
|
||||
|
||||
if (!mystr) {
|
||||
mystr = '[Nessun Circuito]';
|
||||
}
|
||||
|
||||
return mystr;
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.SetDefMinMaxCollettivi = async function (idapp, valmin, valmax) {
|
||||
|
||||
ris = await Circuit.updateMany({ idapp },
|
||||
@@ -994,6 +988,27 @@ CircuitSchema.statics.SetDefMinMaxCollettivi = async function (idapp, valmin, va
|
||||
|
||||
};
|
||||
|
||||
|
||||
CircuitSchema.statics.setFido = async function (idapp, username, circuitName, groupname) {
|
||||
|
||||
mycircuit = await Circuit.findOne({ idapp, name: circuitName });
|
||||
if (mycircuit) {
|
||||
const circuitId = mycircuit._id;
|
||||
|
||||
const account = await Account.getAccountByUsernameAndCircuitId(idapp, username, circuitId, true, true, groupname, '');
|
||||
if (account) {
|
||||
let fido = 0;
|
||||
if (groupname)
|
||||
fido = mycircuit.fido_scoperto_default_grp;
|
||||
else
|
||||
fido = mycircuit.fido_scoperto_default;
|
||||
|
||||
return await Account.updateFido(idapp, username, circuitId, fido);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const Circuit = mongoose.model('Circuit', CircuitSchema);
|
||||
|
||||
module.exports = { Circuit };
|
||||
|
||||
@@ -47,9 +47,11 @@ const MovementSchema = new Schema({
|
||||
},
|
||||
causal: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
residual: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
expiringDate: {
|
||||
type: Date,
|
||||
@@ -128,7 +130,7 @@ MovementSchema.statics.getQueryMovsByCircuitId = async function (idapp, username
|
||||
if (!circuitId) {
|
||||
return [];
|
||||
}
|
||||
const myaccount = await Account.getAccountByUsernameAndCircuitId(idapp, username, circuitId, false, groupname, contocom);
|
||||
const myaccount = await Account.getAccountByUsernameAndCircuitId(idapp, username, circuitId, false, true, groupname, contocom);
|
||||
|
||||
if (myaccount) {
|
||||
|
||||
|
||||
@@ -176,6 +176,7 @@ MyBachecaSchema.statics.executeQueryTable = function (idapp, params, user) {
|
||||
MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
const MyBacheca = this;
|
||||
|
||||
|
||||
let myparsid = {
|
||||
'_id': id,
|
||||
idapp,
|
||||
@@ -273,6 +274,20 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
'from': 'mygroups',
|
||||
'localField': 'groupname',
|
||||
'foreignField': 'groupname',
|
||||
'as': 'mygrp',
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: '$mygrp',
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': shared_consts.getProjectForAll({}, tableModel),
|
||||
},
|
||||
@@ -330,7 +345,7 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
try {
|
||||
let numtab = tools.getNumTabByTable(shared_consts.TABLES_MYBACHECAS);
|
||||
|
||||
const objadd = tools.addNumFavoriteAndBookmarkToQuery(idapp, numtab);
|
||||
let objadd = tools.addNumFavoriteAndBookmarkToQuery(idapp, numtab);
|
||||
query = [...query, ...objadd.query];
|
||||
|
||||
const toadd = {
|
||||
|
||||
@@ -35,6 +35,9 @@ const ProvinceSchema = new Schema({
|
||||
link_grp: {
|
||||
type: String,
|
||||
},
|
||||
link_telegram: {
|
||||
type: String,
|
||||
},
|
||||
}, { _id : false });
|
||||
|
||||
ProvinceSchema.statics.getRegionByStrProvince = async function(strprovince) {
|
||||
|
||||
@@ -171,9 +171,12 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
let newdescr = '';
|
||||
let mydescr = '';
|
||||
let myidrec = '';
|
||||
let sender = recnotif.sender;
|
||||
let sender = recnotif.sender ? recnotif.sender : '';
|
||||
let tag = '';
|
||||
|
||||
const { Circuit } = require('../models/circuit');
|
||||
const { User } = require('../models/user');
|
||||
|
||||
try {
|
||||
if (recnotif.myrectableorig) {
|
||||
myidrec = recnotif.myrectableorig._id;
|
||||
@@ -309,11 +312,17 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
}
|
||||
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS) {
|
||||
tag = 'circuit';
|
||||
let strtipocontoDest = '';
|
||||
let strtipocontoOrig = '';
|
||||
let groupOComorig = '';
|
||||
let groupOComdest = '';
|
||||
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TAB_MYCIRCUITS, true) + recnotif.paramsObj.path;
|
||||
strtipocontoOrig = recnotif.paramsObj.extrarec.contoComOrig ? i18n.__('COMUNITARIO') : i18n.__('COLLETTIVO');
|
||||
strtipocontoDest = recnotif.paramsObj.extrarec.contoComDest ? i18n.__('COMUNITARIO') : i18n.__('COLLETTIVO');
|
||||
let groupOComorig = recnotif.paramsObj.extrarec.contoComOrig ? recnotif.paramsObj.extrarec.contoComOrig : recnotif.paramsObj.extrarec.grouporig;
|
||||
let groupOComdest = recnotif.paramsObj.extrarec.contoComDest ? recnotif.paramsObj.extrarec.contoComDest : recnotif.paramsObj.extrarec.groupdest;
|
||||
if (recnotif.paramsObj.extrarec) {
|
||||
strtipocontoOrig = recnotif.paramsObj.extrarec.contoComOrig ? i18n.__('COMUNITARIO') : i18n.__('COLLETTIVO');
|
||||
strtipocontoDest = recnotif.paramsObj.extrarec.contoComDest ? i18n.__('COMUNITARIO') : i18n.__('COLLETTIVO');
|
||||
groupOComorig = recnotif.paramsObj.extrarec.contoComOrig ? recnotif.paramsObj.extrarec.contoComOrig : recnotif.paramsObj.extrarec.grouporig;
|
||||
groupOComdest = recnotif.paramsObj.extrarec.contoComDest ? recnotif.paramsObj.extrarec.contoComDest : recnotif.paramsObj.extrarec.groupdest;
|
||||
}
|
||||
let myorig = '';
|
||||
let mydest = '';
|
||||
let destinatario = '';
|
||||
@@ -338,6 +347,21 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
|
||||
if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_NEW_REC) {
|
||||
newdescr = i18n.__('CIRCUIT_CREATED', sender, recnotif.paramsObj.circuitnameDest);
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_SETFIDO) {
|
||||
if (recnotif.paramsObj.isAdmin) {
|
||||
if (recnotif.extrarec.groupname) {
|
||||
newdescr = i18n.__('FIDO_IMPOSTATO_ADMINS_CIRCUIT_MYGROUP', recnotif.extrarec.groupname, recnotif.paramsObj.circuitnameDest,
|
||||
username_action);
|
||||
} else {
|
||||
newdescr = i18n.__('FIDO_IMPOSTATO_ADMINS_CIRCUIT', sender, recnotif.paramsObj.circuitnameDest,
|
||||
username_action);
|
||||
}
|
||||
|
||||
recnotif.openUrl = '/my/' + sender;
|
||||
} else {
|
||||
newdescr = i18n.__('FIDO_IMPOSTATO', username_action, recnotif.paramsObj.circuitnameDest);
|
||||
}
|
||||
tag = 'setfido';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_ACCEPTED) {
|
||||
if (recnotif.paramsObj.isAdmin) {
|
||||
if (recnotif.extrarec.groupname) {
|
||||
@@ -380,12 +404,15 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
}
|
||||
tag = 'refcircuit';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_REQUEST_TO_ENTER) {
|
||||
|
||||
aportador_solidario = await User.getAportadorSolidarioByUsername(idapp, sender);
|
||||
if (recnotif.extrarec.groupname) {
|
||||
newdescr = i18n.__('CIRCUIT_REQUEST_TO_ENTER_WITH_GROUP', recnotif.extrarec.groupname, recnotif.paramsObj.circuitnameDest,
|
||||
recnotif.paramsObj.singleadmin_username);
|
||||
} else {
|
||||
newdescr = i18n.__('CIRCUIT_REQUEST_TO_ENTER', sender, recnotif.paramsObj.circuitnameDest,
|
||||
recnotif.paramsObj.singleadmin_username);
|
||||
newdescr = i18n.__('CIRCUIT_REQUEST_TO_ENTER', sender, '<strong>' + recnotif.paramsObj.circuitnameDest + '</strong>', aportador_solidario);
|
||||
|
||||
newdescr += '\n' + i18n.__('CIRCUIT_WHERE_IS_PRESENT', await Circuit.getListCircuitsByUsername(recnotif.idapp, sender, recnotif.extrarec.groupname));
|
||||
}
|
||||
tag = 'reqcircuits';
|
||||
|
||||
@@ -394,7 +421,7 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
tag = 'deletecircuit';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_ADDED_ADMIN) {
|
||||
if (sender === recnotif.paramsObj.usernameDest) {
|
||||
newdescr = i18n.__('CIRCUIT_ADDED_ADMIN_YOU', recnotif.paramsObj.circuitnameDest, username_action);
|
||||
newdescr = i18n.__('CIRCUIT_ADDED_ADMIN_YOU', recnotif.paramsObj.usernameDest, recnotif.paramsObj.circuitnameDest, username_action);
|
||||
} else {
|
||||
newdescr = i18n.__('CIRCUIT_ADDED_ADMIN', sender, recnotif.paramsObj.circuitnameDest, username_action);
|
||||
recnotif.openUrl = '/my/' + sender;
|
||||
@@ -402,7 +429,7 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
tag = 'addadmingrp';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_REMOVED_ADMIN) {
|
||||
if (sender === recnotif.paramsObj.usernameDest) {
|
||||
newdescr = i18n.__('CIRCUIT_REMOVED_ADMIN_YOU', recnotif.paramsObj.circuitnameDest, username_action);
|
||||
newdescr = i18n.__('CIRCUIT_REMOVED_ADMIN_YOU', recnotif.paramsObj.usernameDest, recnotif.paramsObj.circuitnameDest, username_action);
|
||||
} else {
|
||||
newdescr = i18n.__('CIRCUIT_REMOVED_ADMIN', sender, recnotif.paramsObj.circuitnameDest, username_action);
|
||||
recnotif.openUrl = '/my/' + sender;
|
||||
@@ -614,10 +641,10 @@ sendNotifSchema.statics.updateStatusAndDescr = async function (myrecnotif, onlys
|
||||
let typeidsearch = 0;
|
||||
let dest = '';
|
||||
|
||||
let sender = myrecnotif.sender;
|
||||
let newdest = myrecnotif.dest;
|
||||
let sendergroup = myrecnotif.sendergroup;
|
||||
let newdestgroup = myrecnotif.destgroup;
|
||||
let sender = myrecnotif.sender ? myrecnotif.sender : '';
|
||||
let newdest = myrecnotif.dest ? myrecnotif.dest : '';
|
||||
let sendergroup = myrecnotif.sendergroup ? myrecnotif.sendergroup : '';
|
||||
let newdestgroup = myrecnotif.destgroup ? myrecnotif.destgroup : '';
|
||||
|
||||
// Controllare se devo modificare un Notif già esistente !
|
||||
if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FRIENDS) {
|
||||
|
||||
@@ -1530,7 +1530,7 @@ UserSchema.statics.getUserById = function (idapp, id) {
|
||||
UserSchema.statics.getUserByUsername = function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
return User.findne({
|
||||
return User.findOne({
|
||||
idapp,
|
||||
username,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
@@ -1900,13 +1900,65 @@ UserSchema.statics.removeFromMyGroups = async function (
|
||||
return await User.updateOne({ idapp, username },
|
||||
{ $pull: { 'profile.mygroups': { groupname: { $in: [groupnameDest] } } } });
|
||||
};
|
||||
// Rimuovo il Gruppo
|
||||
|
||||
// Rimuovo il Circuito
|
||||
UserSchema.statics.removeFromCircuits = async function (idapp, username, circuitname) {
|
||||
return await User.updateOne({ idapp, username },
|
||||
|
||||
// Elimina la richiesta (se esiste):
|
||||
update = { $pull: { req_users: { username: { $in: [username] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
|
||||
return await User.updateOne({ idapp, username },
|
||||
{ $pull: { 'profile.mycircuits': { circuitname: { $in: [circuitname] } } } });
|
||||
|
||||
};
|
||||
|
||||
// Aggiungo il Circuito
|
||||
UserSchema.statics.addCircuitToUser = async function (idapp, usernameOrig, circuitname, confido, groupname, contocom) {
|
||||
|
||||
let ris = null;
|
||||
|
||||
if (groupname) {
|
||||
|
||||
ris = await MyGroup.addCircuitFromGroup(idapp, groupname, circuitname);
|
||||
|
||||
// Elimina la richiesta:
|
||||
update = { $pull: { req_groups: { groupname: { $in: [groupname] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
|
||||
// Elimina eventualmente se era bloccato:
|
||||
update = { $pull: { refused_groups: { groupname: { $in: [groupname] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
|
||||
} else {
|
||||
|
||||
let update = {
|
||||
$push: {
|
||||
'profile.mycircuits': {
|
||||
circuitname,
|
||||
date: new Date(),
|
||||
},
|
||||
},
|
||||
};
|
||||
ris = await User.updateOne({ idapp, username: usernameOrig }, update);
|
||||
|
||||
if (confido) {
|
||||
// Elimina la richiesta:
|
||||
update = { $pull: { req_users: { username: { $in: [usernameOrig] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
}
|
||||
|
||||
// Elimina eventualmente se era bloccato:
|
||||
update = { $pull: { refused_users: { username: { $in: [usernameOrig] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
|
||||
}
|
||||
|
||||
await Account.createAccount(idapp, usernameOrig, circuitname, confido, groupname, contocom);
|
||||
|
||||
return ris;
|
||||
};
|
||||
|
||||
// Rimuovo il Gruppo per Tutti gli Utenti
|
||||
UserSchema.statics.removeAllUsersFromMyGroups = async function (idapp, groupnameDest) {
|
||||
return await User.updateMany({ idapp },
|
||||
@@ -2521,7 +2573,7 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
const mycirc = await Circuit.findOne({ idapp, name: circuitname });
|
||||
if (mycirc) {
|
||||
// Il Conto Comunitario prende il nome del circuito !
|
||||
await Account.createAccount(idapp, '', circuitname, '', mycirc.path);
|
||||
await Account.createAccount(idapp, '', circuitname, true, '', mycirc.path);
|
||||
}
|
||||
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.SET) {
|
||||
@@ -2529,18 +2581,7 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
const foundIfCircuitInGroup = await MyGroup.ifCircuitAlreadyInGroup(idapp, groupname, circuitname);
|
||||
|
||||
if (!foundIfCircuitInGroup) {
|
||||
ris = await MyGroup.addCircuitFromGroup(idapp, groupname, circuitname);
|
||||
|
||||
// Elimina la richiesta:
|
||||
update = { $pull: { req_groups: { groupname: { $in: [groupname] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
|
||||
// Elimina eventualmente se era bloccato:
|
||||
update = { $pull: { refused_groups: { groupname: { $in: [groupname] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
|
||||
await Account.createAccount(idapp, '', circuitname, groupname);
|
||||
|
||||
ris = await this.addCircuitToUser(idapp, usernameOrig, circuitname, true, groupname);
|
||||
|
||||
} else {
|
||||
ris = false;
|
||||
@@ -2552,7 +2593,6 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, value, true, username_action, extrarec);
|
||||
outres.result = await Circuit.getInfoCircuitByName(idapp, circuitname);
|
||||
}
|
||||
|
||||
} else {
|
||||
const foundIfAlreadyCircuit = await this.ifAlreadyInCircuit(idapp, usernameOrig, circuitname);
|
||||
|
||||
@@ -2567,10 +2607,6 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
};
|
||||
ris = await User.updateOne({ idapp, username: usernameOrig }, update);
|
||||
|
||||
// Elimina la richiesta:
|
||||
update = { $pull: { req_users: { username: { $in: [usernameOrig] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
|
||||
// Elimina eventualmente se era bloccato:
|
||||
update = { $pull: { refused_users: { username: { $in: [usernameOrig] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
@@ -2589,6 +2625,22 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
outres.result = await Circuit.getInfoCircuitByName(idapp, circuitname);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.SETFIDO) {
|
||||
|
||||
ris = await Circuit.setFido(idapp, usernameOrig, circuitname, groupname);
|
||||
|
||||
// Elimina la richiesta:
|
||||
update = { $pull: { req_users: { username: { $in: [usernameOrig] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
|
||||
await Circuit.updateData(idapp, circuitname)
|
||||
if (ris) {
|
||||
// Invia una notifica alla persona e agli Admin
|
||||
tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, value, true, username_action, extrarec);
|
||||
outres.result = await Circuit.getInfoCircuitByName(idapp, circuitname);
|
||||
}
|
||||
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REQ) {
|
||||
|
||||
if (groupname) {
|
||||
@@ -2628,7 +2680,7 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
}
|
||||
|
||||
} else {
|
||||
// Aggiungo la richiesta di Gruppo a me
|
||||
// Aggiungo la richiesta di Circuito a me
|
||||
const foundIfAlreadyAskCircuit = await Circuit.findOne({
|
||||
idapp,
|
||||
name: circuitname,
|
||||
@@ -2638,6 +2690,9 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
});
|
||||
|
||||
if (value) {
|
||||
// Aggiungi intanto l'utente al Circuito (senza fido)
|
||||
ris = await this.addCircuitToUser(idapp, usernameOrig, circuitname, false);
|
||||
|
||||
if (!foundIfAlreadyAskCircuit) {
|
||||
update = {
|
||||
$push: {
|
||||
@@ -2647,6 +2702,7 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
},
|
||||
},
|
||||
};
|
||||
// Aggiungi la richiesta per ottenere il fido
|
||||
ris = await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user