ver 0.5.51
This commit is contained in:
@@ -34,7 +34,9 @@
|
||||
"FRIEND_UNBLOCKED": "E' stato riattivato %s da %s.",
|
||||
"FRIEND_UNBLOCKED_YOU": "Hai riattivato %s.",
|
||||
"CIRCUIT_ACCEPT_NEWENTRY": "❇️👥 🧍♂️ Accetta Ingresso nel Circuito %s:",
|
||||
"CIRCUIT_ACCEPT_NEWENTRY_BYGROUP": "❇️👥 🧍♂️ Accetta Ingresso nel Circuito il gruppo %s:",
|
||||
"CIRCUIT_REQUEST_TO_ENTER": "%s ha chiesto di entrare nel circuito %s",
|
||||
"CIRCUIT_REQUEST_TO_ENTER_WITH_GROUP": "il gruppo %s ha chiesto di entrare nel circuito %s",
|
||||
"CIRCUIT_CREATED": "✅ %s ha creato un nuovo Circuito chiamato %s",
|
||||
"CIRCUIT_REQUEST": "Richiesta di entrare nel Circuito %s da parte di %s",
|
||||
"CIRCUIT_ADDED_ADMIN": "E' stato aggiunto %s come Amministratore del circuito %s da parte di %s",
|
||||
@@ -44,6 +46,7 @@
|
||||
"RICHIESTA_BLOCCO_CIRCUIT": "Richiesta di bloccare il Circuito %s da parte di %s",
|
||||
"CIRCUIT_ELIMINATO": "Il circuito %s è stato eliminato da parte di %s",
|
||||
"ACCETTATO_NOTIFICA_ADMINS_CIRCUIT": "✅ l'utente %s è stato accettato a far parte del Circuito %s (da parte di %s)",
|
||||
"ACCETTATO_NOTIFICA_ADMINS_CIRCUIT_MYGROUP": "✅ il gruppo %s è stato accettato a far parte del Circuito %s (da parte di %s)",
|
||||
"CIRCUIT_ACCEPTED": "✅ Sei stato accettato da %s a far parte del Circuito %s.\nApri la APP e clicca in alto a destra sull'icona delle monete, oppure clicca qui: %s",
|
||||
"CIRCUIT_ACCEPTED_YOU": "✅ Hai accettato %s a far parte del Circuito %s",
|
||||
"CIRCUIT_REFUSED": "❌ Ti è stato rifiutato l'accesso da %s a far parte del Circuito %s. Se pensi sia un'errore, contatta l'amministratore del Circuito.",
|
||||
|
||||
@@ -33,6 +33,9 @@ const AccountSchema = new Schema({
|
||||
username: {
|
||||
type: String,
|
||||
},
|
||||
groupname: { // For the Groups
|
||||
type: String,
|
||||
},
|
||||
circuitId: { // ----- REF TO Circuit
|
||||
type: String,
|
||||
},
|
||||
@@ -192,7 +195,7 @@ AccountSchema.pre('save', async function (next) {
|
||||
next();
|
||||
});
|
||||
|
||||
AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp, username, circuitId, createifnotexist) {
|
||||
AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp, username, circuitId, createifnotexist, groupname = '') {
|
||||
const Account = this;
|
||||
|
||||
try {
|
||||
@@ -203,11 +206,16 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp,
|
||||
return false;
|
||||
|
||||
let myquery = {
|
||||
'idapp': idapp,
|
||||
'username': username,
|
||||
idapp,
|
||||
circuitId,
|
||||
};
|
||||
|
||||
if (groupname) {
|
||||
myquery.groupname = groupname;
|
||||
} else {
|
||||
myquery.username = username;
|
||||
}
|
||||
|
||||
let mycircuit = await Circuit.getCircuitById(circuitId);
|
||||
|
||||
if (mycircuit) {
|
||||
@@ -218,14 +226,28 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp,
|
||||
_id: new ObjectID().toString(),
|
||||
idapp,
|
||||
username,
|
||||
groupname,
|
||||
circuitId: mycircuit._id,
|
||||
deperibile: false,
|
||||
fidoConcesso: mycircuit.fido_scoperto_default,
|
||||
qta_maxConcessa: mycircuit.qta_max_default,
|
||||
importo_iniziale: 0,
|
||||
saldo: 0,
|
||||
fidoConcesso: 0,
|
||||
qta_maxConcessa: 0,
|
||||
});
|
||||
|
||||
if (!mycircuit.fido_scoperto_default_grp)
|
||||
mycircuit.fido_scoperto_default_grp = shared_consts.CIRCUIT_PARAMS.SCOPERTO_MIN_GRP;
|
||||
if (!mycircuit.qta_max_default_grp)
|
||||
mycircuit.qta_max_default_grp = shared_consts.CIRCUIT_PARAMS.SCOPERTO_MAX_GRP;
|
||||
|
||||
if (groupname) {
|
||||
myaccount.fidoConcesso = mycircuit.fido_scoperto_default_grp;
|
||||
myaccount.qta_maxConcessa = mycircuit.qta_max_default_grp;
|
||||
} else {
|
||||
myaccount.fidoConcesso = mycircuit.fido_scoperto_default;
|
||||
myaccount.qta_maxConcessa = mycircuit.qta_max_default;
|
||||
}
|
||||
|
||||
return await myaccount.save();
|
||||
}
|
||||
|
||||
@@ -239,14 +261,14 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp,
|
||||
|
||||
};
|
||||
|
||||
AccountSchema.statics.createAccount = async function (idapp, username, circuitName) {
|
||||
AccountSchema.statics.createAccount = async function (idapp, username, circuitName, groupname = '') {
|
||||
|
||||
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);
|
||||
return await Account.getAccountByUsernameAndCircuitId(idapp, username, mycircuit._id, true, groupname);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -323,6 +345,97 @@ AccountSchema.statics.getUserAccounts = async function (idapp, username) {
|
||||
|
||||
};
|
||||
|
||||
AccountSchema.statics.getGroupAccounts = async function (idapp, groupname) {
|
||||
|
||||
try {
|
||||
let aggr1 = [
|
||||
{
|
||||
$match: { idapp, groupname },
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'circuits',
|
||||
localField: 'circuitId',
|
||||
foreignField: '_id',
|
||||
as: 'circuit',
|
||||
},
|
||||
},
|
||||
{ $unwind: '$circuit' },
|
||||
{
|
||||
$lookup: {
|
||||
from: 'sendnotifs',
|
||||
as: 'notifspending',
|
||||
let: {
|
||||
circuitname: '$circuit.name',
|
||||
groupname: '$groupname',
|
||||
idapp: '$idapp',
|
||||
typedir: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS,
|
||||
typeid: shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ,
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{ $eq: ['$typedir', '$$typedir'] },
|
||||
{ $eq: ['$typeid', '$$typeid'] },
|
||||
{ $eq: ['$status', 0] },
|
||||
{ $eq: ['$sender', '$$username'] },
|
||||
{ $eq: ['$idapp', '$$idapp'] },
|
||||
{ $eq: ['$extrarec.circuitname', '$$circuitname'] },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
ris = await this.aggregate(aggr1);
|
||||
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
|
||||
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);
|
||||
account.saldo -= saldopending;
|
||||
}
|
||||
}
|
||||
|
||||
return ris;
|
||||
} catch (e) {
|
||||
console.error('e', e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Aggiungi agli Admin del Account
|
||||
AccountSchema.statics.addToPeopleOfMyAccount = async function (idapp, username, circuitId, person_username, perm) {
|
||||
|
||||
return await Account.updateOne({ idapp, username, circuitId },
|
||||
{
|
||||
$push:
|
||||
{
|
||||
people: {
|
||||
username: person_username,
|
||||
perm,
|
||||
date: new Date(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
// Rimuovi dagli Admin del Account
|
||||
AccountSchema.statics.removeAdminOfAccount = async function (idapp, username, circuitId, person_username, perm) {
|
||||
|
||||
return await Circuit.updateOne({ idapp, username, circuitId },
|
||||
{ $pull: { people: { username: { $in: [person_username] } } } });
|
||||
};
|
||||
|
||||
|
||||
const Account = mongoose.model('Account', AccountSchema);
|
||||
|
||||
module.exports = { Account };
|
||||
|
||||
@@ -106,6 +106,12 @@ const CircuitSchema = new Schema({
|
||||
qta_max_default: {
|
||||
type: Number,
|
||||
},
|
||||
fido_scoperto_default_grp: {
|
||||
type: Number,
|
||||
},
|
||||
qta_max_default_grp: {
|
||||
type: Number,
|
||||
},
|
||||
data_costituz: {
|
||||
type: Date,
|
||||
},
|
||||
@@ -173,6 +179,18 @@ const CircuitSchema = new Schema({
|
||||
username: { type: String },
|
||||
date: { type: Date },
|
||||
}], // username
|
||||
req_groups: [
|
||||
{
|
||||
_id: false,
|
||||
groupname: { type: String },
|
||||
date: { type: Date },
|
||||
}], // username
|
||||
refused_groups: [
|
||||
{
|
||||
_id: false,
|
||||
groupname: { type: String },
|
||||
date: { type: Date },
|
||||
}], // username
|
||||
deleted: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
@@ -245,10 +263,12 @@ CircuitSchema.statics.getWhatToShow = function (idapp, username) {
|
||||
date_updated: 1,
|
||||
nome_valuta: 1,
|
||||
fido_scoperto_default: 1,
|
||||
qta_max_default: 1,
|
||||
fido_scoperto_default_grp: 1,
|
||||
qta_max_default_grp: 1,
|
||||
deperimento: 1,
|
||||
transactionsEnabled: 1,
|
||||
status: 1,
|
||||
qta_max_default: 1,
|
||||
valuta_per_euro: 1,
|
||||
symbol: 1,
|
||||
idCity: 1,
|
||||
@@ -261,6 +281,8 @@ CircuitSchema.statics.getWhatToShow = function (idapp, username) {
|
||||
admins: 1,
|
||||
req_users: 1,
|
||||
refused_users: 1,
|
||||
req_groups: 1,
|
||||
refused_groups: 1,
|
||||
'mycities': 1,
|
||||
};
|
||||
|
||||
@@ -304,6 +326,8 @@ CircuitSchema.statics.getWhatToShow_Unknown = function (idapp, username) {
|
||||
totCircolante: 1,
|
||||
totTransato: 1,
|
||||
fido_scoperto_default: 1,
|
||||
fido_scoperto_default_grp: 1,
|
||||
qta_max_default_grp: 1,
|
||||
qta_max_default: 1,
|
||||
valuta_per_euro: 1,
|
||||
symbol: 1,
|
||||
@@ -320,6 +344,8 @@ CircuitSchema.statics.getWhatToShow_Unknown = function (idapp, username) {
|
||||
date_updated: 1,
|
||||
req_users: 1,
|
||||
refused_users: 1,
|
||||
req_groups: 1,
|
||||
refused_groups: 1,
|
||||
transactionsEnabled: 1,
|
||||
status: 1,
|
||||
'mycities': 1,
|
||||
@@ -620,8 +646,8 @@ 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);
|
||||
const accountorigTable = await Account.getAccountByUsernameAndCircuitId(idapp, usernameOrig, circuittable._id, true);
|
||||
const accountdestTable = await Account.getAccountByUsernameAndCircuitId(idapp, extrarec.dest, circuittable._id, true, extrarec.groupdest);
|
||||
const accountorigTable = await Account.getAccountByUsernameAndCircuitId(idapp, usernameOrig, circuittable._id, true, extrarec.grouporig);
|
||||
|
||||
const circolantePrec = this.getCircolanteSingolaTransaz(accountorigTable, accountdestTable);
|
||||
|
||||
@@ -658,7 +684,7 @@ CircuitSchema.statics.sendCoins = async function (onlycheck, idapp, usernameOrig
|
||||
await Circuit.updateOne({ _id: circuittable }, { $set: paramstoupdate });
|
||||
|
||||
ris.result = true;
|
||||
console.log('Inviate Monete da', usernameOrig, extrarec.dest, myqty, extrarec.causal);
|
||||
console.log('Inviate Monete da', usernameOrig, extrarec.grouporig, extrarec.dest, extrarec.groupdest, myqty, extrarec.causal);
|
||||
|
||||
ris.useraccounts = await Account.getUserAccounts(idapp, usernameOrig);
|
||||
|
||||
@@ -666,7 +692,7 @@ CircuitSchema.statics.sendCoins = async function (onlycheck, idapp, usernameOrig
|
||||
extrarec.saldoDest = accountdestTable.saldo;
|
||||
|
||||
} else {
|
||||
console.log('NON Inviate Monete da', usernameOrig, extrarec.dest, myqty, extrarec.causal);
|
||||
console.log('NON Inviate Monete da', usernameOrig, extrarec.grouporig, extrarec.dest, extrarec.groupdest, myqty, extrarec.causal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -688,6 +714,13 @@ CircuitSchema.statics.removeReqCircuit = async function (idapp, username, name)
|
||||
{ $pull: { req_users: { username: { $in: [username] } } } });
|
||||
};
|
||||
|
||||
// Rimuovo la Richiesta del Gruppo sul Circuito
|
||||
CircuitSchema.statics.removeReqGroupCircuit = async function (idapp, groupname, name) {
|
||||
|
||||
return await Circuit.updateOne({ idapp, name },
|
||||
{ $pull: { req_groups: { groupname: { $in: [groupname] } } } });
|
||||
};
|
||||
|
||||
// Aggiungi agli utenti Rifiutati del Circuito
|
||||
|
||||
CircuitSchema.statics.refuseReqCircuit = async function (idapp, username, name) {
|
||||
@@ -705,6 +738,21 @@ CircuitSchema.statics.refuseReqCircuit = async function (idapp, username, name)
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.refuseReqGroupCircuit = async function (idapp, groupname, name) {
|
||||
|
||||
return await Circuit.updateOne({ idapp, name },
|
||||
{
|
||||
$push:
|
||||
{
|
||||
refused_groups: {
|
||||
groupname,
|
||||
date: new Date(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.updateData = async function (idapp, circuitname) {
|
||||
|
||||
try {
|
||||
|
||||
@@ -75,8 +75,9 @@ const MyGroupSchema = new Schema({
|
||||
},
|
||||
admins: [
|
||||
{
|
||||
username: {type: String},
|
||||
date: {type: Date},
|
||||
username: { type: String },
|
||||
perm: { type: Number },
|
||||
date: { type: Date },
|
||||
},
|
||||
],
|
||||
blocked: {
|
||||
@@ -97,34 +98,35 @@ const MyGroupSchema = new Schema({
|
||||
req_users: [
|
||||
{
|
||||
_id: false,
|
||||
username: {type: String},
|
||||
date: {type: Date},
|
||||
username: { type: String },
|
||||
date: { type: Date },
|
||||
}], // username
|
||||
refused_users: [
|
||||
{
|
||||
_id: false,
|
||||
username: {type: String},
|
||||
date: {type: Date},
|
||||
username: { type: String },
|
||||
date: { type: Date },
|
||||
}], // username
|
||||
deleted: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
circuits_list: [
|
||||
mycircuits: [
|
||||
{
|
||||
Num: { type: Number },
|
||||
inscription_date: {type: Date},
|
||||
_id: false,
|
||||
circuitname: { type: String },
|
||||
date: { type: Date },
|
||||
}],
|
||||
});
|
||||
|
||||
MyGroupSchema.statics.getFieldsForSearch = function() {
|
||||
return [{field: 'descr', type: tools.FieldType.string}];
|
||||
MyGroupSchema.statics.getFieldsForSearch = function () {
|
||||
return [{ field: 'descr', type: tools.FieldType.string }];
|
||||
};
|
||||
|
||||
MyGroupSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
MyGroupSchema.statics.executeQueryTable = function (idapp, params, user) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
|
||||
const {User} = require('./user');
|
||||
const { User } = require('./user');
|
||||
|
||||
if (params.options) {
|
||||
if (tools.isBitActive(params.options, shared_consts.OPTIONS_SEARCH_USER_ONLY_FULL_WORDS)) {
|
||||
@@ -137,9 +139,9 @@ MyGroupSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
return tools.executeQueryTable(this, idapp, params, user);
|
||||
};
|
||||
|
||||
MyGroupSchema.pre('save', async function(next) {
|
||||
MyGroupSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
const myrec = await MyGroup.findOne().limit(1).sort({_id: -1});
|
||||
const myrec = await MyGroup.findOne().limit(1).sort({ _id: -1 });
|
||||
if (!!myrec) {
|
||||
if (myrec._doc._id === 0)
|
||||
this._id = 1;
|
||||
@@ -156,35 +158,35 @@ MyGroupSchema.pre('save', async function(next) {
|
||||
next();
|
||||
});
|
||||
|
||||
MyGroupSchema.statics.findAllIdApp = async function(idapp) {
|
||||
const myfind = {idapp};
|
||||
MyGroupSchema.statics.findAllIdApp = async function (idapp) {
|
||||
const myfind = { idapp };
|
||||
|
||||
return await MyGroup.find(myfind);
|
||||
};
|
||||
|
||||
MyGroupSchema.statics.findAllGroups = async function(idapp) {
|
||||
MyGroupSchema.statics.findAllGroups = async function (idapp) {
|
||||
|
||||
const whatToShow = this.getWhatToShow(idapp, '');
|
||||
|
||||
return await MyGroup.find({
|
||||
idapp,
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
{deleted: {$exists: true, $eq: false}}],
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}, whatToShow);
|
||||
};
|
||||
|
||||
// Rimuovo la Richiesta del Gruppo
|
||||
MyGroupSchema.statics.removeReqGroup = async function(idapp, username, groupnameDest) {
|
||||
MyGroupSchema.statics.removeReqGroup = async function (idapp, username, groupnameDest) {
|
||||
|
||||
return await MyGroup.updateOne({idapp, groupname: groupnameDest},
|
||||
{$pull: {req_users: {username: {$in: [username]}}}});
|
||||
return await MyGroup.updateOne({ idapp, groupname: groupnameDest },
|
||||
{ $pull: { req_users: { username: { $in: [username] } } } });
|
||||
};
|
||||
|
||||
// Aggiungi agli utenti Rifiutati del Gruppo
|
||||
MyGroupSchema.statics.refuseReqGroup = async function(idapp, username, groupnameDest) {
|
||||
MyGroupSchema.statics.refuseReqGroup = async function (idapp, username, groupnameDest) {
|
||||
|
||||
return await MyGroup.updateOne({idapp, groupname: groupnameDest},
|
||||
return await MyGroup.updateOne({ idapp, groupname: groupnameDest },
|
||||
{
|
||||
$push:
|
||||
{
|
||||
@@ -198,9 +200,9 @@ MyGroupSchema.statics.refuseReqGroup = async function(idapp, username, groupname
|
||||
};
|
||||
|
||||
// Aggiungi agli Admin del Gruppo
|
||||
MyGroupSchema.statics.addToAdminOfMyGroup = async function(idapp, username, groupnameDest) {
|
||||
MyGroupSchema.statics.addToAdminOfMyGroup = async function (idapp, username, groupnameDest) {
|
||||
|
||||
return await MyGroup.updateOne({idapp, groupname: groupnameDest},
|
||||
return await MyGroup.updateOne({ idapp, groupname: groupnameDest },
|
||||
{
|
||||
$push:
|
||||
{
|
||||
@@ -214,13 +216,27 @@ MyGroupSchema.statics.addToAdminOfMyGroup = async function(idapp, username, grou
|
||||
};
|
||||
|
||||
// Rimuovi dagli Admin del Gruppo
|
||||
MyGroupSchema.statics.removeAdminOfMyGroup = async function(idapp, username, groupnameDest) {
|
||||
MyGroupSchema.statics.removeAdminOfMyGroup = async function (idapp, username, groupnameDest) {
|
||||
|
||||
return await MyGroup.updateOne({idapp, groupname: groupnameDest},
|
||||
{$pull: {admins: {username: {$in: [username]}}}});
|
||||
return await MyGroup.updateOne({ idapp, groupname: groupnameDest },
|
||||
{ $pull: { admins: { username: { $in: [username] } } } });
|
||||
};
|
||||
|
||||
MyGroupSchema.statics.getWhatToShow = function(idapp, username) {
|
||||
MyGroupSchema.statics.getListAdminsByGroupName = async function (idapp, groupname) {
|
||||
|
||||
let arr = await MyGroup.findOne({
|
||||
idapp,
|
||||
groupname,
|
||||
$or: [
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}, {admins: 1}).lean();
|
||||
|
||||
return arr && arr.admins ? arr.admins : [];
|
||||
|
||||
};
|
||||
|
||||
MyGroupSchema.statics.getWhatToShow = function (idapp, username) {
|
||||
// FOR ME, PERMIT ALL
|
||||
return {
|
||||
groupname: 1,
|
||||
@@ -242,12 +258,12 @@ MyGroupSchema.statics.getWhatToShow = function(idapp, username) {
|
||||
createdBy: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
circuits_list: 1,
|
||||
mycircuits: 1,
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
MyGroupSchema.statics.getWhatToShow_Unknown = function(idapp, username) {
|
||||
MyGroupSchema.statics.getWhatToShow_Unknown = function (idapp, username) {
|
||||
return {
|
||||
groupname: 1,
|
||||
title: 1,
|
||||
@@ -259,14 +275,14 @@ MyGroupSchema.statics.getWhatToShow_Unknown = function(idapp, username) {
|
||||
note: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
circuits_list: 1,
|
||||
mycircuits: 1,
|
||||
};
|
||||
};
|
||||
|
||||
MyGroupSchema.statics.getArrUsernameFromFieldByGroupname = async function(
|
||||
MyGroupSchema.statics.getArrUsernameFromFieldByGroupname = async function (
|
||||
idapp, groupname, field) {
|
||||
|
||||
const {User} = require('../models/user');
|
||||
const { User } = require('../models/user');
|
||||
|
||||
const myobj = {};
|
||||
myobj[field + '.' + subfield] = 1;
|
||||
@@ -274,7 +290,7 @@ MyGroupSchema.statics.getArrUsernameFromFieldByGroupname = async function(
|
||||
let arrrec = await User.findOne({
|
||||
idapp,
|
||||
groupname,
|
||||
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
}, myobj).then((ris) => ris ? ris._doc[field] : []);
|
||||
|
||||
if (arrrec.length > 0) {
|
||||
@@ -284,7 +300,7 @@ MyGroupSchema.statics.getArrUsernameFromFieldByGroupname = async function(
|
||||
|
||||
};
|
||||
|
||||
MyGroupSchema.statics.getInfoGroupByGroupname = async function(idapp, groupname) {
|
||||
MyGroupSchema.statics.getInfoGroupByGroupname = async function (idapp, groupname) {
|
||||
|
||||
const whatToShow = this.getWhatToShow(idapp, groupname);
|
||||
|
||||
@@ -294,13 +310,13 @@ MyGroupSchema.statics.getInfoGroupByGroupname = async function(idapp, groupname)
|
||||
};
|
||||
|
||||
const query = [
|
||||
{$match: myfind},
|
||||
{ $unwind: '$circuits_list' },
|
||||
{ $match: myfind },
|
||||
{ $unwind: '$mycircuits' },
|
||||
{
|
||||
$lookup: {
|
||||
from: 'circuits',
|
||||
localField: 'circuits_list.Num',
|
||||
foreignField: 'Num',
|
||||
localField: 'mycircuits.circuitname',
|
||||
foreignField: 'name',
|
||||
as: 'mycircuits',
|
||||
},
|
||||
},
|
||||
@@ -319,7 +335,7 @@ MyGroupSchema.statics.getInfoGroupByGroupname = async function(idapp, groupname)
|
||||
},
|
||||
},
|
||||
},
|
||||
{$project: whatToShow},
|
||||
{ $project: whatToShow },
|
||||
|
||||
];
|
||||
|
||||
@@ -336,15 +352,15 @@ MyGroupSchema.statics.getInfoGroupByGroupname = async function(idapp, groupname)
|
||||
|
||||
};
|
||||
|
||||
MyGroupSchema.statics.deleteGroup = async function(idapp, usernameOrig, groupname) {
|
||||
MyGroupSchema.statics.deleteGroup = async function (idapp, usernameOrig, groupname) {
|
||||
console.log('Gruppo ' + groupname + ' rimosso da ' + usernameOrig);
|
||||
return await MyGroup.findOneAndRemove({idapp, groupname});
|
||||
return await MyGroup.findOneAndRemove({ idapp, groupname });
|
||||
};
|
||||
|
||||
MyGroupSchema.statics.getGroupsByUsername = async function(idapp, username, req) {
|
||||
MyGroupSchema.statics.getGroupsByUsername = async function (idapp, username, req) {
|
||||
|
||||
try {
|
||||
const {User} = require('../models/user');
|
||||
const { User } = require('../models/user');
|
||||
|
||||
const whatToShow = this.getWhatToShow(idapp, username);
|
||||
const whatToShow_Unknown = this.getWhatToShow_Unknown(idapp, username);
|
||||
@@ -353,17 +369,17 @@ MyGroupSchema.statics.getGroupsByUsername = async function(idapp, username, req)
|
||||
|
||||
let listUsersGroup = await User.find({
|
||||
idapp,
|
||||
username: {$in: arrUsernameGroups},
|
||||
username: { $in: arrUsernameGroups },
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
{deleted: {$exists: true, $eq: false}}],
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}, whatToShow);
|
||||
|
||||
let listgroups = await MyGroup.find({
|
||||
idapp,
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
{deleted: {$exists: true, $eq: false}}],
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}, whatToShow_Unknown);
|
||||
|
||||
/*let listRequestUsersGroup = await User.find({
|
||||
@@ -379,21 +395,21 @@ MyGroupSchema.statics.getGroupsByUsername = async function(idapp, username, req)
|
||||
let listSentRequestGroups = await MyGroup.find({
|
||||
idapp,
|
||||
'req_users': {
|
||||
$elemMatch: {username: {$eq: username}},
|
||||
$elemMatch: { username: { $eq: username } },
|
||||
},
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
{deleted: {$exists: true, $eq: false}}],
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}, whatToShow_Unknown);
|
||||
|
||||
let listRefusedGroups = await MyGroup.find({
|
||||
idapp,
|
||||
'refused_users': {
|
||||
$elemMatch: {username: {$eq: username}},
|
||||
$elemMatch: { username: { $eq: username } },
|
||||
},
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
{deleted: {$exists: true, $eq: false}}],
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}, whatToShow_Unknown);
|
||||
|
||||
return {
|
||||
@@ -418,12 +434,12 @@ MyGroupSchema.statics.getGroupsByUsername = async function(idapp, username, req)
|
||||
};
|
||||
};
|
||||
|
||||
MyGroupSchema.statics.extractCitiesName = async function(idapp, id) {
|
||||
MyGroupSchema.statics.extractCitiesName = async function (idapp, id) {
|
||||
|
||||
try {
|
||||
let aggr1 = [
|
||||
{
|
||||
$match: {idapp, _id: id},
|
||||
$match: { idapp, _id: id },
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
@@ -459,13 +475,42 @@ MyGroupSchema.statics.extractCitiesName = async function(idapp, id) {
|
||||
ris = await this.aggregate(aggr1);
|
||||
|
||||
return ris;
|
||||
}catch (e) {
|
||||
} catch (e) {
|
||||
console.error('e', e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
MyGroupSchema.statics.ifCircuitAlreadyInGroup = async function (idapp, groupname, circuitname) {
|
||||
|
||||
// Controllo se è stato già inserito il circuito sul gruppo
|
||||
return await this.findOne({
|
||||
idapp,
|
||||
groupname,
|
||||
'mycircuits': {
|
||||
$elemMatch: { circuitname: { $eq: circuitname } },
|
||||
},
|
||||
}).lean();
|
||||
};
|
||||
|
||||
// aggiungo il Circuito all'interno del Gruppo
|
||||
MyGroupSchema.statics.addCircuitFromGroup = async function (idapp, groupname, circuitname) {
|
||||
return await this.updateOne({ idapp, groupname },
|
||||
{ $push: { 'mycircuits': {
|
||||
circuitname,
|
||||
date: new Date(),
|
||||
} } });
|
||||
|
||||
};
|
||||
|
||||
// Rimuovo il Circuito all'interno del Gruppo
|
||||
MyGroupSchema.statics.removeCircuitFromGroup = async function (idapp, groupname, circuitname) {
|
||||
return await this.updateOne({ idapp, groupname },
|
||||
{ $pull: { 'mycircuits': { circuitname: { $in: [circuitname] } } } });
|
||||
|
||||
};
|
||||
|
||||
|
||||
const MyGroup = mongoose.model('MyGroup', MyGroupSchema);
|
||||
|
||||
module.exports = {MyGroup};
|
||||
module.exports = { MyGroup };
|
||||
|
||||
@@ -6,7 +6,7 @@ mongoose.level = 'F';
|
||||
|
||||
const i18n = require('i18n');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
@@ -39,6 +39,14 @@ const sendNotifSchema = new Schema({
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
sendergroup: { // mittente
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
destgroup: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
@@ -90,7 +98,7 @@ const sendNotifSchema = new Schema({
|
||||
},
|
||||
});
|
||||
|
||||
sendNotifSchema.statics.setNotifAsRead = function(idapp, username, idnotif) {
|
||||
sendNotifSchema.statics.setNotifAsRead = function (idapp, username, idnotif) {
|
||||
const SendNotif = this;
|
||||
|
||||
try {
|
||||
@@ -98,15 +106,15 @@ sendNotifSchema.statics.setNotifAsRead = function(idapp, username, idnotif) {
|
||||
if (idnotif) {
|
||||
return SendNotif.findOneAndUpdate({
|
||||
$and: [
|
||||
{idapp},
|
||||
{dest: username},
|
||||
{'_id': idnotif},
|
||||
{ idapp },
|
||||
{ dest: username },
|
||||
{ '_id': idnotif },
|
||||
],
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
{deleted: {$exists: true, $eq: false}}],
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
|
||||
}, {$set: {read: true}}, {new: false}).then((ret) => {
|
||||
}, { $set: { read: true } }, { new: false }).then((ret) => {
|
||||
return !!ret;
|
||||
}).catch((err) => {
|
||||
console.error('err', err);
|
||||
@@ -117,7 +125,7 @@ sendNotifSchema.statics.setNotifAsRead = function(idapp, username, idnotif) {
|
||||
}
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.getRecNotif = function(id) {
|
||||
sendNotifSchema.statics.getRecNotif = function (id) {
|
||||
const SendNotif = this;
|
||||
|
||||
try {
|
||||
@@ -128,16 +136,16 @@ sendNotifSchema.statics.getRecNotif = function(id) {
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.findAllNotifByUsernameIdAndIdApp = function(username, lastdataread, idapp) {
|
||||
sendNotifSchema.statics.findAllNotifByUsernameIdAndIdApp = function (username, lastdataread, idapp) {
|
||||
const SendNotif = this;
|
||||
|
||||
return SendNotif.find({
|
||||
$and: [
|
||||
{idapp},
|
||||
{'dest': username},
|
||||
{'datenotif': {$gt: new Date(lastdataread)}},
|
||||
{ idapp },
|
||||
{ 'dest': username },
|
||||
{ 'datenotif': { $gt: new Date(lastdataread) } },
|
||||
],
|
||||
}).lean().sort({datenotif: -1}).then(async (arrnotif) => {
|
||||
}).lean().sort({ datenotif: -1 }).then(async (arrnotif) => {
|
||||
// console.log('arrnotif', arrnotif.length);
|
||||
|
||||
return this.compileOtherFields(arrnotif);
|
||||
@@ -148,7 +156,7 @@ sendNotifSchema.statics.findAllNotifByUsernameIdAndIdApp = function(username, la
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function(recnotif) {
|
||||
sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif) {
|
||||
|
||||
const numchars = 80;
|
||||
let newdescr = '';
|
||||
@@ -275,8 +283,14 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function(recnotif) {
|
||||
newdescr = i18n.__('CIRCUIT_CREATED', userorig, recnotif.paramsObj.circuitnameDest);
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_ACCEPTED) {
|
||||
if (recnotif.paramsObj.isAdmin) {
|
||||
if (recnotif.extrarec.groupname) {
|
||||
newdescr = i18n.__('ACCETTATO_NOTIFICA_ADMINS_CIRCUIT_MYGROUP', recnotif.extrarec.groupname, recnotif.paramsObj.circuitnameDest,
|
||||
recnotif.paramsObj.username_action);
|
||||
} else {
|
||||
newdescr = i18n.__('ACCETTATO_NOTIFICA_ADMINS_CIRCUIT', userorig, recnotif.paramsObj.circuitnameDest,
|
||||
recnotif.paramsObj.username_action);
|
||||
}
|
||||
|
||||
recnotif.openUrl = '/my/' + userorig;
|
||||
} else {
|
||||
if (userorig === recnotif.paramsObj.usernameDest) {
|
||||
@@ -307,8 +321,13 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function(recnotif) {
|
||||
}
|
||||
tag = 'refcircuit';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_REQUEST_TO_ENTER) {
|
||||
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', userorig, recnotif.paramsObj.circuitnameDest,
|
||||
recnotif.paramsObj.singleadmin_username);
|
||||
}
|
||||
tag = 'reqcircuits';
|
||||
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_DELETE_USER) {
|
||||
@@ -336,8 +355,10 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function(recnotif) {
|
||||
tag = 'sendcoin';
|
||||
recnotif.openUrl = '/circuit/' + recnotif.paramsObj.path; //++Todo: dove lo mando ?
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ_SENT) {
|
||||
let mydest = recnotif.paramsObj.extrarec.groupdest ? recnotif.paramsObj.extrarec.groupdest : recnotif.paramsObj.extrarec.dest;
|
||||
|
||||
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ_TO_ME', recnotif.paramsObj.extrarec.qty.toString(),
|
||||
recnotif.paramsObj.extrarec.symbol, recnotif.paramsObj.extrarec.dest);
|
||||
recnotif.paramsObj.extrarec.symbol, mydest);
|
||||
tag = 'sendcoin';
|
||||
recnotif.openUrl = '/circuit/' + recnotif.paramsObj.path; //++Todo: dove lo mando ?
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_ACCEPTED) {
|
||||
@@ -359,7 +380,7 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function(recnotif) {
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_REFUSED_SENT) {
|
||||
newdescr = i18n.__('ID_CIRCUIT_COINS_REFUSED_TO_ME', recnotif.paramsObj.extrarec.qty.toString(), recnotif.paramsObj.extrarec.symbol,
|
||||
recnotif.paramsObj.extrarec.dest);
|
||||
tag = 'sendcoin';ac
|
||||
tag = 'sendcoin'; ac
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,14 +398,14 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function(recnotif) {
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.compileOtherFields = async function(arrnotif) {
|
||||
sendNotifSchema.statics.compileOtherFields = async function (arrnotif) {
|
||||
|
||||
const {User} = require('../models/user');
|
||||
const { User } = require('../models/user');
|
||||
|
||||
try {
|
||||
// Fill in the image profile of the semyinders !
|
||||
for (const notif of arrnotif) {
|
||||
let myimgprofile = await User.findOne({idapp: notif.idapp, username: notif.sender}, {'profile.img': 1}).lean();
|
||||
let myimgprofile = await User.findOne({ idapp: notif.idapp, username: notif.sender }, { 'profile.img': 1 }).lean();
|
||||
if (myimgprofile && myimgprofile.profile.img)
|
||||
notif.myimgsender = 'upload/profile/' + notif.sender + '/' + myimgprofile.profile.img;
|
||||
}
|
||||
@@ -398,7 +419,7 @@ sendNotifSchema.statics.compileOtherFields = async function(arrnotif) {
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.findLastNotifsByUserIdAndIdApp = function(username, idapp, limit) {
|
||||
sendNotifSchema.statics.findLastNotifsByUserIdAndIdApp = function (username, idapp, limit) {
|
||||
const SendNotif = this;
|
||||
|
||||
return SendNotif.aggregate([
|
||||
@@ -408,9 +429,9 @@ sendNotifSchema.statics.findLastNotifsByUserIdAndIdApp = function(username, idap
|
||||
dest: username,
|
||||
},
|
||||
},
|
||||
{$limit: limit},
|
||||
{ $limit: limit },
|
||||
{
|
||||
$sort: {datenotif: -1},
|
||||
$sort: { datenotif: -1 },
|
||||
},
|
||||
]).then(async (arrnotif) => {
|
||||
return this.compileOtherFields(arrnotif);
|
||||
@@ -421,14 +442,16 @@ sendNotifSchema.statics.findLastNotifsByUserIdAndIdApp = function(username, idap
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.saveAndSendNotif = async function(myrecnotif, req, res, user) {
|
||||
sendNotifSchema.statics.saveAndSendNotif = async function (myrecnotif, req, res, user) {
|
||||
const SendNotif = this;
|
||||
|
||||
let idapp = req.body.idapp;
|
||||
const check = tools.checkUserOk(myrecnotif.sender, user ? myrecnotif.sender : req.user.username, res);
|
||||
let check = tools.checkUserOk(myrecnotif.sender, user ? myrecnotif.sender : req.user.username, res);
|
||||
if (!check)
|
||||
check = tools.checkUserOk(myrecnotif.sendergroup, user ? myrecnotif.sendergroup : req.user.username, res);
|
||||
if (check.exit) return check.ret;
|
||||
|
||||
const {myrecout, save} = await SendNotif.updateStatusAndDescr(myrecnotif, false);
|
||||
const { myrecout, save } = await SendNotif.updateStatusAndDescr(myrecnotif, false);
|
||||
if (!myrecout)
|
||||
return null;
|
||||
|
||||
@@ -458,7 +481,7 @@ sendNotifSchema.statics.saveAndSendNotif = async function(myrecnotif, req, res,
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysave) {
|
||||
sendNotifSchema.statics.updateStatusAndDescr = async function (myrecnotif, onlysave) {
|
||||
const SendNotif = this;
|
||||
|
||||
try {
|
||||
@@ -474,6 +497,8 @@ sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysa
|
||||
|
||||
let sender = myrecnotif.sender;
|
||||
let newdest = myrecnotif.dest;
|
||||
let sendergroup = myrecnotif.sendergroup;
|
||||
let newdestgroup = myrecnotif.destgroup;
|
||||
|
||||
// Controllare se devo modificare un Notif già esistente !
|
||||
if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FRIENDS) {
|
||||
@@ -550,6 +575,8 @@ sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysa
|
||||
datenotif: new Date(),
|
||||
sender,
|
||||
dest: newdest,
|
||||
sendergroup,
|
||||
destgroup: newdestgroup,
|
||||
};
|
||||
|
||||
let query = {
|
||||
@@ -569,13 +596,13 @@ sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysa
|
||||
}
|
||||
|
||||
// Cerca il record e se lo trova lo aggiorna
|
||||
const myrec = await SendNotif.findOneAndUpdate(query, {$set: fields_to_update}, {
|
||||
const myrec = await SendNotif.findOneAndUpdate(query, { $set: fields_to_update }, {
|
||||
new: true,
|
||||
returnNewDocument: true,
|
||||
});
|
||||
|
||||
if (myrec) {
|
||||
return {myrecout: myrec, save: false};
|
||||
return { myrecout: myrec, save: false };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -584,19 +611,19 @@ sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysa
|
||||
myrecnotif.status = newstatus;
|
||||
}
|
||||
|
||||
return {myrecout: myrecnotif, save: true};
|
||||
return { myrecout: myrecnotif, save: true };
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return {myrecout: null, save: false};
|
||||
return { myrecout: null, save: false };
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.getStatus = async function(notifId) {
|
||||
sendNotifSchema.statics.getStatus = async function (notifId) {
|
||||
const SendNotif = this;
|
||||
|
||||
try {
|
||||
return await SendNotif.findOne({_id: notifId}, {status: 1}).lean().then((rec) => rec.status);
|
||||
return await SendNotif.findOne({ _id: notifId }, { status: 1 }).lean().then((rec) => rec.status);
|
||||
|
||||
} catch (e) {
|
||||
return 0;
|
||||
@@ -604,7 +631,7 @@ sendNotifSchema.statics.getStatus = async function(notifId) {
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.checkIfCoinsAlreadySent = async function(notifId) {
|
||||
sendNotifSchema.statics.checkIfCoinsAlreadySent = async function (notifId) {
|
||||
const SendNotif = this;
|
||||
|
||||
try {
|
||||
@@ -624,11 +651,11 @@ sendNotifSchema.statics.checkIfCoinsAlreadySent = async function(notifId) {
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.saveNotif = async function(myrecnotif) {
|
||||
sendNotifSchema.statics.saveNotif = async function (myrecnotif) {
|
||||
|
||||
const SendNotif = this;
|
||||
|
||||
const {myrecout, save} = await SendNotif.updateStatusAndDescr(myrecnotif, true);
|
||||
const { myrecout, save } = await SendNotif.updateStatusAndDescr(myrecnotif, true);
|
||||
if (!myrecout)
|
||||
return null;
|
||||
|
||||
@@ -644,14 +671,16 @@ sendNotifSchema.statics.saveNotif = async function(myrecnotif) {
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.getDefaultRec = function(req) {
|
||||
sendNotifSchema.statics.getDefaultRec = function (req) {
|
||||
|
||||
return {
|
||||
idapp: req.body.idapp,
|
||||
typedir: '',
|
||||
typeid: '',
|
||||
sender: req.user ? req.user.username : '',
|
||||
sendergroup: '',
|
||||
dest: '',
|
||||
destgroup: '',
|
||||
descr: '',
|
||||
openUrl: '',
|
||||
datenotif: new Date(),
|
||||
@@ -663,7 +692,7 @@ sendNotifSchema.statics.getDefaultRec = function(req) {
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.getExtraParam = function(myrecnotif, paramsObj) {
|
||||
sendNotifSchema.statics.getExtraParam = function (myrecnotif, paramsObj) {
|
||||
let out = myrecnotif;
|
||||
//if (myrecnotif._doc) {
|
||||
//out = myrecnotif._doc
|
||||
@@ -681,7 +710,7 @@ sendNotifSchema.statics.getExtraParam = function(myrecnotif, paramsObj) {
|
||||
return myrecnotif;
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.createNewNotification = async function(req, res, paramsObj, table, rec, typedir, typeid) {
|
||||
sendNotifSchema.statics.createNewNotification = async function (req, res, paramsObj, table, rec, typedir, typeid) {
|
||||
const SendNotif = this;
|
||||
|
||||
try {
|
||||
@@ -705,7 +734,7 @@ sendNotifSchema.statics.createNewNotification = async function(req, res, paramsO
|
||||
}
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.createNewNotifToSingleUser = async function(req, res, paramsObj, onlysave, typedir, typeid) {
|
||||
sendNotifSchema.statics.createNewNotifToSingleUser = async function (req, res, paramsObj, onlysave, typedir, typeid) {
|
||||
const SendNotif = this;
|
||||
|
||||
try {
|
||||
@@ -723,13 +752,13 @@ sendNotifSchema.statics.createNewNotifToSingleUser = async function(req, res, pa
|
||||
}
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotifpass, req, res) {
|
||||
sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass, req, res) {
|
||||
const SendNotif = this;
|
||||
|
||||
const {User} = require('../models/user');
|
||||
const { User } = require('../models/user');
|
||||
|
||||
const {City} = require('../models/city');
|
||||
const {Province} = require('../models/province');
|
||||
const { City } = require('../models/city');
|
||||
const { Province } = require('../models/province');
|
||||
|
||||
try {
|
||||
|
||||
@@ -737,8 +766,8 @@ sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotifpass, r
|
||||
const userlist = await User.find({
|
||||
idapp: myrecnotifpass.idapp,
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
{deleted: {$exists: true, $eq: false}}],
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}, {
|
||||
name: 1,
|
||||
surname: 1,
|
||||
@@ -762,7 +791,7 @@ sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotifpass, r
|
||||
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotifpass.tablerec) ||
|
||||
shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
|
||||
|
||||
const myrectableorig = await mytable.findOne({_id: myrecnotifpass.idrec}).lean();
|
||||
const myrectableorig = await mytable.findOne({ _id: myrecnotifpass.idrec }).lean();
|
||||
if (myrectableorig) {
|
||||
for (const city of myrectableorig.idCity) {
|
||||
arrprovinces.push(await City.getProvinceByIdCity(city));
|
||||
@@ -836,7 +865,7 @@ sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotifpass, r
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.sendToSingleUserDest = async function(myrecnotif, req, res, onlysave) {
|
||||
sendNotifSchema.statics.sendToSingleUserDest = async function (myrecnotif, req, res, onlysave) {
|
||||
const SendNotif = this;
|
||||
|
||||
try {
|
||||
@@ -859,13 +888,14 @@ sendNotifSchema.statics.sendToSingleUserDest = async function(myrecnotif, req, r
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.getSumPendingTransactions = async function(idapp, username, circuitname) {
|
||||
sendNotifSchema.statics.getSumPendingTransactions = async function (idapp, username, circuitname, groupname) {
|
||||
const SendNotif = this;
|
||||
|
||||
try {
|
||||
const query = {
|
||||
idapp,
|
||||
sender: username,
|
||||
sendergroup: groupname,
|
||||
typedir: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS,
|
||||
typeid: shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ,
|
||||
status: 0,
|
||||
@@ -882,4 +912,4 @@ sendNotifSchema.statics.getSumPendingTransactions = async function(idapp, userna
|
||||
|
||||
const SendNotif = mongoose.model('SendNotif', sendNotifSchema);
|
||||
|
||||
module.exports = {SendNotif: SendNotif};
|
||||
module.exports = { SendNotif: SendNotif };
|
||||
|
||||
@@ -70,7 +70,7 @@ const UserSchema = new mongoose.Schema({
|
||||
type: String,
|
||||
required: true,
|
||||
trim: true,
|
||||
minlength: 6,
|
||||
minlength: 3,
|
||||
unique: false,
|
||||
},
|
||||
name: {
|
||||
@@ -421,8 +421,7 @@ const UserSchema = new mongoose.Schema({
|
||||
type: Number,
|
||||
}],
|
||||
},
|
||||
})
|
||||
;
|
||||
});
|
||||
|
||||
UserSchema.methods.toJSON = function () {
|
||||
const user = this;
|
||||
@@ -2270,8 +2269,40 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
result: false,
|
||||
};
|
||||
let update = {};
|
||||
|
||||
let groupname = extrarec && extrarec.groupname ? extrarec.groupname : '';
|
||||
|
||||
try {
|
||||
if (cmd === shared_consts.CIRCUITCMD.SET) {
|
||||
if (groupname) {
|
||||
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);
|
||||
|
||||
|
||||
} else {
|
||||
ris = false;
|
||||
}
|
||||
|
||||
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 {
|
||||
const foundIfAlreadyCircuit = await this.ifAlreadyInCircuit(idapp, usernameOrig, circuitname);
|
||||
|
||||
if (!foundIfAlreadyCircuit) {
|
||||
@@ -2306,7 +2337,46 @@ 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 if (cmd === shared_consts.CIRCUITCMD.REQ) {
|
||||
|
||||
if (groupname) {
|
||||
// Aggiungo la richiesta di Gruppo a me
|
||||
const foundIfAlreadyAskCircuit = await Circuit.findOne({
|
||||
idapp,
|
||||
name: circuitname,
|
||||
'req_groups': {
|
||||
$elemMatch: { groupname: { $eq: groupname } },
|
||||
},
|
||||
});
|
||||
|
||||
if (value) {
|
||||
if (!foundIfAlreadyAskCircuit) {
|
||||
update = {
|
||||
$push: {
|
||||
'req_groups': {
|
||||
groupname,
|
||||
date: new Date(),
|
||||
},
|
||||
},
|
||||
};
|
||||
ris = await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
|
||||
}
|
||||
if (ris) {
|
||||
// Invia una notifica alla persona
|
||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, true, true, username_action, extrarec);
|
||||
}
|
||||
} else {
|
||||
if (foundIfAlreadyAskCircuit) {
|
||||
outres.result = await MyGroup.removeCircuitFromGroup(idapp, groupname, circuitname); // Rimuovo il Circuito dal gruppo
|
||||
|
||||
// Invia una notifica alla persona
|
||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Aggiungo la richiesta di Gruppo a me
|
||||
const foundIfAlreadyAskCircuit = await Circuit.findOne({
|
||||
idapp,
|
||||
@@ -2342,6 +2412,9 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REMOVE_FROM_MYLIST) {
|
||||
|
||||
// Remove if is also an Admin
|
||||
@@ -2368,16 +2441,24 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.CANCEL_REQ) {
|
||||
|
||||
if (groupname)
|
||||
outres.result = await Circuit.removeReqGroupCircuit(idapp, groupname, circuitname); // Rimuovo l'Amicizia da me
|
||||
else
|
||||
outres.result = await Circuit.removeReqCircuit(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
||||
|
||||
await Circuit.updateData(idapp, circuitname)
|
||||
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REFUSE_REQ) {
|
||||
|
||||
if (groupname) {
|
||||
outres.result = await MyGroup.removeCircuitFromGroup(idapp, groupname, circuitname); // Rimuovo l'Amicizia da me
|
||||
outres.result = await Circuit.removeReqGroupCircuit(idapp, groupname, circuitname); // Rimuovo l'Amicizia da me
|
||||
outres.result = await Circuit.refuseReqGroupCircuit(idapp, groupname, circuitname); // Rimuovo l'Amicizia da me
|
||||
} else {
|
||||
outres.result = await this.removeFromCircuits(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
||||
|
||||
outres.result = await Circuit.removeReqCircuit(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
||||
|
||||
outres.result = await Circuit.refuseReqCircuit(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
||||
}
|
||||
|
||||
// Invia una notifica alla persona
|
||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||
@@ -2438,6 +2519,7 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT && outcheck.cansend) {
|
||||
if (!await Movement.checkIfCoinsAlreadySent(extrarec.notifId)) {
|
||||
outres = await Circuit.sendCoins(false, idapp, usernameOrig, extrarec);
|
||||
|
||||
} else {
|
||||
outcheck.cansend = false; //GIA INVIATO
|
||||
}
|
||||
@@ -2446,6 +2528,10 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
if (outcheck.cansend) {
|
||||
// Invia una notifica di moneta (accettata o rifiutata) alla persona
|
||||
const out = await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||
|
||||
if (outres && extrarec.groupname) {
|
||||
// Setta agli altri admin,
|
||||
}
|
||||
}
|
||||
|
||||
outres.recnotif = await SendNotif.getRecNotif(extrarec.notifId);
|
||||
@@ -2466,6 +2552,7 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
outres.userprofile = userprofile;
|
||||
}
|
||||
outres.listcircuits = await Circuit.findAllIdApp(idapp);
|
||||
outres.mygroups = await MyGroup.findAllGroups(idapp);
|
||||
}
|
||||
|
||||
if (circuitname)
|
||||
@@ -3299,7 +3386,7 @@ UserSchema.statics.getUsersRegistered = async function (idapp) {
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
};
|
||||
|
||||
return await User. countDocuments(myfind);
|
||||
return await User.countDocuments(myfind);
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsersRegisteredToday = async function (idapp) {
|
||||
@@ -3314,7 +3401,7 @@ UserSchema.statics.getUsersRegisteredToday = async function (idapp) {
|
||||
date_reg: { $gt: starttoday },
|
||||
};
|
||||
|
||||
return await User. countDocuments(myfind);
|
||||
return await User.countDocuments(myfind);
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsersOnLineToday = async function (idapp) {
|
||||
@@ -3329,7 +3416,7 @@ UserSchema.statics.getUsersOnLineToday = async function (idapp) {
|
||||
lasttimeonline: { $gt: starttoday },
|
||||
};
|
||||
|
||||
return await User. countDocuments(myfind);
|
||||
return await User.countDocuments(myfind);
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -3398,7 +3485,7 @@ UserSchema.statics.getEmailNotVerified = async function (idapp) {
|
||||
verified_email: false,
|
||||
};
|
||||
|
||||
return await User. countDocuments(myfind);
|
||||
return await User.countDocuments(myfind);
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsersTelegramAttivo = async function (idapp) {
|
||||
@@ -3410,7 +3497,7 @@ UserSchema.statics.getUsersTelegramAttivo = async function (idapp) {
|
||||
'profile.teleg_id': { $gt: 0 },
|
||||
};
|
||||
|
||||
return await User. countDocuments(myfind);
|
||||
return await User.countDocuments(myfind);
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsersAutorizzati = async function (idapp) {
|
||||
@@ -3423,7 +3510,7 @@ UserSchema.statics.getUsersAutorizzati = async function (idapp) {
|
||||
verified_by_aportador: true,
|
||||
};
|
||||
|
||||
return await User. countDocuments(myfind);
|
||||
return await User.countDocuments(myfind);
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsersAutorizzare = async function (idapp) {
|
||||
@@ -3436,7 +3523,7 @@ UserSchema.statics.getUsersAutorizzare = async function (idapp) {
|
||||
verified_by_aportador: { $exists: false },
|
||||
};
|
||||
|
||||
return await User. countDocuments(myfind);
|
||||
return await User.countDocuments(myfind);
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsersTelegramPending = async function (idapp) {
|
||||
@@ -3448,7 +3535,7 @@ UserSchema.statics.getUsersTelegramPending = async function (idapp) {
|
||||
'profile.teleg_checkcode': { $gt: 0 },
|
||||
};
|
||||
|
||||
return await User. countDocuments(myfind);
|
||||
return await User.countDocuments(myfind);
|
||||
};
|
||||
|
||||
UserSchema.statics.getNumUsers = async function (idapp) {
|
||||
@@ -3459,7 +3546,7 @@ UserSchema.statics.getNumUsers = async function (idapp) {
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
};
|
||||
|
||||
return await User. countDocuments(myfind);
|
||||
return await User.countDocuments(myfind);
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsersZoom = async function (idapp) {
|
||||
@@ -3471,7 +3558,7 @@ UserSchema.statics.getUsersZoom = async function (idapp) {
|
||||
'profile.saw_zoom_presentation': true,
|
||||
};
|
||||
|
||||
return await User. countDocuments(myfind);
|
||||
return await User.countDocuments(myfind);
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsersResidenti = async function (idapp) {
|
||||
@@ -3495,7 +3582,7 @@ UserSchema.statics.getSaw_and_Accepted = async function (idapp) {
|
||||
'profile.saw_and_accepted': shared_consts.ALL_SAW_AND_ACCEPTED,
|
||||
};
|
||||
|
||||
return await User. countDocuments(myfind);
|
||||
return await User.countDocuments(myfind);
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsersDreams = async function (idapp) {
|
||||
@@ -3508,7 +3595,7 @@ UserSchema.statics.getUsersDreams = async function (idapp) {
|
||||
'$expr': { '$gt': [{ '$strLenCP': '$profile.my_dream' }, 10] },
|
||||
};
|
||||
|
||||
return await User. countDocuments(myfind);
|
||||
return await User.countDocuments(myfind);
|
||||
};
|
||||
|
||||
UserSchema.statics.getLastUsers = async function (idapp) {
|
||||
|
||||
@@ -10,11 +10,11 @@ const appTelegramDest = [tools.FREEPLANET, tools.FREEPLANET, tools.FREEPLANET];
|
||||
|
||||
const printf = require('util').format;
|
||||
|
||||
const {User} = require('../models/user');
|
||||
const {MyGroup} = require('../models/mygroup');
|
||||
const {Circuit} = require('../models/circuit');
|
||||
const {CalZoom} = require('../models/calzoom');
|
||||
const {MyBot} = require('../models/bot');
|
||||
const { User } = require('../models/user');
|
||||
const { MyGroup } = require('../models/mygroup');
|
||||
const { Circuit } = require('../models/circuit');
|
||||
const { CalZoom } = require('../models/calzoom');
|
||||
const { MyBot } = require('../models/bot');
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const sharp = require('sharp');
|
||||
@@ -22,7 +22,7 @@ const sharp = require('sharp');
|
||||
const server_constants = require('../tools/server_constants');
|
||||
|
||||
// const {ListaIngresso} = require('../models/listaingresso');
|
||||
const {MsgTemplate} = require('../models/msg_template');
|
||||
const { MsgTemplate } = require('../models/msg_template');
|
||||
|
||||
const globalTables = require('../tools/globalTables');
|
||||
|
||||
@@ -399,12 +399,12 @@ const MenuLang = {
|
||||
};
|
||||
|
||||
const MenuYesNo = {
|
||||
it: {menu: [[Menu.it.SI, Menu.it.NO]]},
|
||||
es: {menu: [[Menu.es.SI, Menu.es.NO]]},
|
||||
fr: {menu: [[Menu.fr.SI, Menu.fr.NO]]},
|
||||
si: {menu: [[Menu.si.SI, Menu.si.NO]]},
|
||||
pt: {menu: [[Menu.pt.SI, Menu.pt.NO]]},
|
||||
enUs: {menu: [[Menu.enUs.SI, Menu.enUs.NO]]},
|
||||
it: { menu: [[Menu.it.SI, Menu.it.NO]] },
|
||||
es: { menu: [[Menu.es.SI, Menu.es.NO]] },
|
||||
fr: { menu: [[Menu.fr.SI, Menu.fr.NO]] },
|
||||
si: { menu: [[Menu.si.SI, Menu.si.NO]] },
|
||||
pt: { menu: [[Menu.pt.SI, Menu.pt.NO]] },
|
||||
enUs: { menu: [[Menu.enUs.SI, Menu.enUs.NO]] },
|
||||
};
|
||||
|
||||
const MenuAdmin = {
|
||||
@@ -424,12 +424,12 @@ const MenuSend = {
|
||||
};
|
||||
|
||||
const MenuChat = {
|
||||
it: {menu: [[Menu.it.ESCI_DA_CHAT, Menu.it.INDIETRO]]},
|
||||
es: {menu: [[Menu.es.ESCI_DA_CHAT, Menu.es.INDIETRO]]},
|
||||
fr: {menu: [[Menu.fr.ESCI_DA_CHAT, Menu.fr.INDIETRO]]},
|
||||
si: {menu: [[Menu.si.ESCI_DA_CHAT, Menu.si.INDIETRO]]},
|
||||
pt: {menu: [[Menu.pt.ESCI_DA_CHAT, Menu.pt.INDIETRO]]},
|
||||
enUs: {menu: [[Menu.enUs.ESCI_DA_CHAT, Menu.enUs.INDIETRO]]},
|
||||
it: { menu: [[Menu.it.ESCI_DA_CHAT, Menu.it.INDIETRO]] },
|
||||
es: { menu: [[Menu.es.ESCI_DA_CHAT, Menu.es.INDIETRO]] },
|
||||
fr: { menu: [[Menu.fr.ESCI_DA_CHAT, Menu.fr.INDIETRO]] },
|
||||
si: { menu: [[Menu.si.ESCI_DA_CHAT, Menu.si.INDIETRO]] },
|
||||
pt: { menu: [[Menu.pt.ESCI_DA_CHAT, Menu.pt.INDIETRO]] },
|
||||
enUs: { menu: [[Menu.enUs.ESCI_DA_CHAT, Menu.enUs.INDIETRO]] },
|
||||
};
|
||||
|
||||
const Sex = {
|
||||
@@ -701,11 +701,11 @@ const MyTelegramBot = {
|
||||
ISCRIZIONE_ARCADEI: 4,
|
||||
},
|
||||
|
||||
getAppTelegram: function() {
|
||||
getAppTelegram: function () {
|
||||
return appTelegram;
|
||||
},
|
||||
|
||||
local_sendMsgTelegramByIdTelegram: async function(idapp, idtelegram, text,
|
||||
local_sendMsgTelegramByIdTelegram: async function (idapp, idtelegram, text,
|
||||
message_id, chat_id, ripr_menuPrec,
|
||||
MyForm = null) {
|
||||
|
||||
@@ -721,7 +721,7 @@ const MyTelegramBot = {
|
||||
|
||||
},
|
||||
|
||||
deleteRecInMemByUsername: function(idapp, username_bo) {
|
||||
deleteRecInMemByUsername: function (idapp, username_bo) {
|
||||
|
||||
const cl = getclTelegByidapp(idapp);
|
||||
if (cl) {
|
||||
@@ -730,7 +730,7 @@ const MyTelegramBot = {
|
||||
}
|
||||
},
|
||||
|
||||
getFormDaMostrare: function(idapp, myfunc, myuser) {
|
||||
getFormDaMostrare: function (idapp, myfunc, myuser) {
|
||||
|
||||
let FormDaMostrare = null;
|
||||
|
||||
@@ -757,11 +757,11 @@ const MyTelegramBot = {
|
||||
return FormDaMostrare;
|
||||
},
|
||||
|
||||
getCiao: function(idapp, username, lang) {
|
||||
getCiao: function (idapp, username, lang) {
|
||||
return tools.gettranslate('CIAO', lang) + ' ' + username + '!\n';
|
||||
},
|
||||
|
||||
notifyToTelegram: async function(phase, mylocalsconf) {
|
||||
notifyToTelegram: async function (phase, mylocalsconf) {
|
||||
let userdest = mylocalsconf.user.aportador_solidario;
|
||||
let langdest = mylocalsconf.user.lang;
|
||||
let NameFrom = `${mylocalsconf.user.name} ${mylocalsconf.user.surname}`;
|
||||
@@ -808,7 +808,7 @@ const MyTelegramBot = {
|
||||
|
||||
},
|
||||
|
||||
notifyIscrizioneToTelegram: async function(phase, mylocalsconf, msg) {
|
||||
notifyIscrizioneToTelegram: async function (phase, mylocalsconf, msg) {
|
||||
let langdest = mylocalsconf.iscritto.lang;
|
||||
let NameFrom = `${mylocalsconf.iscritto.name} ${mylocalsconf.iscritto.surname}`;
|
||||
|
||||
@@ -821,7 +821,7 @@ const MyTelegramBot = {
|
||||
await this.sendMsgTelegramToTheManagers(mylocalsconf.idapp, addtext + text);
|
||||
},
|
||||
|
||||
askConfirmationUser: async function(idapp, myfunc, myuser, userDest = '', groupname = '', groupid = '', regexpire = '') {
|
||||
askConfirmationUser: async function (idapp, myfunc, myuser, userDest = '', name = '', groupid = '', regexpire = '', groupname = '') {
|
||||
|
||||
try {
|
||||
const cl = getclTelegByidapp(idapp);
|
||||
@@ -878,7 +878,7 @@ const MyTelegramBot = {
|
||||
}
|
||||
} else if (myfunc === shared_consts.CallFunz.RICHIESTA_GRUPPO) {
|
||||
|
||||
domanda = printf(getstr(langdest, 'MSG_ACCEPT_NEWENTRY_INGROUP'), groupname) + '<br>' + struserinfomsg;
|
||||
domanda = printf(getstr(langdest, 'MSG_ACCEPT_NEWENTRY_INGROUP'), name) + '<br>' + struserinfomsg;
|
||||
|
||||
keyb = cl.getInlineKeyboard(myuser.lang, [
|
||||
{
|
||||
@@ -892,7 +892,23 @@ const MyTelegramBot = {
|
||||
]);
|
||||
} else if (myfunc === shared_consts.CallFunz.RICHIESTA_CIRCUIT) {
|
||||
|
||||
domanda = i18n.__({phrase: 'CIRCUIT_ACCEPT_NEWENTRY', locale: langdest}, groupname) + '<br>' + struserinfomsg;
|
||||
if (groupname) {
|
||||
domanda = i18n.__({ phrase: 'CIRCUIT_ACCEPT_NEWENTRY_BYGROUP', locale: langdest }, groupname) + '<br>' + struserinfomsg;
|
||||
|
||||
keyb = cl.getInlineKeyboard(myuser.lang, [
|
||||
{
|
||||
text: '✅ Accetta ' + groupname,
|
||||
callback_data: InlineConferma.RISPOSTA_SI + myfunc + tools.SEP + myuser.username + tools.SEP + '' + tools.SEP + '' + tools.SEP +
|
||||
groupid + tools.SEP + groupname,
|
||||
},
|
||||
{
|
||||
text: '🚫 Rifiuta ' + groupname,
|
||||
callback_data: InlineConferma.RISPOSTA_NO + myfunc + tools.SEP + myuser.username + tools.SEP + '' + tools.SEP + '' + tools.SEP +
|
||||
groupid + tools.SEP + groupname,
|
||||
},
|
||||
]);
|
||||
} else {
|
||||
domanda = i18n.__({ phrase: 'CIRCUIT_ACCEPT_NEWENTRY', locale: langdest }, name) + '<br>' + struserinfomsg;
|
||||
|
||||
keyb = cl.getInlineKeyboard(myuser.lang, [
|
||||
{
|
||||
@@ -907,6 +923,7 @@ const MyTelegramBot = {
|
||||
},
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Invia Msg
|
||||
if (domanda) {
|
||||
@@ -920,14 +937,14 @@ const MyTelegramBot = {
|
||||
|
||||
},
|
||||
|
||||
askConfirmationUserFriend: async function(idapp, myfunc, myuser, userDest = '', username = '') {
|
||||
askConfirmationUserFriend: async function (idapp, myfunc, myuser, userDest = '', username = '') {
|
||||
|
||||
try {
|
||||
const cl = getclTelegByidapp(idapp);
|
||||
if (!cl)
|
||||
return false;
|
||||
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
|
||||
const langdest = myuser.lang;
|
||||
|
||||
@@ -944,7 +961,7 @@ const MyTelegramBot = {
|
||||
sendnotif = true;
|
||||
typedir = shared_consts.TypeNotifs.TYPEDIR_FRIENDS;
|
||||
typeid = shared_consts.TypeNotifs.ID_FRIENDS_NEW_REC;
|
||||
paramsObj = {usernameDest: userDest};
|
||||
paramsObj = { usernameDest: userDest };
|
||||
|
||||
domanda = printf(tools.gettranslate('RICHIESTA_AMICIZIA', langdest), myuser.username) + '<br>' + struserinfomsg;
|
||||
|
||||
@@ -978,7 +995,7 @@ const MyTelegramBot = {
|
||||
|
||||
},
|
||||
|
||||
sendMsgTelegramToTheManagers: async function(
|
||||
sendMsgTelegramToTheManagers: async function (
|
||||
idapp, text, onlyintofile = false, MyForm = null, nottousername = '') {
|
||||
|
||||
tools.writeManagersLog(text);
|
||||
@@ -1000,7 +1017,7 @@ const MyTelegramBot = {
|
||||
|
||||
},
|
||||
|
||||
sendMsgTelegramToTheManagersAndZoomeri: async function(
|
||||
sendMsgTelegramToTheManagersAndZoomeri: async function (
|
||||
idapp, text, onlyintofile, MyForm = null) {
|
||||
|
||||
tools.writeManagersLog(text);
|
||||
@@ -1019,9 +1036,9 @@ const MyTelegramBot = {
|
||||
return true;
|
||||
|
||||
},
|
||||
getMsgByTipoMsg: async function(mydata, lang, user, sonosognatore) {
|
||||
getMsgByTipoMsg: async function (mydata, lang, user, sonosognatore) {
|
||||
if (!!mydata.msgextra) {
|
||||
return {body: mydata.msgextra, title: ''};
|
||||
return { body: mydata.msgextra, title: '' };
|
||||
}
|
||||
|
||||
let title = '';
|
||||
@@ -1086,17 +1103,17 @@ const MyTelegramBot = {
|
||||
Math.ceil(mydata.flotta.col_ultima / 8));
|
||||
}
|
||||
|
||||
return {body: msg, title};
|
||||
return { body: msg, title };
|
||||
},
|
||||
|
||||
sendMsgTelegramToTheAdminAllSites: async function(text, senzaintestazione) {
|
||||
sendMsgTelegramToTheAdminAllSites: async function (text, senzaintestazione) {
|
||||
for (const idapp of this.getAppTelegram()) {
|
||||
text = text.replace('{appname}', tools.getNomeAppByIdApp(idapp));
|
||||
await this.sendMsgTelegramToTheAdmin(idapp, text, senzaintestazione);
|
||||
}
|
||||
},
|
||||
|
||||
sendMsgTelegramToTheAdmin: async function(idapp, text, senzaintestazione) {
|
||||
sendMsgTelegramToTheAdmin: async function (idapp, text, senzaintestazione) {
|
||||
const usersmanagers = await User.getusersManagers(idapp);
|
||||
|
||||
let intestaz = emo.ROBOT_FACE + '[BOT-ADMIN]' + emo.ADMIN + ': ';
|
||||
@@ -1116,7 +1133,7 @@ const MyTelegramBot = {
|
||||
|
||||
},
|
||||
|
||||
sendMsgTelegramToALL: async function(idapp, text) {
|
||||
sendMsgTelegramToALL: async function (idapp, text) {
|
||||
const usersall = await User.getUsersTelegALL(idapp);
|
||||
|
||||
if (usersall) {
|
||||
@@ -1128,9 +1145,9 @@ const MyTelegramBot = {
|
||||
|
||||
},
|
||||
|
||||
sendMsgTelegram: async function(
|
||||
sendMsgTelegram: async function (
|
||||
idapp, username, text, alsotomanagers = false, username_mitt = '') {
|
||||
const {User} = require('../models/user');
|
||||
const { User } = require('../models/user');
|
||||
|
||||
const teleg_id = await User.TelegIdByUsername(idapp, username);
|
||||
const cl = getclTelegByidapp(idapp);
|
||||
@@ -1154,7 +1171,7 @@ const MyTelegramBot = {
|
||||
return ris;
|
||||
},
|
||||
|
||||
sendMsgTelegramByIdTelegram: async function(
|
||||
sendMsgTelegramByIdTelegram: async function (
|
||||
idapp, idtelegram, text, message_id, chat_id, ripr_menuPrec,
|
||||
MyForm = null) {
|
||||
|
||||
@@ -1173,7 +1190,7 @@ const MyTelegramBot = {
|
||||
|
||||
},
|
||||
|
||||
reloadMenuBot: async function(idapp) {
|
||||
reloadMenuBot: async function (idapp) {
|
||||
|
||||
const cl = getclTelegByidapp(idapp);
|
||||
if (cl) {
|
||||
@@ -1182,13 +1199,13 @@ const MyTelegramBot = {
|
||||
|
||||
},
|
||||
|
||||
reloadSites: async function() {
|
||||
reloadSites: async function () {
|
||||
|
||||
tools.loadApps();
|
||||
|
||||
},
|
||||
|
||||
sendMsgFromSite: async function(idapp, user, params) {
|
||||
sendMsgFromSite: async function (idapp, user, params) {
|
||||
|
||||
try {
|
||||
let ris = {
|
||||
@@ -1232,7 +1249,7 @@ const MyTelegramBot = {
|
||||
}
|
||||
},
|
||||
|
||||
sendMsgFromSiteToBotTelegram: async function(idapp, user, params) {
|
||||
sendMsgFromSiteToBotTelegram: async function (idapp, user, params) {
|
||||
|
||||
if (!params.typesend) {
|
||||
params.typesend = shared_consts.TypeSend.TELEGRAM;
|
||||
@@ -2508,7 +2525,7 @@ class Telegram {
|
||||
ok = true;
|
||||
}
|
||||
|
||||
return {rec, user, myid, ok};
|
||||
return { rec, user, myid, ok };
|
||||
}
|
||||
|
||||
async setUsernameBo(msg) {
|
||||
@@ -2666,7 +2683,7 @@ class Telegram {
|
||||
msg.from.username || '', msg.from.first_name || '',
|
||||
msg.from.last_name || '');
|
||||
|
||||
} catch (e) {}
|
||||
} catch (e) { }
|
||||
// let ris = await this.getUser(msg, rec, false);
|
||||
|
||||
rec.status = Status.VERIFIED;
|
||||
@@ -2992,7 +3009,7 @@ class Telegram {
|
||||
invitante = arrparams[1];
|
||||
regexpire = arrparams[3];
|
||||
}
|
||||
return {invitante, regexpire};
|
||||
return { invitante, regexpire };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3339,7 +3356,7 @@ class Telegram {
|
||||
if (true) {
|
||||
lang = rec.lang;
|
||||
if (!arrlang[rec.lang])
|
||||
arrlang[rec.lang] = {menu: []};
|
||||
arrlang[rec.lang] = { menu: [] };
|
||||
|
||||
if (riga !== rec.riga) {
|
||||
if (arrtemp.length > 0)
|
||||
@@ -3646,11 +3663,11 @@ class Telegram {
|
||||
let myfileprofile = tools.getdirByIdApp(idapp, true) +
|
||||
server_constants.DIR_UPLOAD + '/profile/' + username + '/';
|
||||
let user_profile = bot.getUserProfilePhotos(telegid);
|
||||
user_profile.then(function(res) {
|
||||
user_profile.then(function (res) {
|
||||
if (res.photos[0]) {
|
||||
var file_id = res.photos[0][2].file_id;
|
||||
var file = bot.getFile(file_id);
|
||||
file.then(function(result) {
|
||||
file.then(function (result) {
|
||||
|
||||
const file_path = result.file_path;
|
||||
const photo_url = 'https://api.telegram.org/file/bot' + token +
|
||||
@@ -3671,7 +3688,7 @@ class Telegram {
|
||||
// SMALL
|
||||
|
||||
// questa opzione 'failOnError' serve per risolvere l'errore (Error: VipsJpeg: Invalid SOS parameters for sequential JPEG
|
||||
sharp(myfileprofile, {failOnError: false}).
|
||||
sharp(myfileprofile, { failOnError: false }).
|
||||
resize(64, 64).
|
||||
withMetadata().
|
||||
toFile(resized_img_small);
|
||||
@@ -3832,7 +3849,7 @@ if (true) {
|
||||
|
||||
if (!!token) {
|
||||
console.log('*** START BOT ' + nomebot);
|
||||
const bot = new TelegramBot(token, {polling: true});
|
||||
const bot = new TelegramBot(token, { polling: true });
|
||||
|
||||
if (url === '0') {
|
||||
const ngrok = require('ngrok');
|
||||
@@ -3843,7 +3860,7 @@ if (true) {
|
||||
});
|
||||
}
|
||||
|
||||
arrTelegram.push({idapp, cl: new Telegram(idapp, bot)});
|
||||
arrTelegram.push({ idapp, cl: new Telegram(idapp, bot) });
|
||||
|
||||
bot.onText(/\/start/, (msg) => {
|
||||
const myclTelegram = getclTelegBytoken(bot.token);
|
||||
@@ -3889,6 +3906,7 @@ if (true) {
|
||||
userDest: '',
|
||||
groupId: 0,
|
||||
circuitId: '',
|
||||
groupname: '',
|
||||
};
|
||||
|
||||
const datastr = callbackQuery.data;
|
||||
@@ -3901,6 +3919,7 @@ if (true) {
|
||||
userDest: dataarr[2] ? dataarr[2] : '',
|
||||
groupId: dataarr[3] ? parseInt(dataarr[3]) : '',
|
||||
circuitId: dataarr[4] ? dataarr[4] : '',
|
||||
groupname: dataarr[5] ? dataarr[5] : '',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -3925,10 +3944,10 @@ if (true) {
|
||||
let group = null;
|
||||
let circuit = null;
|
||||
if (data.groupId) {
|
||||
group = await MyGroup.findOne({idapp, _id: data.groupId}).lean();
|
||||
group = await MyGroup.findOne({ idapp, _id: data.groupId }).lean();
|
||||
}
|
||||
if (data.circuitId) {
|
||||
circuit = await Circuit.findOne({idapp, _id: data.circuitId}).lean();
|
||||
circuit = await Circuit.findOne({ idapp, _id: data.circuitId }).lean();
|
||||
}
|
||||
|
||||
let cmd = 0;
|
||||
@@ -4022,23 +4041,31 @@ if (true) {
|
||||
|
||||
if (circuit) {
|
||||
cmd = shared_consts.CIRCUITCMD.SET;
|
||||
const foundIfAlreadyCircuit = await User.ifAlreadyInCircuit(user.idapp, data.username, circuit.name);
|
||||
|
||||
let foundIfAlreadyCircuit = false;
|
||||
if (data.groupname) {
|
||||
foundIfAlreadyCircuit = await MyGroup.ifCircuitAlreadyInGroup(user.idapp, data.groupname, circuit.name);
|
||||
} else {
|
||||
foundIfAlreadyCircuit = await User.ifAlreadyInCircuit(user.idapp, data.username, circuit.name);
|
||||
}
|
||||
if (!foundIfAlreadyCircuit) {
|
||||
// Aggiungilo nel Circuito
|
||||
await User.setCircuitCmd(user.idapp, data.username, circuit.name, cmd, 0, username_action);
|
||||
await User.setCircuitCmd(user.idapp, data.username, circuit.name, cmd, 0, username_action, {groupname: data.groupname});
|
||||
}
|
||||
|
||||
}
|
||||
} else if (data.action === InlineConferma.RISPOSTA_NO + shared_consts.CallFunz.RICHIESTA_CIRCUIT) {
|
||||
|
||||
if (circuit) {
|
||||
cmd = shared_consts.CIRCUITCMD.REFUSE_REQ;
|
||||
const foundIfAlreadyCircuit = await User.ifAlreadyInCircuit(user.idapp, data.username, circuit.name);
|
||||
let foundIfAlreadyCircuit = false;
|
||||
if (data.groupname) {
|
||||
foundIfAlreadyCircuit = await MyGroup.ifCircuitAlreadyInGroup(user.idapp, data.groupname, circuit.name);
|
||||
} else {
|
||||
foundIfAlreadyCircuit = await User.ifAlreadyInCircuit(user.idapp, data.username, circuit.name);
|
||||
}
|
||||
|
||||
if (foundIfAlreadyCircuit) {
|
||||
// Rimuovilo nel Circuito
|
||||
await User.setCircuitCmd(user.idapp, data.username, circuit.name, cmd, 0, username_action);
|
||||
await User.setCircuitCmd(user.idapp, data.username, circuit.name, cmd, 0, username_action, {groupname: data.groupname});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ const CryptoJS = require('crypto-js');
|
||||
|
||||
const Url = require('url-parse');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
const { ObjectID, ObjectId } = require('mongodb');
|
||||
|
||||
const shared_consts = require('./shared_nodejs');
|
||||
|
||||
@@ -836,8 +836,10 @@ module.exports = {
|
||||
}).catch(async (err) => {
|
||||
console.error('err Push', err.body);
|
||||
|
||||
if (err.body) {
|
||||
// Cancella dal DB la notifica Push, visto che da errore! (sarà scaduto)
|
||||
const ris = await Subscription.deleteOne({ _id: subscription._id });
|
||||
}
|
||||
|
||||
reject({
|
||||
status: false,
|
||||
@@ -1020,6 +1022,7 @@ module.exports = {
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
const { User } = require('../models/user');
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
const { MyGroup } = require('../models/mygroup');
|
||||
|
||||
const req = this.getReqByPar(idapp, usernameOrig);
|
||||
|
||||
@@ -1065,7 +1068,7 @@ module.exports = {
|
||||
// paramsObj.options = MessageOptions.Notify_OnlyToNotifinApp + MessageOptions.Notify_ByBotTelegram;
|
||||
const myuserdata = await User.getUserShortDataByUsername(idapp, username_action);
|
||||
telegrambot.askConfirmationUser(idapp, shared_consts.CallFunz.RICHIESTA_CIRCUIT, myuserdata, usernameDest, circuitname,
|
||||
myreccircuit._id);
|
||||
myreccircuit._id, '', extrarec.groupname);
|
||||
onlysave = false;
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.ADDADMIN) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_ADDED_ADMIN;
|
||||
@@ -1074,6 +1077,8 @@ module.exports = {
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REQ) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ;
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REQ_SENT) {
|
||||
// Crea l'ID di Transazione
|
||||
paramsObj.idTransaction = new ObjectId();
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ_SENT;
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_COINS_ACCEPTED;
|
||||
@@ -1088,10 +1093,27 @@ module.exports = {
|
||||
}
|
||||
|
||||
if (sendnotif && typeid > 0) {
|
||||
// Check if is group:
|
||||
if (extrarec.groupdest) {
|
||||
|
||||
let arrusers = await MyGroup.getListAdminsByGroupName(idapp, extrarec.groupdest);
|
||||
|
||||
let ris = null;
|
||||
|
||||
for (let i = 0; i < arrusers.length; i++) {
|
||||
paramsObj.usernameDest = arrusers[i].username;
|
||||
ris = await SendNotif.createNewNotifToSingleUser(req, null, paramsObj, onlysave, typedir, typeid);
|
||||
if (!ris) {
|
||||
console.error('Errore createNewNotifToSingleUser! ', paramsObj.usernameDest, "dest ->", extrarec.groupdest)
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
||||
return await SendNotif.createNewNotifToSingleUser(req, null, paramsObj, onlysave, typedir, typeid);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
@@ -1297,7 +1319,7 @@ module.exports = {
|
||||
this.mylog('checkUserOk', userpassed, userauth);
|
||||
if (String(userpassed) !== String(userauth)) {
|
||||
// I'm trying to write something not mine!
|
||||
this.mylog('userId = ', userpassed, 'req.user._id', userauth);
|
||||
this.mylog('I\'m trying to write something not mine!: userId = ', userpassed, 'req.user._id', userauth);
|
||||
if (!res) {
|
||||
return {
|
||||
exit: true,
|
||||
@@ -1580,7 +1602,7 @@ module.exports = {
|
||||
{
|
||||
$and:
|
||||
[
|
||||
{ $eq: ['$'+params.lk_FF, '$$'+params.lk_FF] },
|
||||
{ $eq: ['$' + params.lk_FF, '$$' + params.lk_FF] },
|
||||
{ $eq: ['$idapp', '$$idapp'] },
|
||||
],
|
||||
},
|
||||
|
||||
@@ -440,6 +440,10 @@ module.exports = {
|
||||
|
||||
replaceUsername: async function (idapp, search_username, replace_username) {
|
||||
|
||||
if (!search_username || !replace_username) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
let ris = null;
|
||||
console.log('replaceUsername = ', search_username, replace_username);
|
||||
@@ -447,6 +451,10 @@ module.exports = {
|
||||
ris = await User.findOneAndUpdate({ idapp, username: search_username }, { $set: { username: replace_username } });
|
||||
console.log('username result = ', ris);
|
||||
|
||||
tools.move(server_constants.DIR_UPLOAD + 'profile/' + search_username, server_constants.DIR_UPLOAD + 'profile/' + replace_username, function callback() {
|
||||
console.log(' ... moved dir', server_constants.DIR_UPLOAD + 'profile/' + search_username, server_constants.DIR_UPLOAD + 'profile/' + replace_username);
|
||||
});
|
||||
|
||||
ris = await User.findOneAndUpdate({ idapp, 'profile.username_telegram': search_username }, { $set: { 'profile.username_telegram': replace_username } });
|
||||
console.log('profile.username_telegram result = ', ris);
|
||||
|
||||
|
||||
@@ -501,4 +501,9 @@ module.exports = {
|
||||
FASE3_MONETA_ABILITATA: 3,
|
||||
},
|
||||
|
||||
CIRCUIT_PARAMS: {
|
||||
SCOPERTO_MIN_GRP: 200,
|
||||
SCOPERTO_MAX_GRP: 500,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user