Campo Citta di Nascita (nel profilo nuova maniera), manca ancora da sistemare l'edit

Se seleziono la Provincia , mi deve comparire la lista dei comuni
This commit is contained in:
paoloar77
2022-02-21 13:12:27 +01:00
parent 9aa7518e31
commit 50c3018baa
33 changed files with 1402 additions and 369 deletions

View File

@@ -260,6 +260,9 @@ const UserSchema = new mongoose.Schema({
type: String,
trim: true,
},
born_city_id: {
type: Number,
},
born_province: {
type: String,
trim: true,
@@ -1217,7 +1220,7 @@ UserSchema.statics.getUserProfileByUsername = async function(
'profile.img': 1,
'profile.sex': 1,
'profile.dateofbirth': 1,
'profile.born_city': 1,
'profile.born_city_id': 1,
'profile.born_province': 1,
'profile.born_country': 1,
email: 1,
@@ -1245,23 +1248,72 @@ UserSchema.statics.getUserProfileByUsername = async function(
'profile.img': 1,
'profile.sex': 1,
'profile.dateofbirth': 1,
'profile.born_city': 1,
'profile.born_city_id': 1,
'profile.born_province': 1,
'profile.born_country': 1,
'mycities': 1,
'comune': 1,
email: 1,
date_reg: 1,
};
}
return User.findOne({
const myfind = {
idapp, username,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
};
const query = [
{$match: myfind},
{
$lookup: {
from: 'cities',
localField: 'profile.born_city_id',
foreignField: '_id',
as: 'mycities',
},
},
{
'$replaceRoot': {
'newRoot': {
'$mergeObjects': [
{
'$arrayElemAt': [
'$mycities',
0,
],
},
'$$ROOT',
],
},
},
},
{$project: whatToShow},
];
try {
const ris = await User.aggregate(query);
if (ris && ris.length > 0)
return ris[0];
} catch (e) {
return null;
}
return null;
/*
return User.findOne({
}, whatToShow).then((rec) => {
return (rec._doc);
}).catch((e) => {
return null;
});
*/
};
UserSchema.statics.getArrUsernameFromFieldByUsername = async function(
@@ -1417,7 +1469,8 @@ UserSchema.statics.setFriendsCmd = async function(
}
if (ris) {
// Invia una notifica alla persona
tools.sendNotificationByUsername(idapp, usernameDest, cmd, true, usernameOrig);
tools.sendNotificationByUsername(idapp, usernameDest, cmd, true,
usernameOrig);
}
} else {
if (foundIfAlreadyAskFriend) {
@@ -1587,7 +1640,7 @@ function getWhatToShow(idapp, username) {
'profile.img': 1,
'profile.sex': 1,
'profile.dateofbirth': 1,
'profile.born_city': 1,
'profile.born_city_id': 1,
'profile.born_province': 1,
'profile.born_country': 1,
email: 1,
@@ -2218,12 +2271,19 @@ UserSchema.statics.getFieldsForSearchUserFriend = function() {
return [{field: 'username', type: tools.FieldType.exact}];
};
UserSchema.statics.getFieldsForSearchUserFriend_AllWords = function() {
return [{field: 'username', type: tools.FieldType.string}];
};
UserSchema.statics.executeQueryTable = function(idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
if (params.options) {
if (tools.isBitActive(params.options,
shared_consts.OPTIONS_SEARCH_ONLY_FULL_WORDS)) {
shared_consts.OPTIONS_SEARCH_USER_ONLY_FULL_WORDS)) {
params.fieldsearch = this.getFieldsForSearchUserFriend();
} else if (tools.isBitActive(params.options,
shared_consts.OPTIONS_SEARCH_USER_ALL_WORDS)) {
params.fieldsearch = this.getFieldsForSearchUserFriend_AllWords();
}
}
return tools.executeQueryTable(this, idapp, params);
@@ -2557,25 +2617,31 @@ UserSchema.statics.checkUser = async function(idapp, username) {
UserSchema.statics.calculateStat = async function(idapp, username) {
const User = this;
const {MySkill} = require('../models/myskill');
const {MyBacheca} = require('../models/mybacheca');
const {MyGroup} = require('../models/mygroup');
try {
const {MySkill} = require('../models/myskill');
const {MyGood} = require('../models/mygood');
const {MyBacheca} = require('../models/mybacheca');
const {MyGroup} = require('../models/mygroup');
const numUsersReg = await User.countDocuments(
{
idapp,
$or: [
{deleted: {$exists: false}},
{deleted: {$exists: true, $eq: false}}],
});
const numUsersReg = await User.countDocuments(
{
idapp,
$or: [
{deleted: {$exists: false}},
{deleted: {$exists: true, $eq: false}}],
});
const numMySkills = await MySkill.countDocuments({idapp});
const numMySkills = await MySkill.countDocuments({idapp});
const numMyGoods = await MyGood.countDocuments({idapp});
const numMyBachecas = await MyBacheca.countDocuments({idapp});
const numMyBachecas = await MyBacheca.countDocuments({idapp});
const numGroups = await MyGroup.countDocuments({idapp});
const numGroups = await MyGroup.countDocuments({idapp});
return {numMySkills, numMyBachecas, numUsersReg, numGroups};
return {numMySkills, numMyGoods, numMyBachecas, numUsersReg, numGroups};
} catch (e) {
console.error(e.message);
}
};