- Invia Ris a e Ricevi Ris
- Tutorial Guidato Passi da Compiere - Provincia in cui vivi - Policy aggiornata
This commit is contained in:
@@ -117,6 +117,9 @@ const MyGroupSchema = new Schema({
|
||||
circuitname: { type: String },
|
||||
date: { type: Date },
|
||||
}],
|
||||
lastdate_reqRisGroup: {
|
||||
type: Date,
|
||||
},
|
||||
});
|
||||
|
||||
MyGroupSchema.statics.getFieldsForSearch = function () {
|
||||
@@ -223,14 +226,14 @@ MyGroupSchema.statics.removeAdminOfMyGroup = async function (idapp, username, gr
|
||||
};
|
||||
|
||||
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();
|
||||
}, { admins: 1 }).lean();
|
||||
|
||||
return arr && arr.admins ? arr.admins : [];
|
||||
|
||||
@@ -259,6 +262,7 @@ MyGroupSchema.statics.getWhatToShow = function (idapp, username) {
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
mycircuits: 1,
|
||||
lastdate_reqRisGroup: 1,
|
||||
};
|
||||
|
||||
};
|
||||
@@ -276,6 +280,7 @@ MyGroupSchema.statics.getWhatToShow_Unknown = function (idapp, username) {
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
mycircuits: 1,
|
||||
lastdate_reqRisGroup: 1,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -496,10 +501,14 @@ MyGroupSchema.statics.ifCircuitAlreadyInGroup = async function (idapp, groupname
|
||||
// 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(),
|
||||
} } });
|
||||
{
|
||||
$push: {
|
||||
'mycircuits': {
|
||||
circuitname,
|
||||
date: new Date(),
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
@@ -510,6 +519,117 @@ MyGroupSchema.statics.removeCircuitFromGroup = async function (idapp, groupname,
|
||||
|
||||
};
|
||||
|
||||
MyGroupSchema.statics.getQueryReceiveRISGroups = function (idapp, hours) {
|
||||
|
||||
const query = [
|
||||
{
|
||||
$match: {
|
||||
idapp,
|
||||
'lastdate_reqRisGroup': { $gte: tools.IncDateNow(-(1000 * 60 * 60 * hours)) },
|
||||
$or: [
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
},
|
||||
},
|
||||
{
|
||||
$group:
|
||||
{
|
||||
_id: "$groupname",
|
||||
count: {
|
||||
$sum: 1,
|
||||
},
|
||||
}
|
||||
},
|
||||
{ $sort: { 'lastdate_reqRisGroup': -1 } },
|
||||
{ $limit: 30 },
|
||||
{
|
||||
$lookup: {
|
||||
from: "mygroups",
|
||||
let: {
|
||||
groupname: "$_id",
|
||||
idapp,
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{
|
||||
$eq: [
|
||||
"$$groupname",
|
||||
"$groupname",
|
||||
],
|
||||
},
|
||||
{
|
||||
$eq: [
|
||||
"$$idapp",
|
||||
"$idapp",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
as: "mygroup",
|
||||
},
|
||||
},
|
||||
{ $unwind: "$mygroup" },
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: ["$mygroup", "$$ROOT"],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
_id: 0,
|
||||
groupname: 1,
|
||||
title: 1,
|
||||
descr: 1,
|
||||
visibility: 1,
|
||||
idCatGrp: 1,
|
||||
userId: 1,
|
||||
photos: 1,
|
||||
idCity: 1,
|
||||
website: 1,
|
||||
link_telegram: 1,
|
||||
note: 1,
|
||||
admins: 1,
|
||||
blocked: 1,
|
||||
req_users: 1,
|
||||
createdBy: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
lastdate_reqRisGroup: 1,
|
||||
},
|
||||
},
|
||||
];
|
||||
return query;
|
||||
};
|
||||
|
||||
|
||||
MyGroupSchema.statics.getReceiveRISGroups = async function (idapp) {
|
||||
|
||||
return await this.aggregate(this.getQueryReceiveRISGroups(idapp, 8)).then(ris => {
|
||||
return ris;
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
MyGroupSchema.statics.setReceiveRisGroup = async function (idapp, groupname) {
|
||||
|
||||
return await this.findOneAndUpdate({
|
||||
idapp, groupname,
|
||||
},
|
||||
{ $set: { 'lastdate_reqRisGroup': new Date() } }, { new: false }).lean().then((record) => {
|
||||
return !!record;
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
const MyGroup = mongoose.model('MyGroup', MyGroupSchema);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user