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

67
src/server/models/adtypegood.js Executable file
View File

@@ -0,0 +1,67 @@
const mongoose = require('mongoose').set('debug', false);
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
mongoose.level = "";
const tools = require('../tools/general');
const {ObjectID} = require('mongodb');
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true;
});
const AdTypeGoodSchema = new Schema({
_id: {
type: Number,
},
descr: {
type: String,
},
});
AdTypeGoodSchema.pre('save', async function (next) {
if (this.isNew) {
const myrec = await AdTypeGood.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();
});
AdTypeGoodSchema.statics.findAllIdApp = async function(idapp) {
const AdTypeGood = this;
const query = [
{$sort: {_id: 1}},
];
return AdTypeGood.aggregate(query).then((arrrec) => {
return arrrec;
});
};
AdTypeGoodSchema.statics.getFieldsForSearch = function() {
return [
{field: 'descr', type: tools.FieldType.string}];
};
AdTypeGoodSchema.statics.executeQueryTable = function(idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, 0, params);
};
const AdTypeGood = mongoose.model('AdTypeGood', AdTypeGoodSchema);
module.exports = {AdTypeGood};

View File

@@ -109,16 +109,29 @@ CitySchema.statics.executeQueryPickup = async function(idapp, params) {
const strfind = params.search;
if (strfind === '') {
if (strfind === '' && !params.filter) {
return [];
}
let filterfindexact = {comune: strfind};
const risexact = await City.find(filterfindexact, {comune: 1, prov: 1, reg: 1}).lean();
let filterfindexact = {};
if (strfind){
filterfindexact = {comune: strfind};
}
let limit = 10
let risexact = []
let filterfind = {comune: {$regex: '^' + strfind, $options: 'i'}};
let ris = await City.find(filterfind, {comune: 1, prov: 1, reg: 1}).lean().limit(10);
if (params.filter) {
filterfind = {...params.filter, ...filterfind}
limit = 200
} else{
risexact = await City.find(filterfindexact, {comune: 1, prov: 1, reg: 1}).lean();
}
let ris = await City.find(filterfind, {comune: 1, prov: 1, reg: 1}).lean().limit(limit);
return [...risexact, ...ris];

83
src/server/models/good.js Executable file
View File

@@ -0,0 +1,83 @@
const mongoose = require('mongoose').set('debug', false)
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
mongoose.level = "F";
const tools = require('../tools/general');
const { ObjectID } = require('mongodb');
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
const GoodSchema = new Schema({
_id: {
type: Number,
},
descr: {
type: String,
},
idSectorGood: [{
type: Number
}],
icon: {
type: String,
},
img: {
type: String,
},
});
GoodSchema.statics.findAllIdApp = async function (idapp) {
const Good = this;
const query = [
{ $sort: { descr: 1 } }
];
const res = Good
.aggregate(query)
.then((arrrec) => {
return arrrec
})
return res;
};
GoodSchema.pre('save', async function (next) {
if (this.isNew) {
const myrec = await Good.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();
});
GoodSchema.statics.getFieldsForSearch = function () {
return [{ field: 'label', type: tools.FieldType.string },
{ field: 'descr', type: tools.FieldType.string }]
};
GoodSchema.statics.executeQueryTable = function (idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, 0, params);
};
const Good = mongoose.model('Good', GoodSchema);
module.exports = { Good };

View File

@@ -29,11 +29,6 @@ const MyBachecaSchema = new Schema({
type: Number,
default: 0,
},
idSubSkill: [
{
type: Number,
default: 0,
}],
idStatusSkill: [
{
type: Number,
@@ -361,14 +356,14 @@ MyBachecaSchema.statics.getMyRecById = function(idapp, id) {
'profile.qualifica': 1,
},
},
{
/*{
'$lookup': {
'from': 'subskills',
'localField': 'idSubSkill',
'foreignField': '_id',
'as': 'MyBacheca',
},
},
},*/
{
'$replaceRoot': {
'newRoot': {
@@ -390,7 +385,7 @@ MyBachecaSchema.statics.getMyRecById = function(idapp, id) {
'sector': 1,
'idSector': 1,
'idSkill': 1,
'idSubSkill': 1,
// 'idSubSkill': 1,
'idStatusSkill': 1,
'idContribType': 1,
'idCity': 1,
@@ -442,7 +437,7 @@ MyBachecaSchema.statics.getMyRecById = function(idapp, id) {
'sector': 1,
'idSector': 1,
'idSkill': 1,
'idSubSkill': 1,
// 'idSubSkill': 1,
'idStatusSkill': 1,
'idContribType': 1,
'idCity': 1,

481
src/server/models/mygood.js Executable file
View File

@@ -0,0 +1,481 @@
const mongoose = require('mongoose').set('debug', false);
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
mongoose.level = 'F';
const tools = require('../tools/general');
const {ObjectID} = require('mongodb');
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true;
});
const MyGoodSchema = new Schema({
_id: {
type: Number,
},
idapp: {
type: String,
required: true,
},
userId: {type: Schema.Types.ObjectId, ref: 'User'},
idSectorGood: {
type: Number,
},
idGood: {
type: Number,
default: 0,
},
idShipping: [
{
type: Number,
}],
idContribType: [
{
type: String,
}],
idCity: [
{
type: Number,
}],
numLevel: {
type: Number,
default: 0,
},
adType: {
type: Number,
},
photos: [
{
imagefile: {
type: String,
},
alt: {
type: String,
},
description: {
type: String,
},
}],
note: {
type: String,
default: '',
},
descr: {
type: String,
},
//**ADDFIELD_MyGood
website: {
type: String,
},
date_created: {
type: Date,
default: Date.now,
},
date_updated: {
type: Date,
default: Date.now,
},
});
MyGoodSchema.pre('save', async function(next) {
if (this.isNew) {
const myrec = await MyGood.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;
}
this.date_created = new Date();
}
next();
});
MyGoodSchema.statics.findAllIdApp = async function(idapp) {
const MyGood = this;
const query = [
{$match: {idapp}},
{$sort: {descr: 1}},
];
return MyGood.aggregate(query).then((arrrec) => {
return arrrec;
});
};
MyGoodSchema.statics.getFieldsForSearch = function() {
return [];
};
MyGoodSchema.statics.getFieldsLastForSearch = function() {
return [
{field: 'note', type: tools.FieldType.string},
{field: 'descr', type: tools.FieldType.string},
{field: 'recGood.descr', type: tools.FieldType.string},
{field: 'MyGood.descr', type: tools.FieldType.string},
];
};
MyGoodSchema.statics.executeQueryTable = function(idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
params.fieldsearch_last = this.getFieldsLastForSearch();
const otherparams = {
lookup1: {
lk_tab: 'users',
lk_LF: 'userId',
lk_FF: '_id',
lk_as: 'user',
af_objId_tab: 'myId',
lk_proj: {
idGood: 1,
idShipping: 1,
MyGood: 1,
idStatusGood: 1,
idContribType: 1,
idCity: 1,
numLevel: 1,
adType: 1,
photos: 1,
note: 1,
website: 1,
//**ADDFIELD_MyGood
descr: 1,
date_created: 1,
date_updated: 1,
userId: 1,
username: 1,
name: 1,
surname: 1,
'profile.img': 1,
'profile.qualifica': 1,
},
},
};
params = {...params, ...otherparams};
return tools.executeQueryTable(this, idapp, params);
};
MyGoodSchema.statics.getMyGoodById = function(idapp, idGood) {
const MyGood = this;
const query = [
{
'$match': {
'$and': [
{
'_id': parseInt(idGood),
},
],
},
},
{
'$match': {
'idapp': idapp,
},
},
{
'$sort': {
'desc': 1,
},
},
{
'$addFields': {
'myId1': {
'$toObjectId': '$userId',
},
},
},
{
'$lookup': {
'from': 'users',
'localField': 'myId1',
'foreignField': '_id',
'as': 'user',
},
},
{
'$replaceRoot': {
'newRoot': {
'$mergeObjects': [
{
'$arrayElemAt': [
'$user',
0,
],
},
'$$ROOT',
],
},
},
},
{
'$project': {
'recGood': 1,
'sectorgood': 1,
'idSectorGood': 1,
'idGood': 1,
'idShipping': 1,
'idStatusGood': 1,
'idContribType': 1,
'idCity': 1,
'numLevel': 1,
adType: 1,
'photos': 1,
note: 1,
website: 1,
//**ADDFIELD_MyGood
'descr': 1,
'date_created': 1,
'date_updated': 1,
'userId': 1,
'username': 1,
'name': 1,
'surname': 1,
'comune': 1,
'mycities': 1,
'profile.img': 1,
'profile.qualifica': 1,
},
},
{
'$lookup': {
'from': 'goods',
'localField': 'idGood',
'foreignField': '_id',
'as': 'recGood',
},
},
{
'$replaceRoot': {
'newRoot': {
'$mergeObjects': [
{
'$arrayElemAt': [
'$recGood',
0,
],
},
'$$ROOT',
],
},
},
},
{
'$project': {
'recGood': 1,
'sectorgood': 1,
'idSectorGood': 1,
'idGood': 1,
'idShipping': 1,
'idStatusGood': 1,
'idContribType': 1,
'idCity': 1,
'numLevel': 1,
adType: 1,
'photos': 1,
'note': 1,
website: 1,
//**ADDFIELD_MyGood
'descr': 1,
'date_created': 1,
'date_updated': 1,
'userId': 1,
'username': 1,
'name': 1,
'surname': 1,
'comune': 1,
'mycities': 1,
'profile.img': 1,
'profile.qualifica': 1,
},
},
{
'$lookup': {
'from': 'sectorgoods',
'localField': 'recGood.idSectorGood',
'foreignField': '_id',
'as': 'sectorgood',
},
},
{
'$replaceRoot': {
'newRoot': {
'$mergeObjects': [
{
'$arrayElemAt': [
'$sectorgood',
0,
],
},
'$$ROOT',
],
},
},
},
{
'$project': {
'recGood': 1,
'sectorgood': 1,
'idSectorGood': 1,
'idGood': 1,
'idShipping': 1,
'idStatusGood': 1,
'idContribType': 1,
'idCity': 1,
'numLevel': 1,
adType: 1,
'photos': 1,
'note': 1,
website: 1,
//**ADDFIELD_MyGood
'descr': 1,
'date_created': 1,
'date_updated': 1,
'userId': 1,
'username': 1,
'name': 1,
'surname': 1,
'comune': 1,
'mycities': 1,
'profile.img': 1,
'profile.qualifica': 1,
},
},
{
'$lookup': {
'from': 'subgoods',
'localField': 'idShipping',
'foreignField': '_id',
'as': 'MyGood',
},
},
{
'$replaceRoot': {
'newRoot': {
'$mergeObjects': [
{
'$arrayElemAt': [
'$MyGood',
0,
],
},
'$$ROOT',
],
},
},
},
{
'$project': {
'recGood': 1,
'sectorgood': 1,
'idSectorGood': 1,
'idGood': 1,
'idShipping': 1,
'idStatusGood': 1,
'idContribType': 1,
'idCity': 1,
'numLevel': 1,
adType: 1,
'photos': 1,
'note': 1,
website: 1,
//**ADDFIELD_MyGood
'descr': 1,
'date_created': 1,
'date_updated': 1,
'userId': 1,
'username': 1,
'name': 1,
'surname': 1,
'comune': 1,
'mycities': 1,
'profile.img': 1,
'profile.qualifica': 1,
},
},
{
'$lookup': {
'from': 'cities',
'localField': 'idCity',
'foreignField': '_id',
'as': 'mycities',
},
},
{
'$replaceRoot': {
'newRoot': {
'$mergeObjects': [
{
'$arrayElemAt': [
'$mycities',
0,
],
},
'$$ROOT',
],
},
},
},
{
'$project': {
'recGood': 1,
'sectorgood': 1,
'idSectorGood': 1,
'idGood': 1,
'idShipping': 1,
'idStatusGood': 1,
'idContribType': 1,
'idCity': 1,
'numLevel': 1,
adType: 1,
'photos': 1,
'note': 1,
website: 1,
//**ADDFIELD_MyGood
'descr': 1,
'date_created': 1,
'date_updated': 1,
'userId': 1,
'username': 1,
'name': 1,
'surname': 1,
'comune': 1,
'mycities': 1,
'profile.img': 1,
'profile.qualifica': 1,
},
},
];
return MyGood.aggregate(query).then((rec) => {
return rec ? rec[0] : null;
});
};
MyGoodSchema.statics.getCompleteRecord = function(idapp, id) {
const MyGood = this;
return MyGood.getMyGoodById(idapp, id);
};
const MyGood = mongoose.model('MyGood', MyGoodSchema);
module.exports = {MyGood};

View File

@@ -106,9 +106,10 @@ MyGroupSchema.statics.executeQueryTable = function(idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
if (params.options) {
if (tools.isBitActive(params.options,
shared_consts.OPTIONS_SEARCH_USER_ONLY_FULL_WORDS)) {
if (tools.isBitActive(params.options, shared_consts.OPTIONS_SEARCH_USER_ONLY_FULL_WORDS)) {
params.fieldsearch = User.getFieldsForSearchUserFriend();
} else if (tools.isBitActive(params.options, shared_consts.OPTIONS_SEARCH_USER_ALL_WORDS)) {
params.fieldsearch = User.getFieldsForSearchUserFriend_AllWords();
}
}

View File

@@ -29,11 +29,13 @@ const MySkillSchema = new Schema({
type: Number,
default: 0,
},
idSubSkill: [
/*idSubSkill: [
{
type: Number,
default: 0,
}],
*/
idStatusSkill: [
{
type: Number,
@@ -146,7 +148,7 @@ MySkillSchema.statics.executeQueryTable = function(idapp, params) {
af_objId_tab: 'myId',
lk_proj: {
idSkill: 1,
idSubSkill: 1,
// idSubSkill: 1,
myskill: 1,
idStatusSkill: 1,
idContribType: 1,
@@ -234,7 +236,7 @@ MySkillSchema.statics.getMySkillByIdkill = function(idapp, idSkill) {
'sector': 1,
'idSector': 1,
'idSkill': 1,
'idSubSkill': 1,
// 'idSubSkill': 1,
'idStatusSkill': 1,
'idContribType': 1,
'idCity': 1,
@@ -286,7 +288,7 @@ MySkillSchema.statics.getMySkillByIdkill = function(idapp, idSkill) {
'sector': 1,
'idSector': 1,
'idSkill': 1,
'idSubSkill': 1,
// 'idSubSkill': 1,
'idStatusSkill': 1,
'idContribType': 1,
'idCity': 1,
@@ -338,7 +340,7 @@ MySkillSchema.statics.getMySkillByIdkill = function(idapp, idSkill) {
'sector': 1,
'idSector': 1,
'idSkill': 1,
'idSubSkill': 1,
//'idSubSkill': 1,
'idStatusSkill': 1,
'idContribType': 1,
'idCity': 1,
@@ -361,7 +363,7 @@ MySkillSchema.statics.getMySkillByIdkill = function(idapp, idSkill) {
'profile.qualifica': 1,
},
},
{
/*{
'$lookup': {
'from': 'subskills',
'localField': 'idSubSkill',
@@ -369,6 +371,8 @@ MySkillSchema.statics.getMySkillByIdkill = function(idapp, idSkill) {
'as': 'myskill',
},
},
*/
{
'$replaceRoot': {
'newRoot': {
@@ -390,7 +394,7 @@ MySkillSchema.statics.getMySkillByIdkill = function(idapp, idSkill) {
'sector': 1,
'idSector': 1,
'idSkill': 1,
'idSubSkill': 1,
// 'idSubSkill': 1,
'idStatusSkill': 1,
'idContribType': 1,
'idCity': 1,
@@ -442,7 +446,7 @@ MySkillSchema.statics.getMySkillByIdkill = function(idapp, idSkill) {
'sector': 1,
'idSector': 1,
'idSkill': 1,
'idSubSkill': 1,
// 'idSubSkill': 1,
'idStatusSkill': 1,
'idContribType': 1,
'idCity': 1,

83
src/server/models/sectorgood.js Executable file
View File

@@ -0,0 +1,83 @@
const mongoose = require('mongoose').set('debug', false)
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
mongoose.level = "F";
const tools = require('../tools/general');
const { ObjectID } = require('mongodb');
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
const SectorGoodSchema = new Schema({
_id: {
type: Number,
},
descr: {
type: String,
},
idSectorGood: {
type: Number
},
icon: {
type: String,
},
img: {
type: String,
},
color: {
type: String,
},
theme: {
type: String,
},
});
SectorGoodSchema.pre('save', async function (next) {
if (this.isNew) {
const myrec = await SectorGood.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();
});
SectorGoodSchema.statics.findAllIdApp = async function (idapp) {
const SectorGood = this;
const query = [
{ $sort: { descr: 1 } }
];
return SectorGood
.aggregate(query)
.then((arrrec) => {
return arrrec
})
};
SectorGoodSchema.statics.getFieldsForSearch = function () {
return [{ field: 'descr', type: tools.FieldType.string }]
};
SectorGoodSchema.statics.executeQueryTable = function (idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, 0, params);
};
const SectorGood = mongoose.model('SectorGood', SectorGoodSchema);
module.exports = { SectorGood };

View File

@@ -21,6 +21,9 @@ const StatusSkillSchema = new Schema({
color: {
type: String,
},
icon: {
type: String,
},
theme: {
type: String,
},

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