Merge branch 'develop' of ssh://risosrv:5522/~/repository/freeplanet_serverside into develop

This commit is contained in:
Surya Paolo
2023-11-27 11:16:13 +01:00
9 changed files with 78 additions and 18 deletions

View File

@@ -80,6 +80,7 @@ let aggregation = [
"profile.mygroups": 1,
"profile.qualifica": 1,
"profile.resid_province": 1,
"profile.resid_card": 1,
reported: 1,
date_report: 1,
username_who_report: 1,
@@ -141,6 +142,7 @@ let aggregation = [
"profile.mygroups": 1,
"profile.qualifica": 1,
"profile.resid_province": 1,
"profile.resid_card": 1,
reported: 1,
date_report: 1,
username_who_report: 1,

View File

@@ -57,6 +57,10 @@ const CircuitSchema = new Schema({
{
type: String,
},
card: // Punti cardinali
{
type: String,
},
pub_to_share: {
type: Number, // PUB_TO_SHARE_ALL, PUB_TO_SHARE_ONLY_TABLE_FOLLOW
},
@@ -290,6 +294,7 @@ CircuitSchema.statics.getWhatToShow = function (idapp, username) {
symbol: 1,
idCity: 1,
strProv: 1,
card: 1,
link_group: 1,
pub_to_share: 1,
visibility: 1,
@@ -354,6 +359,7 @@ CircuitSchema.statics.getWhatToShow_Unknown = function (idapp, username) {
color: 1,
idCity: 1,
strProv: 1,
card: 1,
link_group: 1,
pub_to_share: 1,
visibility: 1,
@@ -495,12 +501,22 @@ CircuitSchema.statics.getCircuitIdByName = async function (idapp, name) {
};
CircuitSchema.statics.getCircuitByProvince = async function (idapp, strProv) {
CircuitSchema.statics.getCircuitByProvinceAndCard = async function (idapp, strProv, card) {
const myfind = {
idapp,
strProv,
};
let myfind = {};
if (card) {
myfind = {
idapp,
strProv,
card
};
} else {
myfind = {
idapp,
strProv,
};
}
try {
return await Circuit.findOne(myfind);
@@ -815,7 +831,13 @@ CircuitSchema.statics.updateData = async function (idapp, circuitname) {
const ris = await User.aggregate(aggr1);
let numMembers = ris ? ris[0].count : 0;
let numMembers = 0;
try {
numMembers = ris && tools.isArray(ris) ? ris[0].count : 0;
} catch (e) {
};
let paramstoupdate = {
numMembers: numMembers,
@@ -948,7 +970,7 @@ CircuitSchema.statics.getCircuitMyProvince = async function (idapp, username) {
const myuser = await User.getUserByUsername(idapp, username);
try {
const circuit = await this.getCircuitByProvince(idapp, myuser.profile.resid_province);
const circuit = await this.getCircuitByProvinceAndCard(idapp, myuser.profile.resid_province, myuser.profile.resid_card);
if (circuit) {
if (await User.ifAlreadyInCircuit(idapp, username, circuit.name)) {
@@ -964,14 +986,14 @@ CircuitSchema.statics.getCircuitMyProvince = async function (idapp, username) {
};
// Imposta a tutti i Conti Collettivi, i seguenti minimi e massimi
CircuitSchema.statics.createCircuitIfNotExist = async function (req, idapp, province) {
CircuitSchema.statics.createCircuitIfNotExist = async function (req, idapp, province, card) {
const { User } = require('../models/user');
const useradmin = tools.USER_ADMIN_CIRCUITS;
let myrec = null;
try {
const circuit = await this.getCircuitByProvince(idapp, province);
const circuit = await this.getCircuitByProvinceAndCard(idapp, province, card);
const nomeprovincia = await Province.getStrProvinceByProv(province);
@@ -981,6 +1003,7 @@ CircuitSchema.statics.createCircuitIfNotExist = async function (req, idapp, prov
name: 'Circuito RIS ' + nomeprovincia,
path: 'ris' + tools.convertSpaces_ToUScore(nomeprovincia.toLowerCase()),
strProv: province,
card,
photos: [],
color: '#ff5500',
deperimento: false,
@@ -1155,7 +1178,7 @@ CircuitSchema.statics.setFido = async function (idapp, username, circuitName, gr
const accountsuser = await Account.getUserAccounts(idapp, username);
if (accountsuser) {
// Se lo trovo della mia provincia, prendo quello
account = accountsuser.find((account) => account.circuit.strProv === myuser.profile.resid_province)
account = accountsuser.find((account) => account.circuit.strProv === myuser.profile.resid_province && account.circuit.card === myuser.profile.resid_card)
if (!account && accountsuser.length > 0) {
// Se non lo trovo, prendo il primo in cui sono entrato !
account = accountsuser[0];

View File

@@ -98,7 +98,7 @@ const MySkillSchema = new Schema(
},
},
...Reaction.getFieldsForReactions()
});
}, { strict: false });
MySkillSchema.index({ 'idapp': 1 });

View File

@@ -35,11 +35,32 @@ const ProvinceSchema = new Schema({
link_grp: {
type: String,
},
card : {
type: String,
},
link_telegram: {
type: String,
},
}, { _id : false });
ProvinceSchema.pre('save', async function (next) {
if (this.isNew) {
const myrec = await Province.findOne().limit(1).sort({_id:-1});
if (!!myrec) {
if (myrec._doc._id === 0)
this._id = 1;
else
this._id = myrec._doc._id + 1;
} else {
this._id = 1;
}
}
next();
});
ProvinceSchema.statics.getRegionByStrProvince = async function(strprovince) {
const myrec = await Province.findOne({prov: strprovince}).lean();
if (myrec) {

View File

@@ -981,6 +981,7 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
'profile.notifs': 1,
'profile.mycircuits': 1,
'profile.resid_province': 1,
'profile.resid_card': 1,
'profile.notif_idCities': 1,
'profile.notif_provinces': 1,
'profile.notif_regions': 1,

View File

@@ -441,6 +441,10 @@ const UserSchema = new mongoose.Schema({
type: String,
trim: true,
},
resid_card: {
type: String,
trim: true,
},
stepTutorial: {
type: Number,
},
@@ -1623,6 +1627,7 @@ UserSchema.statics.getUserProfileByUsername = async function (
'profile.born_province': 1,
'profile.born_country': 1,
'profile.resid_province': 1,
'profile.resid_card': 1,
'profile.calc': 1,
'profile.handshake': 1,
'profile.friends': 1,
@@ -1667,6 +1672,7 @@ UserSchema.statics.getUserProfileByUsername = async function (
'profile.born_province': 1,
'profile.born_country': 1,
'profile.resid_province': 1,
'profile.resid_card': 1,
'profile.calc': 1,
'profile.handshake': 1,
'profile.friends': 1,
@@ -1712,6 +1718,7 @@ UserSchema.statics.getUserProfileByUsername = async function (
'profile.born_province': 1,
'profile.born_country': 1,
'profile.resid_province': 1,
'profile.resid_card': 1,
'profile.calc': 1,
'profile.handshake': 1,
'profile.friends': 1,
@@ -3006,6 +3013,7 @@ function getWhatToShow(idapp, username) {
'profile.born_province': 1,
'profile.born_country': 1,
'profile.resid_province': 1,
'profile.resid_card': 1,
'profile.calc': 1,
email: 1,
date_reg: 1,
@@ -3030,6 +3038,7 @@ function getWhatToShow_Unknown(idapp, username) {
'profile.born_province': 1,
'profile.born_country': 1,
'profile.resid_province': 1,
'profile.resid_card': 1,
'profile.calc': 1,
date_reg: 1,
'profile.handshake': 1,
@@ -3056,6 +3065,7 @@ UserSchema.statics.getWhatToShow_IfFriends = async function (idapp, username) {
'profile.born_province': 1,
'profile.born_country': 1,
'profile.resid_province': 1,
'profile.resid_card': 1,
'profile.calc': 1,
reported: 1,
date_report: 1,

View File

@@ -113,13 +113,14 @@ module.exports = {
{_id: 111, reg: 'RSM', prov: 'RSM', descr: 'Repubblica di San Marino', link_grp: 'https://t.me/+HSdNurm0IXY1MGI0', link_telegram: ''},
{_id: 112, reg: 'EST', prov: 'EST', descr: 'Estero', link_grp: '', link_telegram: ''},
{_id: 113, reg: 'ONL', prov: 'ONL', descr: 'On Line', link_grp: '', link_telegram: ''},
{_id: 114, reg: 'LAZ', prov: 'RM', descr: 'Roma Nord-Est', link_grp: 'https://t.me/c/1614195634/64?thread=57', link_telegram: ''},
{_id: 115, reg: 'LAZ', prov: 'RM', descr: 'Roma Sud-Est', link_grp: 'https://t.me/c/1614195634/65?thread=58', link_telegram: ''},
{_id: 116, reg: 'LAZ', prov: 'RM', descr: 'Roma Nord', link_grp: 'https://t.me/c/1614195634/75?thread=73', link_telegram: ''},
{_id: 117, reg: 'LAZ', prov: 'RM', descr: 'Roma Nord-Ovest', link_grp: 'https://t.me/c/1614195634/62?thread=47', link_telegram: ''},
{_id: 118, reg: 'LAZ', prov: 'RM', descr: 'Roma Sud e Litorale', link_grp: 'https://t.me/c/1614195634/67?thread=43', link_telegram: ''},
{_id: 114, reg: 'LAZ', prov: 'RM', descr: 'Roma Nord-Est', card: 'NORD-EST', link_grp: 'https://t.me/c/1614195634/64?thread=57', link_telegram: ''},
{_id: 115, reg: 'LAZ', prov: 'RM', descr: 'Roma Sud-Est', card: 'SUD-EST', link_grp: 'https://t.me/c/1614195634/65?thread=58', link_telegram: ''},
{_id: 116, reg: 'LAZ', prov: 'RM', descr: 'Roma Nord', card: 'NORD', link_grp: 'https://t.me/c/1614195634/75?thread=73', link_telegram: ''},
{_id: 117, reg: 'LAZ', prov: 'RM', descr: 'Roma Nord-Ovest', card: 'NORD-OVEST', link_grp: 'https://t.me/c/1614195634/62?thread=47', link_telegram: ''},
{_id: 118, reg: 'LAZ', prov: 'RM', descr: 'Roma Sud e Litorale', card: 'SUD', link_grp: 'https://t.me/c/1614195634/67?thread=43', link_telegram: ''},
{_id: 119, reg: 'PUG', prov: 'VAL', descr: 'Valle D\'Itria', link_grp: 'https://t.me/progettoriso/7016?thread=7015', link_telegram: ''},
{_id: 120, reg: 'SAR', prov: 'SUS', descr: 'Sud Sardegna', link_grp: 'https://t.me/c/1614195634/552?thread=545', link_telegram: ''},
{_id: 121, reg: 'ITA', prov: 'ITA', descr: 'Italia', link_grp: '', link_telegram: ''},
{_id: 122, reg: 'LOM', prov: 'MI', card: 'EST', descr: 'Milano Est', link_grp: '', link_telegram: ''},
],
};

View File

@@ -360,7 +360,7 @@ router.post('/settable', authenticate, async (req, res) => {
const mytablestrutt = globalTables.getTableByTableName(params.table);
if (mydata['_id'] !== undefined && mydata['_id'] !== 0) {
if (mydata['_id'] !== undefined && mydata['_id'] !== 0 && mydata['_id'] !== '') {
mytablerec.isNew = false;
}
@@ -952,8 +952,9 @@ router.patch('/chval', authenticate, async (req, res) => {
if (mydata.table === 'users') {
if ('profile.resid_province' in fieldsvalue) {
const card = fieldsvalue.hasOwnProperty('profile.resid_card') ? fieldsvalue['profile.resid_card'] : '';
// Controlla se esiste il Circuito di questa provincia, se non esiste lo crea!
await Circuit.createCircuitIfNotExist(req, idapp, fieldsvalue['profile.resid_province']);
await Circuit.createCircuitIfNotExist(req, idapp, fieldsvalue['profile.resid_province'], card);
}
if (camporequisiti) {

View File

@@ -762,6 +762,7 @@ module.exports = {
'profile.mycircuits': 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
'profile.resid_card': 1,
'profile.username_telegram': 1,
'profile.favorite': 1,
'profile.bookmark': 1,