- Invia Ris a e Ricevi Ris

- Tutorial Guidato Passi da Compiere
- Provincia in cui vivi
- Policy aggiornata
This commit is contained in:
Surya Paolo
2023-03-11 01:01:11 +01:00
parent 6a4c270c91
commit e705594294
8 changed files with 390 additions and 65 deletions

View File

@@ -47,6 +47,10 @@ const CircuitSchema = new Schema({
{
type: Number,
}],
strProv:
{
type: String,
},
pub_to_share: {
type: Number, // PUB_TO_SHARE_ALL, PUB_TO_SHARE_ONLY_TABLE_FOLLOW
},
@@ -225,7 +229,7 @@ CircuitSchema.statics.findAllIdApp = async function (idapp) {
const whatToShow = this.getWhatToShow(idapp, '');
return await Circuit.find(myfind, whatToShow).sort({status: -1, numMembers: -1, name: 1});
return await Circuit.find(myfind, whatToShow).sort({ status: -1, numMembers: -1, name: 1 });
};
CircuitSchema.statics.getFieldsForSearch = function () {
@@ -271,6 +275,7 @@ CircuitSchema.statics.getWhatToShow = function (idapp, username) {
valuta_per_euro: 1,
symbol: 1,
idCity: 1,
strProv: 1,
pub_to_share: 1,
visibility: 1,
color: 1,
@@ -332,6 +337,7 @@ CircuitSchema.statics.getWhatToShow_Unknown = function (idapp, username) {
symbol: 1,
color: 1,
idCity: 1,
strProv: 1,
pub_to_share: 1,
visibility: 1,
abbrev: 1,
@@ -370,14 +376,14 @@ CircuitSchema.statics.getCircuitsByUsername = async function (idapp, username, u
$or: [
{ deleted: { $exists: false } },
{ deleted: { $exists: true, $eq: false } }],
}).sort({status: -1, numMembers: -1, name: 1}).lean();
}).sort({ status: -1, numMembers: -1, name: 1 }).lean();
let listcircuits = await Circuit.find({
idapp,
$or: [
{ deleted: { $exists: false } },
{ deleted: { $exists: true, $eq: false } }],
}, whatToShow_Unknown).sort({status: -1, numMembers: -1, name: 1}).lean();
}, whatToShow_Unknown).sort({ status: -1, numMembers: -1, name: 1 }).lean();
let asked_circuits = await Circuit.find({
idapp,
@@ -387,7 +393,7 @@ CircuitSchema.statics.getCircuitsByUsername = async function (idapp, username, u
$or: [
{ deleted: { $exists: false } },
{ deleted: { $exists: true, $eq: false } }],
}, whatToShow_Unknown).sort({status: -1}).lean();
}, whatToShow_Unknown).sort({ status: -1 }).lean();
let refused_circuits = await Circuit.find({
idapp,
@@ -397,7 +403,7 @@ CircuitSchema.statics.getCircuitsByUsername = async function (idapp, username, u
$or: [
{ deleted: { $exists: false } },
{ deleted: { $exists: true, $eq: false } }],
}, whatToShow_Unknown).sort({status: -1}).lean();
}, whatToShow_Unknown).sort({ status: -1 }).lean();
return {
listcircuits,
@@ -575,7 +581,7 @@ CircuitSchema.statics.getUsersSingleCircuit = async function (idapp, username, c
username: 1,
name: 1,
surname: 1,
profile: 1,
profile: 1,
idapp: 1 /*, 'circuit.name': 1, 'circuit._id': 1*/
},
@@ -687,7 +693,7 @@ CircuitSchema.statics.sendCoins = async function (onlycheck, idapp, usernameOrig
extrarec.saldoDest = accountdestTable.saldo;
let orig = usernameOrig + (extrarec.grouporig ? extrarec.grouporig : '') + (extrarec.contoComOrig ? extrarec.contoComOrig : '');
let dest = (extrarec.dest ? extrarec.dest : '') + (extrarec.groupDest ? extrarec.groupDest : '') + (extrarec.contoComDest ? extrarec.contoComDest : '');
let dest = (extrarec.dest ? extrarec.dest : '') + (extrarec.groupDest ? extrarec.groupDest : '') + (extrarec.contoComDest ? extrarec.contoComDest : '');
ris.result = true;
let msg = 'Inviate Monete da ' + orig + ' a ' + dest + ' ' + myqty + ' ' + circuittable.symbol + ' [causale: ' + extrarec.causal + `] [Saldo ${orig}: ` + extrarec.saldoOrig + ' ' + circuittable.symbol + '] ' + ` [Saldo ${dest}: ` + extrarec.saldoDest + ' ' + circuittable.symbol + ']';
@@ -835,6 +841,25 @@ CircuitSchema.statics.getListAdminsByCircuitPath = async function (idapp, circui
// Imposta a tutti i Conti Collettivi, i seguenti minimi e massimi
CircuitSchema.statics.setstrProvByIdCityCircuits = async function (idapp) {
const { City } = require('../models/city');
const arrcircuits = await Circuit.find({ idapp }).lean();
try {
for (const rec of arrcircuits) {
let recstrProv = await City.findOne({ _id: rec.idCity[0] });
if (recstrProv) {
let objProv = {}
objProv['strProv'] = recstrProv.prov;
await Circuit.updateOne({ _id: rec._id }, { $set: objProv });
}
}
} catch (e) {
}
};
CircuitSchema.statics.SetDefMinMaxCollettivi = async function (idapp, valmin, valmax) {
ris = await Circuit.updateMany({ idapp, contocom: { "$nin": [null, ""] } },

View File

@@ -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);

View File

@@ -91,7 +91,7 @@ ProvinceSchema.statics.executeQueryPickup = async function(idapp, params) {
ProvinceSchema.statics.findAllIdApp = async function(idapp) {
const myfind = {};
return Province.find(myfind).sort({prov: 1});
return Province.find(myfind).sort({descr: 1});
};
const Province = mongoose.model('Province', ProvinceSchema);

View File

@@ -398,7 +398,12 @@ const UserSchema = new mongoose.Schema({
circuitname: { type: String },
date: { type: Date },
}],
last_circuitpath: {
type: String,
},
lastdate_reqRis: {
type: Date,
},
notifs: [
{
_id: false,
@@ -433,6 +438,12 @@ const UserSchema = new mongoose.Schema({
type: String,
trim: true,
},
stepTutorial: {
type: Number,
},
noNameSurname: {
type: Boolean,
}
},
});
@@ -3764,6 +3775,7 @@ UserSchema.statics.getLastOnlineUsers = async function (idapp) {
name: 1,
surname: 1,
lasttimeonline: 1,
date_reg: 1,
'profile.img': 1,
index: 1,
}).sort({ lasttimeonline: -1 }).limit(lastn).then((arr) => {
@@ -3790,6 +3802,7 @@ UserSchema.statics.getLastSharedLink = async function (idapp) {
name: 1,
surname: 1,
lasttimeonline: 1,
date_reg: 1,
'profile.img': 1,
index: 1,
}).sort({ date_tokenreg: -1 }).limit(lastn).then((arr) => {
@@ -3822,6 +3835,16 @@ UserSchema.statics.getBestStretteDiManoUsers = async function (idapp) {
};
UserSchema.statics.getReceiveRISUsers = async function (idapp) {
const User = this;
return await User.aggregate(User.getQueryReceiveRISUsers(idapp, 8)).then(ris => {
// console.table(ris);
return ris;
});
};
UserSchema.statics.checkUser = async function (idapp, username) {
const User = this;
@@ -4020,8 +4043,10 @@ UserSchema.statics.getQueryUsersDiffusori = function (idapp) {
name: 1,
surname: 1,
lasttimeonline: 1,
date_reg: 1,
idapp: 1,
"profile.img": 1,
'profile.mycircuits': 1,
},
},
];
@@ -4110,6 +4135,92 @@ UserSchema.statics.getQueryUsersStretteDiMano = function (idapp) {
name: 1,
surname: 1,
lasttimeonline: 1,
date_reg: 1,
idapp: 1,
"profile.img": 1,
'profile.handshake': 1,
'profile.mycircuits': 1,
},
},
];
return query;
};
UserSchema.statics.getQueryReceiveRISUsers = function (idapp, hours) {
const query = [
{
$match: {
idapp,
'profile.lastdate_reqRis': { $gte: tools.IncDateNow(-(1000 * 60 * 60 * hours)) },
$or: [
{ deleted: { $exists: false } },
{ deleted: { $exists: true, $eq: false } }],
},
},
{
$group:
{
_id: "$username",
count: {
$sum: 1,
},
}
},
{ $sort: { 'profile.lastdate_reqRis': -1 } },
{ $limit: 30 },
{
$lookup: {
from: "users",
let: {
username: "$_id",
idapp,
},
pipeline: [
{
$match: {
$expr: {
$and: [
{
$eq: [
"$$username",
"$username",
],
},
{
$eq: [
"$$idapp",
"$idapp",
],
},
],
},
},
},
],
as: "user",
},
},
{ $unwind: "$user" },
{
$replaceRoot: {
newRoot: {
$mergeObjects: ["$user", "$$ROOT"],
},
},
},
{
$project: {
_id: 0,
count: 1,
aportador_solidario: 1,
username: 1,
name: 1,
surname: 1,
lasttimeonline: 1,
'profile.lastdate_reqRis': 1,
'profile.mycircuits': 1,
date_reg: 1,
idapp: 1,
"profile.img": 1,
'profile.handshake': 1,
@@ -4184,7 +4295,7 @@ UserSchema.statics.getnumRegNDays = function (idapp, nrec) {
UserSchema.statics.calcnumRegUntilDay = async function (idapp) {
const User = this;
return await User.aggregate(User.getnumRegNDays(idapp, 30)).then((arr) => {
return await User.aggregate(User.getnumRegNDays(idapp, 60)).then((arr) => {
return arr.reduce((sum, rec) => sum + rec.count, 0);
});
@@ -4622,6 +4733,27 @@ UserSchema.statics.tooManyReqPassword = async function (idapp, email, set) {
};
UserSchema.statics.setLastCircuitOpened = async function (idapp, username, circuitpath) {
try {
return await User.findOneAndUpdate({ idapp, username }, { $set: { 'profile.last_circuitpath': circuitpath } });
} catch (e) {
return false;
}
};
UserSchema.statics.setReceiveRis = async function (idapp, username) {
const User = this;
return await User.findOneAndUpdate({
idapp, username,
},
{ $set: { 'profile.lastdate_reqRis': new Date() } }, { new: false }).lean().then((record) => {
return !!record;
});
};
UserSchema.statics.createNewSubRecord = async function (idapp, req) {
const User = this;