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,71 +158,85 @@ 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:
|
||||
{
|
||||
$push:
|
||||
{
|
||||
refused_users: {
|
||||
username,
|
||||
date: new Date(),
|
||||
},
|
||||
},
|
||||
});
|
||||
refused_users: {
|
||||
username,
|
||||
date: new Date(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
// 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:
|
||||
{
|
||||
$push:
|
||||
{
|
||||
admins: {
|
||||
username,
|
||||
date: new Date(),
|
||||
},
|
||||
},
|
||||
});
|
||||
admins: {
|
||||
username,
|
||||
date: new Date(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
// 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(
|
||||
idapp, groupname, field) {
|
||||
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) {
|
||||
newdescr = i18n.__('ACCETTATO_NOTIFICA_ADMINS_CIRCUIT', userorig, recnotif.paramsObj.circuitnameDest,
|
||||
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) {
|
||||
newdescr = i18n.__('CIRCUIT_REQUEST_TO_ENTER', userorig, recnotif.paramsObj.circuitnameDest,
|
||||
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) {
|
||||
@@ -332,34 +351,36 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function(recnotif) {
|
||||
tag = 'removeadmincircuit';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ) {
|
||||
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ', tools.getAhref(recnotif.paramsObj.username_action, await tools.getLinkUserTelegram(recnotif.idapp, recnotif.paramsObj.username_action)), recnotif.paramsObj.extrarec.qty.toString(),
|
||||
recnotif.paramsObj.extrarec.symbol);
|
||||
recnotif.paramsObj.extrarec.symbol);
|
||||
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) {
|
||||
newdescr = i18n.__('ID_CIRCUIT_COINS_ACCEPTED', recnotif.paramsObj.extrarec.qty.toString(), recnotif.paramsObj.extrarec.symbol,
|
||||
recnotif.paramsObj.username_action) + `\n` + i18n.__('SALDO_UPDATE', recnotif.paramsObj.extrarec.saldoDest,
|
||||
recnotif.paramsObj.username_action) + `\n` + i18n.__('SALDO_UPDATE', recnotif.paramsObj.extrarec.saldoDest,
|
||||
recnotif.paramsObj.extrarec.symbol
|
||||
);
|
||||
);
|
||||
tag = 'sendcoin';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_ACCEPTED_SENT) {
|
||||
newdescr = i18n.__('ID_CIRCUIT_COINS_ACCEPTED_TO_ME', recnotif.paramsObj.extrarec.qty.toString(),
|
||||
recnotif.paramsObj.extrarec.symbol,
|
||||
recnotif.paramsObj.extrarec.dest) + `\n` + i18n.__('SALDO_UPDATE', recnotif.paramsObj.extrarec.saldoOrig,
|
||||
recnotif.paramsObj.extrarec.symbol,
|
||||
recnotif.paramsObj.extrarec.dest) + `\n` + i18n.__('SALDO_UPDATE', recnotif.paramsObj.extrarec.saldoOrig,
|
||||
recnotif.paramsObj.extrarec.symbol);
|
||||
tag = 'sendcoin';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_REFUSED) {
|
||||
newdescr = i18n.__('ID_CIRCUIT_COINS_REFUSED', recnotif.paramsObj.extrarec.qty.toString(), recnotif.paramsObj.extrarec.symbol,
|
||||
recnotif.paramsObj.username_action);
|
||||
recnotif.paramsObj.username_action);
|
||||
tag = 'sendcoin';
|
||||
} 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
|
||||
recnotif.paramsObj.extrarec.dest);
|
||||
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 {
|
||||
@@ -612,7 +639,7 @@ sendNotifSchema.statics.checkIfCoinsAlreadySent = async function(notifId) {
|
||||
|
||||
if (status !== null) {
|
||||
return (status === shared_consts.CircuitsNotif.STATUS_COINS_ACCEPTED) ||
|
||||
(status === shared_consts.CircuitsNotif.STATUS_COINS_REFUSED);
|
||||
(status === shared_consts.CircuitsNotif.STATUS_COINS_REFUSED);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -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,
|
||||
@@ -760,9 +789,9 @@ sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotifpass, r
|
||||
const mytable = globalTables.getTableByTableName(myrecnotifpass.tablerec);
|
||||
|
||||
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotifpass.tablerec) ||
|
||||
shared_consts.TABLES_EVENTS_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));
|
||||
@@ -790,16 +819,16 @@ sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotifpass, r
|
||||
let send = false;
|
||||
|
||||
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotifpass.tablerec) ||
|
||||
shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
|
||||
shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
|
||||
// Estrai la Città, la Provincia e la regione.
|
||||
|
||||
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_PROVINCE) &&
|
||||
user.profile.notif_provinces && user.profile.notif_provinces.some(r => arrprovinces.indexOf(r) >= 0)) {
|
||||
user.profile.notif_provinces && user.profile.notif_provinces.some(r => arrprovinces.indexOf(r) >= 0)) {
|
||||
send = true;
|
||||
}
|
||||
|
||||
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_REGION) &&
|
||||
user.profile.notif_regions && user.profile.notif_regions.some(r => arrregions.indexOf(r) >= 0)) {
|
||||
user.profile.notif_regions && user.profile.notif_regions.some(r => arrregions.indexOf(r) >= 0)) {
|
||||
send = true;
|
||||
}
|
||||
|
||||
@@ -836,15 +865,15 @@ 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 {
|
||||
|
||||
myrecnotif.dest = myrecnotif.paramsObj && myrecnotif.paramsObj.usernameDest ? myrecnotif.paramsObj.usernameDest : '';
|
||||
myrecnotif.username_worked = myrecnotif.paramsObj && myrecnotif.paramsObj.username_worked
|
||||
? myrecnotif.paramsObj.username_worked
|
||||
: myrecnotif.dest;
|
||||
? myrecnotif.paramsObj.username_worked
|
||||
: myrecnotif.dest;
|
||||
|
||||
if (onlysave) {
|
||||
return await SendNotif.saveNotif(myrecnotif);
|
||||
@@ -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,77 +2269,151 @@ 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) {
|
||||
const foundIfAlreadyCircuit = await this.ifAlreadyInCircuit(idapp, usernameOrig, circuitname);
|
||||
if (groupname) {
|
||||
const foundIfCircuitInGroup = await MyGroup.ifCircuitAlreadyInGroup(idapp, groupname, circuitname);
|
||||
|
||||
if (!foundIfAlreadyCircuit) {
|
||||
update = {
|
||||
$push: {
|
||||
'profile.mycircuits': {
|
||||
circuitname,
|
||||
date: new Date(),
|
||||
},
|
||||
},
|
||||
};
|
||||
ris = await User.updateOne({ idapp, username: usernameOrig }, update);
|
||||
if (!foundIfCircuitInGroup) {
|
||||
ris = await MyGroup.addCircuitFromGroup(idapp, groupname, circuitname);
|
||||
|
||||
// Elimina la richiesta:
|
||||
update = { $pull: { req_users: { username: { $in: [usernameOrig] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
// 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_users: { username: { $in: [usernameOrig] } } } };
|
||||
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, usernameOrig, circuitname);
|
||||
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 {
|
||||
ris = false;
|
||||
}
|
||||
const foundIfAlreadyCircuit = await this.ifAlreadyInCircuit(idapp, usernameOrig, circuitname);
|
||||
|
||||
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) {
|
||||
// Aggiungo la richiesta di Gruppo a me
|
||||
const foundIfAlreadyAskCircuit = await Circuit.findOne({
|
||||
idapp,
|
||||
name: circuitname,
|
||||
'req_users': {
|
||||
$elemMatch: { username: { $eq: usernameOrig } },
|
||||
},
|
||||
});
|
||||
|
||||
if (value) {
|
||||
if (!foundIfAlreadyAskCircuit) {
|
||||
if (!foundIfAlreadyCircuit) {
|
||||
update = {
|
||||
$push: {
|
||||
'req_users': {
|
||||
username: usernameOrig,
|
||||
'profile.mycircuits': {
|
||||
circuitname,
|
||||
date: new Date(),
|
||||
},
|
||||
},
|
||||
};
|
||||
ris = await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
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);
|
||||
|
||||
await Account.createAccount(idapp, usernameOrig, circuitname);
|
||||
|
||||
|
||||
} else {
|
||||
ris = false;
|
||||
}
|
||||
|
||||
await Circuit.updateData(idapp, circuitname)
|
||||
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 this.removeFromCircuits(idapp, usernameOrig, circuitname); // Rimuovo il Gruppo da me
|
||||
|
||||
// Invia una notifica alla persona
|
||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||
// 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) {
|
||||
// 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,
|
||||
name: circuitname,
|
||||
'req_users': {
|
||||
$elemMatch: { username: { $eq: usernameOrig } },
|
||||
},
|
||||
});
|
||||
|
||||
if (value) {
|
||||
if (!foundIfAlreadyAskCircuit) {
|
||||
update = {
|
||||
$push: {
|
||||
'req_users': {
|
||||
username: usernameOrig,
|
||||
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 this.removeFromCircuits(idapp, usernameOrig, circuitname); // Rimuovo il Gruppo da me
|
||||
|
||||
// Invia una notifica alla persona
|
||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REMOVE_FROM_MYLIST) {
|
||||
|
||||
@@ -2368,16 +2441,24 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.CANCEL_REQ) {
|
||||
|
||||
outres.result = await Circuit.removeReqCircuit(idapp, usernameOrig, circuitname); // Rimuovo l'Amicizia da me
|
||||
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) {
|
||||
|
||||
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
|
||||
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) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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);
|
||||
|
||||
// Cancella dal DB la notifica Push, visto che da errore! (sarà scaduto)
|
||||
const ris = await Subscription.deleteOne({ _id: subscription._id });
|
||||
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,8 +1093,25 @@ module.exports = {
|
||||
}
|
||||
|
||||
if (sendnotif && typeid > 0) {
|
||||
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
||||
return await SendNotif.createNewNotifToSingleUser(req, null, paramsObj, onlysave, typedir, typeid);
|
||||
// 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) {
|
||||
@@ -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'] },
|
||||
],
|
||||
},
|
||||
@@ -1907,7 +1929,7 @@ module.exports = {
|
||||
|
||||
if (params.filterextra) {
|
||||
if (params.filterextra.length > 0)
|
||||
query = [...query, ...params.filterextra]
|
||||
query = [...query, ...params.filterextra]
|
||||
}
|
||||
|
||||
if (filtriadded) {
|
||||
|
||||
@@ -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