- se iOS non ricarica la pagina ma disinstalla il SW precedente e chiede di riavviare

- fixed: Creando un Conto di Gruppo, pare che venga impostato anche l'username... invece dev'essere solo il groupname
-
This commit is contained in:
Surya Paolo
2023-10-03 23:16:52 +02:00
parent d6303f5880
commit 536fbd1752
7 changed files with 187 additions and 26 deletions

View File

@@ -4,7 +4,6 @@ const Schema = mongoose.Schema;
const i18n = require('i18n');
const tools = require('../tools/general');
const shared_consts = require('../tools/shared_nodejs');
@@ -67,6 +66,150 @@ reactionSchema.statics.getFieldsForReactions = function () {
return reactionsField;
};
reactionSchema.statics.getReactionsCounts = async function (mytable, idapp, idrec, numtab) {
let query = [];
try {
query =
[
{
$match: {
_id: idrec,
},
},
{
$lookup: {
from: "reactions",
let: {
tab: numtab,
id: '$_id',
},
pipeline: [
{
$match: {
$expr: {
$and: [
{ $eq: ['$idrec', idrec] },
{ $eq: ['$tab', numtab] },
{ $eq: ['$idapp', idapp] },
],
},
},
},
{
$group: {
_id: "$idrec",
numseen: {
$sum: {
$cond: {
if: { $ifNull: ["$seen", false] }, // Check if the field exists and is not null
then: 1, // Increment count by 1 if the field exists
else: 0, // Otherwise, keep the count unchanged
}
}
},
numfav: {
$sum: {
$cond: {
if: { $ifNull: ["$fav", false] }, // Check if the field exists and is not null
then: 1, // Increment count by 1 if the field exists
else: 0, // Otherwise, keep the count unchanged
}
}
},
numbook: {
$sum: {
$cond: {
if: { $ifNull: ["$book", false] }, // Check if the field exists and is not null
then: 1, // Increment count by 1 if the field exists
else: 0, // Otherwise, keep the count unchanged
}
}
},
numattend: {
$sum: {
$cond: {
if: { $ifNull: ["$attend", false] }, // Check if the field exists and is not null
then: 1, // Increment count by 1 if the field exists
else: 0, // Otherwise, keep the count unchanged
}
}
}
},
},
],
as: 'myreact',
},
},
{
$unwind: {
path: "$myreact",
preserveNullAndEmptyArrays: true,
},
},
];
const ris = await mytable.aggregate(query);
return ris ? ris[0]: null;
} catch (e) {
}
};
reactionSchema.statics.updateReactionsCounts = async function () {
const globalTables = require('../tools/globalTables');
console.log('INIZIO - updateReactionsCounts');
try {
for (const tablestr of shared_consts.TABLES_REACTIONS) {
const numtab = tools.getNumTabByTable(tablestr);
const mytable = globalTables.getTableByTableName(tablestr);
const arrrec = await mytable.find({});
console.log(' updateReactionsCounts tabella', tablestr);
for (const rec of arrrec) {
// Calcola
const ris = await Reaction.getReactionsCounts(mytable, idapp, rec._id, numtab);
if (ris && ris.myreact) {
risupdate = await mytable.updateOne({ _id: rec._id }, {
$set: {
numseen: ris.myreact.numseen | 0,
numfav: ris.myreact.numfav | 0,
numbook: ris.myreact.numbook | 0,
numattend: ris.myreact.numattend | 0,
}
})
}
}
}
console.log('FINE - updateReactionsCounts');
} catch (err) {
console.error(err);
}
};
;
reactionSchema.statics.getFieldsForSearch = function () {
return [
{ field: 'username', type: tools.FieldType.string }];