- 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:
@@ -237,7 +237,7 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp,
|
||||
myaccount = new Account({
|
||||
_id: new ObjectID().toString(),
|
||||
idapp,
|
||||
username,
|
||||
username: (!groupname && !contocom) ? username : '',
|
||||
groupname,
|
||||
contocom,
|
||||
circuitId: mycircuit._id,
|
||||
|
||||
@@ -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 }];
|
||||
|
||||
@@ -5021,22 +5021,22 @@ UserSchema.statics.moverecordsFavorite = async function (tab) {
|
||||
};
|
||||
|
||||
UserSchema.statics.removerecordsFavorite = async function () {
|
||||
// Rimuovi i record del vecchio schema
|
||||
const attivacanc = true;
|
||||
// Rimuovi i record del vecchio schema
|
||||
const attivacanc = true;
|
||||
|
||||
if (attivacanc) {
|
||||
const queryfind = { idapp: '13' };
|
||||
await User.findOneAndUpdate(queryfind, {
|
||||
$set:
|
||||
{
|
||||
'profile.favorite': [],
|
||||
'profile.bookmark': [],
|
||||
'profile.attend': [],
|
||||
'profile.seen': []
|
||||
},
|
||||
});
|
||||
if (attivacanc) {
|
||||
const queryfind = { idapp: '13' };
|
||||
await User.findOneAndUpdate(queryfind, {
|
||||
$set:
|
||||
{
|
||||
'profile.favorite': [],
|
||||
'profile.bookmark': [],
|
||||
'profile.attend': [],
|
||||
'profile.seen': []
|
||||
},
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
UserSchema.statics.updateVersion = async function (userversion, recUser) {
|
||||
|
||||
Reference in New Issue
Block a user