diff --git a/mongodb/richieste_inviate_circuiti.mongodb b/mongodb/richieste_inviate_circuiti.mongodb new file mode 100644 index 0000000..a045894 --- /dev/null +++ b/mongodb/richieste_inviate_circuiti.mongodb @@ -0,0 +1,246 @@ +use('test_FreePlanet'); + +let passo1 = +[ + { + $match: { + idapp: "13", + "profile.mycircuits": { + $elemMatch: { + circuitname: { + $eq: "Riso Rovigo", + }, + }, + }, + }, + }, + { + $lookup: { + from: "circuits", + as: "circuit", + let: { + circuitname: "Riso Rovigo", + idapp: "$idapp", + }, + pipeline: [ + { + $match: { + $expr: { + $and: [ + { + $eq: [ + "$name", + "$$circuitname", + ], + }, + { + $eq: [ + "$idapp", + "$$idapp", + ], + }, + ], + }, + }, + }, + ], + }, + }, + +]; + +let passo1b = [ + { + $lookup: { + from: "accounts", + as: "account", + let: { + username: "$username", + idapp: "$idapp", + circuitId: "$circuit._id", + }, + pipeline: [ + { + $match: { + $expr: { + $and: [ + { + $eq: [ + "$$username", + "$username", + ], + }, + { + $eq: [ + "$$idapp", + "$idapp", + ], + }, + { + $eq: [ + "$$circuitId", + "$circuitId", + ], + }, + ], + }, + }, + }, + ], + }, + }, + { + $unwind: "$account", + }, + { + $match: { + idapp: "13", + }, + }, + { + $sort: { + desc: 1, + }, + }, + +]; + +let passo1c = [ + { + $match: { + $expr: { + $eq: [ + "$_id", + "633ed3454b03da33f944da14", + ], + }, + }, + }, + +]; + +let passo2 = [ + { + $project: { + 'req_users': 1, + }, + }, + +]; + +let passo2b = [ + { + $lookup: { + from: "users", + localField: "req_users.username", + foreignField: "username", + as: "user", + }, + }, + { + $replaceRoot: { + newRoot: { + $mergeObjects: [ + { + $arrayElemAt: [ + "$user", + 0, + ], + }, + "$$ROOT", + ], + }, + }, + }, + { + $project: { + "user.idapp": 1, + "user.username": 1, + "user.profile.img": 1, + "user.profile.qualifica": 1, + }, + }, + { + $unwind: "$user", + }, + { + $match: { + $and: [ + { + "user.idapp": "13", + }, + ], + }, + }, + { + $replaceRoot: { + newRoot: "$user", + }, + }, + { + $match: { + $and: [ + { + $or: [ + { + visibility: { + $nin: [ + 2, + ], + }, + }, + { + createdBy: { + $eq: "paoloar77", + }, + }, + ], + }, + ], + }, + }, + { + $group: { + _id: null, + count: { + $sum: 1, + }, + results: { + $push: "$$ROOT", + }, + }, + }, + { + $project: { + count: 1, + rows: { + $slice: [ + "$results", + 0, + 10, + ], + }, + }, + }, +]; + + +let passo3 = [ +]; + + +let aggregation = []; + +let test = false; + +if (test) { + aggregation = [...aggregation, ...passo4]; +} else { + // aggregation = [...aggregation, ...passo1]; + aggregation = [...aggregation, ...passo1]; + // aggregation = [...aggregation, ...passo1b]; + // aggregation = [...aggregation, ...passo1c]; + // aggregation = [...aggregation, ...passo2]; +} + +db.circuits.aggregate(aggregation); diff --git a/src/server/models/circuit.js b/src/server/models/circuit.js index 9958b94..205a11b 100755 --- a/src/server/models/circuit.js +++ b/src/server/models/circuit.js @@ -217,7 +217,8 @@ CircuitSchema.statics.getFieldsForSearch = function() { {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: 'descr', type: tools.FieldType.string}, + ]; }; CircuitSchema.statics.executeQueryTable = function(idapp, params, user) { diff --git a/src/server/models/site.js b/src/server/models/site.js index 2e24fff..2f4d839 100755 --- a/src/server/models/site.js +++ b/src/server/models/site.js @@ -120,6 +120,7 @@ const SiteSchema = new Schema({ enableTodos: { type: Boolean }, enableRegByBot: { type: Boolean }, enableRegMultiChoice: { type: Boolean }, + enableDebugOn: { type: Boolean }, enabledRegNeedTelegram: { type: Boolean }, showViewGroups: { type: Boolean }, showViewCircuits: { type: Boolean },