++ su "Friends" la ricerca per username Telegram e nome e cognome
This commit is contained in:
@@ -6,10 +6,10 @@ mongoose.level = 'F';
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
const {Movement} = require('../models/movement');
|
||||
const {Account} = require('../models/account');
|
||||
const { Movement } = require('../models/movement');
|
||||
const { Account } = require('../models/account');
|
||||
|
||||
const i18n = require('i18n');
|
||||
|
||||
@@ -21,7 +21,7 @@ mongoose.plugin(schema => {
|
||||
const CircuitSchema = new Schema({
|
||||
_id: {
|
||||
type: String,
|
||||
default: function() {
|
||||
default: function () {
|
||||
return new ObjectID().toString();
|
||||
},
|
||||
},
|
||||
@@ -145,8 +145,8 @@ const CircuitSchema = new Schema({
|
||||
},
|
||||
admins: [
|
||||
{
|
||||
username: {type: String},
|
||||
date: {type: Date},
|
||||
username: { type: String },
|
||||
date: { type: Date },
|
||||
},
|
||||
],
|
||||
photos: [
|
||||
@@ -164,14 +164,14 @@ const CircuitSchema = 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,
|
||||
@@ -190,7 +190,7 @@ const CircuitSchema = new Schema({
|
||||
},
|
||||
});
|
||||
|
||||
CircuitSchema.pre('save', async function(next) {
|
||||
CircuitSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
this._id = new ObjectID().toString();
|
||||
|
||||
@@ -200,10 +200,10 @@ CircuitSchema.pre('save', async function(next) {
|
||||
next();
|
||||
});
|
||||
|
||||
CircuitSchema.statics.findAllIdApp = async function(idapp) {
|
||||
CircuitSchema.statics.findAllIdApp = async function (idapp) {
|
||||
const Circuit = this;
|
||||
|
||||
const myfind = {idapp, deleted: false};
|
||||
const myfind = { idapp, deleted: false };
|
||||
|
||||
const whatToShow = this.getWhatToShow(idapp, '');
|
||||
|
||||
@@ -212,21 +212,21 @@ CircuitSchema.statics.findAllIdApp = async function(idapp) {
|
||||
});
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getFieldsForSearch = function() {
|
||||
CircuitSchema.statics.getFieldsForSearch = function () {
|
||||
return [
|
||||
{field: 'nome_circuito', type: tools.FieldType.string},
|
||||
{field: 'sotto_nome', type: tools.FieldType.string},
|
||||
{field: 'nome_valuta', type: tools.FieldType.string},
|
||||
{field: 'descr', type: tools.FieldType.string},
|
||||
{ field: 'nome_circuito', type: tools.FieldType.string },
|
||||
{ field: 'sotto_nome', type: tools.FieldType.string },
|
||||
{ field: 'nome_valuta', type: tools.FieldType.string },
|
||||
{ field: 'descr', type: tools.FieldType.string },
|
||||
];
|
||||
};
|
||||
|
||||
CircuitSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
CircuitSchema.statics.executeQueryTable = function (idapp, params, user) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, idapp, params, user);
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getWhatToShow = function(idapp, username) {
|
||||
CircuitSchema.statics.getWhatToShow = function (idapp, username) {
|
||||
// FOR ME, PERMIT ALL
|
||||
return {
|
||||
_id: 1,
|
||||
@@ -267,9 +267,9 @@ CircuitSchema.statics.getWhatToShow = function(idapp, username) {
|
||||
};
|
||||
|
||||
// Aggiungi agli Admin del Circuito
|
||||
CircuitSchema.statics.addToAdminOfMyCircuit = async function(idapp, username, name) {
|
||||
CircuitSchema.statics.addToAdminOfMyCircuit = async function (idapp, username, name) {
|
||||
|
||||
return await Circuit.updateOne({idapp, name},
|
||||
return await Circuit.updateOne({ idapp, name },
|
||||
{
|
||||
$push:
|
||||
{
|
||||
@@ -283,13 +283,13 @@ CircuitSchema.statics.addToAdminOfMyCircuit = async function(idapp, username, na
|
||||
};
|
||||
|
||||
// Rimuovi dagli Admin del Circuito
|
||||
CircuitSchema.statics.removeAdminOfMyCircuit = async function(idapp, username, name) {
|
||||
CircuitSchema.statics.removeAdminOfMyCircuit = async function (idapp, username, name) {
|
||||
|
||||
return await Circuit.updateOne({idapp, name},
|
||||
{$pull: {admins: {username: {$in: [username]}}}});
|
||||
return await Circuit.updateOne({ idapp, name },
|
||||
{ $pull: { admins: { username: { $in: [username] } } } });
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getWhatToShow_Unknown = function(idapp, username) {
|
||||
CircuitSchema.statics.getWhatToShow_Unknown = function (idapp, username) {
|
||||
return {
|
||||
groupnameId: 1,
|
||||
path: 1,
|
||||
@@ -326,11 +326,11 @@ CircuitSchema.statics.getWhatToShow_Unknown = function(idapp, username) {
|
||||
};
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getCircuitsByUsername = async function(idapp, username, user) {
|
||||
CircuitSchema.statics.getCircuitsByUsername = async function (idapp, username, user) {
|
||||
|
||||
try {
|
||||
const {User} = require('../models/user');
|
||||
const {Account} = require('../models/account');
|
||||
const { User } = require('../models/user');
|
||||
const { Account } = require('../models/account');
|
||||
|
||||
const whatToShow = this.getWhatToShow(idapp, username);
|
||||
const whatToShow_Unknown = this.getWhatToShow_Unknown(idapp, username);
|
||||
@@ -340,38 +340,38 @@ CircuitSchema.statics.getCircuitsByUsername = async function(idapp, username, us
|
||||
const manage_mycircuits = await Circuit.find({
|
||||
idapp,
|
||||
'admins': {
|
||||
$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 } }],
|
||||
}).lean();
|
||||
|
||||
let listcircuits = await Circuit.find({
|
||||
idapp,
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
{deleted: {$exists: true, $eq: false}}],
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}, whatToShow_Unknown).lean();
|
||||
|
||||
let asked_circuits = await Circuit.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).lean();
|
||||
|
||||
let refused_circuits = await Circuit.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).lean();
|
||||
|
||||
return {
|
||||
@@ -396,7 +396,7 @@ CircuitSchema.statics.getCircuitsByUsername = async function(idapp, username, us
|
||||
};
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getInfoCircuitByName = async function(idapp, name) {
|
||||
CircuitSchema.statics.getInfoCircuitByName = async function (idapp, name) {
|
||||
|
||||
const whatToShow = this.getWhatToShow(idapp, '');
|
||||
|
||||
@@ -414,7 +414,7 @@ CircuitSchema.statics.getInfoCircuitByName = async function(idapp, name) {
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getCircuitByName = async function(idapp, name) {
|
||||
CircuitSchema.statics.getCircuitByName = async function (idapp, name) {
|
||||
|
||||
const myfind = {
|
||||
idapp,
|
||||
@@ -430,7 +430,7 @@ CircuitSchema.statics.getCircuitByName = async function(idapp, name) {
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getCircuitById = async function(circuitId) {
|
||||
CircuitSchema.statics.getCircuitById = async function (circuitId) {
|
||||
|
||||
const myfind = {
|
||||
_id: circuitId,
|
||||
@@ -445,12 +445,12 @@ CircuitSchema.statics.getCircuitById = async function(circuitId) {
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.deleteCircuit = async function(idapp, usernameOrig, name) {
|
||||
CircuitSchema.statics.deleteCircuit = async function (idapp, usernameOrig, name) {
|
||||
console.log('Circuito ' + name + ' rimosso da ' + usernameOrig);
|
||||
return await Circuit.findOneAndRemove({idapp, name});
|
||||
return await Circuit.findOneAndRemove({ idapp, name });
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getUserCircuits = async function(idapp, username) {
|
||||
CircuitSchema.statics.getUserCircuits = async function (idapp, username) {
|
||||
|
||||
try {
|
||||
let aggr1 = [
|
||||
@@ -458,8 +458,8 @@ CircuitSchema.statics.getUserCircuits = async function(idapp, username) {
|
||||
$match: {
|
||||
idapp, username,
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
{deleted: {$exists: true, $eq: false}}],
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -504,9 +504,9 @@ CircuitSchema.statics.getUserCircuits = async function(idapp, username) {
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getUsersSingleCircuit = async function(idapp, username, circuitname, circuitId) {
|
||||
CircuitSchema.statics.getUsersSingleCircuit = async function (idapp, username, circuitname, circuitId) {
|
||||
|
||||
const {User} = require('../models/user');
|
||||
const { User } = require('../models/user');
|
||||
|
||||
try {
|
||||
let aggr1 = [
|
||||
@@ -514,7 +514,7 @@ CircuitSchema.statics.getUsersSingleCircuit = async function(idapp, username, ci
|
||||
$match: {
|
||||
idapp: idapp,
|
||||
'profile.mycircuits': {
|
||||
$elemMatch: {circuitname: {$eq: circuitname}},
|
||||
$elemMatch: { circuitname: { $eq: circuitname } },
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -546,14 +546,19 @@ CircuitSchema.statics.getUsersSingleCircuit = async function(idapp, username, ci
|
||||
{$unwind: '$circuit'},
|
||||
*/
|
||||
{
|
||||
$project: {username: 1, profile: 1, idapp: 1 /*, 'circuit.name': 1, 'circuit._id': 1*/},
|
||||
$project: {
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
profile: 1, idapp: 1 /*, 'circuit.name': 1, 'circuit._id': 1*/
|
||||
},
|
||||
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'accounts',
|
||||
as: 'account',
|
||||
let: {username: '$username', idapp: '$idapp', circuitId: circuitId /*, circuitId: '$circuit._id' */ },
|
||||
let: { username: '$username', idapp: '$idapp', circuitId: circuitId /*, circuitId: '$circuit._id' */ },
|
||||
pipeline: [
|
||||
{
|
||||
$match:
|
||||
@@ -562,9 +567,9 @@ CircuitSchema.statics.getUsersSingleCircuit = async function(idapp, username, ci
|
||||
{
|
||||
$and:
|
||||
[
|
||||
{$eq: ['$$username', '$username']},
|
||||
{$eq: ['$$idapp', '$idapp']},
|
||||
{$eq: ['$$circuitId', '$circuitId']},
|
||||
{ $eq: ['$$username', '$username'] },
|
||||
{ $eq: ['$$idapp', '$idapp'] },
|
||||
{ $eq: ['$$circuitId', '$circuitId'] },
|
||||
],
|
||||
},
|
||||
},
|
||||
@@ -572,7 +577,7 @@ CircuitSchema.statics.getUsersSingleCircuit = async function(idapp, username, ci
|
||||
],
|
||||
},
|
||||
},
|
||||
{$unwind: '$account'},
|
||||
{ $unwind: '$account' },
|
||||
];
|
||||
|
||||
ris = await User.aggregate(aggr1);
|
||||
@@ -584,7 +589,7 @@ CircuitSchema.statics.getUsersSingleCircuit = async function(idapp, username, ci
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getCircolanteSingolaTransaz = function(accountorigTable, accountdestTable) {
|
||||
CircuitSchema.statics.getCircolanteSingolaTransaz = function (accountorigTable, accountdestTable) {
|
||||
|
||||
let circolante = 0;
|
||||
if (accountdestTable.saldo > 0)
|
||||
@@ -595,7 +600,7 @@ CircuitSchema.statics.getCircolanteSingolaTransaz = function(accountorigTable, a
|
||||
return circolante;
|
||||
};
|
||||
|
||||
CircuitSchema.statics.sendCoins = async function(onlycheck, idapp, usernameOrig, extrarec) {
|
||||
CircuitSchema.statics.sendCoins = async function (onlycheck, idapp, usernameOrig, extrarec) {
|
||||
|
||||
let ris = {
|
||||
result: false,
|
||||
@@ -650,7 +655,7 @@ CircuitSchema.statics.sendCoins = async function(onlycheck, idapp, usernameOrig,
|
||||
totTransato: circuittable.totTransato,
|
||||
totCircolante: circuittable.totCircolante,
|
||||
};
|
||||
await Circuit.updateOne({_id: circuittable}, {$set: paramstoupdate});
|
||||
await Circuit.updateOne({ _id: circuittable }, { $set: paramstoupdate });
|
||||
|
||||
ris.result = true;
|
||||
console.log('Inviate Monete da', usernameOrig, extrarec.dest, myqty, extrarec.causal);
|
||||
@@ -677,17 +682,17 @@ CircuitSchema.statics.sendCoins = async function(onlycheck, idapp, usernameOrig,
|
||||
};
|
||||
|
||||
// Rimuovo la Richiesta del Circuito
|
||||
CircuitSchema.statics.removeReqCircuit = async function(idapp, username, name) {
|
||||
CircuitSchema.statics.removeReqCircuit = async function (idapp, username, name) {
|
||||
|
||||
return await Circuit.updateOne({idapp, name},
|
||||
{$pull: {req_users: {username: {$in: [username]}}}});
|
||||
return await Circuit.updateOne({ idapp, name },
|
||||
{ $pull: { req_users: { username: { $in: [username] } } } });
|
||||
};
|
||||
|
||||
// Aggiungi agli utenti Rifiutati del Circuito
|
||||
|
||||
CircuitSchema.statics.refuseReqCircuit = async function(idapp, username, name) {
|
||||
CircuitSchema.statics.refuseReqCircuit = async function (idapp, username, name) {
|
||||
|
||||
return await Circuit.updateOne({idapp, name},
|
||||
return await Circuit.updateOne({ idapp, name },
|
||||
{
|
||||
$push:
|
||||
{
|
||||
@@ -700,22 +705,22 @@ CircuitSchema.statics.refuseReqCircuit = async function(idapp, username, name) {
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.updateData = async function(idapp, circuitname) {
|
||||
CircuitSchema.statics.updateData = async function (idapp, circuitname) {
|
||||
|
||||
try {
|
||||
|
||||
const {User} = require('./user');
|
||||
const { User } = require('./user');
|
||||
|
||||
let aggr1 = [
|
||||
{
|
||||
$match: {
|
||||
idapp,
|
||||
'profile.mycircuits': {
|
||||
$elemMatch: {circuitname: {$eq: circuitname}},
|
||||
$elemMatch: { circuitname: { $eq: circuitname } },
|
||||
},
|
||||
},
|
||||
},
|
||||
{$group: {_id: null, count: {$sum: 1}}},
|
||||
{ $group: { _id: null, count: { $sum: 1 } } },
|
||||
];
|
||||
|
||||
const ris = await User.aggregate(aggr1);
|
||||
@@ -725,7 +730,7 @@ CircuitSchema.statics.updateData = async function(idapp, circuitname) {
|
||||
let paramstoupdate = {
|
||||
numMembers: numMembers,
|
||||
};
|
||||
const risult = await this.updateOne({idapp, name: circuitname}, {$set: paramstoupdate});
|
||||
const risult = await this.updateOne({ idapp, name: circuitname }, { $set: paramstoupdate });
|
||||
|
||||
console.log('risult', risult);
|
||||
|
||||
@@ -735,13 +740,13 @@ CircuitSchema.statics.updateData = async function(idapp, circuitname) {
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.setDeperimentoOff = async function() {
|
||||
CircuitSchema.statics.setDeperimentoOff = async function () {
|
||||
|
||||
return await Circuit.updateMany({}, {$set: {'deperimento': false}},
|
||||
{new: false});
|
||||
return await Circuit.updateMany({}, { $set: { 'deperimento': false } },
|
||||
{ new: false });
|
||||
|
||||
};
|
||||
|
||||
const Circuit = mongoose.model('Circuit', CircuitSchema);
|
||||
|
||||
module.exports = {Circuit};
|
||||
module.exports = { Circuit };
|
||||
|
||||
@@ -3133,11 +3133,22 @@ UserSchema.statics.getFieldsForSearch = function () {
|
||||
};
|
||||
|
||||
UserSchema.statics.getFieldsForSearchUserFriend = function () {
|
||||
return [{ field: 'username', type: tools.FieldType.exact }];
|
||||
return [
|
||||
{ field: 'username', type: tools.FieldType.exact },
|
||||
{ field: 'profile.username_telegram', type: tools.FieldType.string },
|
||||
{ field: 'name', type: tools.FieldType.string },
|
||||
{ field: 'surname', type: tools.FieldType.string },
|
||||
];
|
||||
};
|
||||
|
||||
UserSchema.statics.getFieldsForSearchUserFriend_AllWords = function () {
|
||||
return [{ field: 'username', type: tools.FieldType.string }];
|
||||
return [
|
||||
{ field: 'username', type: tools.FieldType.string },
|
||||
{ field: 'profile.username_telegram', type: tools.FieldType.string },
|
||||
{ field: 'name', type: tools.FieldType.string },
|
||||
{ field: 'surname', type: tools.FieldType.string },
|
||||
|
||||
];
|
||||
};
|
||||
|
||||
UserSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
|
||||
@@ -614,6 +614,8 @@ router.post('/getexp', authenticate, (req, res) => {
|
||||
},
|
||||
{
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
email: 1,
|
||||
'reported': 1,
|
||||
date_report: 1,
|
||||
|
||||
Reference in New Issue
Block a user