Aggiunto il filtro per Provincia
This commit is contained in:
@@ -10,6 +10,8 @@ const tools = require('../tools/general');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true;
|
||||
@@ -111,8 +113,15 @@ CitySchema.statics.executeQueryPickup = async function(idapp, params) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const ris = await City.find({ comune: { $regex : '^' + strfind, $options: 'i' } }, {comune: 1, prov: 1, reg: 1}).lean();
|
||||
return ris;
|
||||
let filterfindexact = {comune: strfind};
|
||||
const risexact = await City.find(filterfindexact, {comune: 1, prov: 1, reg: 1}).lean();
|
||||
|
||||
let filterfind = {comune: {$regex: '^' + strfind, $options: 'i'}};
|
||||
|
||||
const ris = await City.find(filterfind, {comune: 1, prov: 1, reg: 1}).lean().limit(10);
|
||||
|
||||
|
||||
return [...risexact, ...ris];
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -35,6 +35,9 @@ const MySkillSchema = new Schema({
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
idSector: {
|
||||
type: Number,
|
||||
},
|
||||
idContribType: [
|
||||
{
|
||||
type: String,
|
||||
@@ -108,10 +111,11 @@ MySkillSchema.statics.findAllIdApp = async function(idapp) {
|
||||
};
|
||||
|
||||
MySkillSchema.statics.getFieldsForSearch = function() {
|
||||
return [{field: 'idSkill', type: tools.FieldType.Number}
|
||||
,{field: 'note', type: tools.FieldType.String}
|
||||
,{field: 'subTitle', type: tools.FieldType.String}
|
||||
];
|
||||
return [
|
||||
{field: 'idSkill', type: tools.FieldType.Number}
|
||||
, {field: 'note', type: tools.FieldType.String}
|
||||
, {field: 'subTitle', type: tools.FieldType.String},
|
||||
];
|
||||
};
|
||||
|
||||
MySkillSchema.statics.executeQueryTable = function(idapp, params) {
|
||||
@@ -145,7 +149,7 @@ MySkillSchema.statics.executeQueryTable = function(idapp, params) {
|
||||
},
|
||||
};
|
||||
|
||||
params = { ...params, ...otherparams };
|
||||
params = {...params, ...otherparams};
|
||||
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
83
src/server/models/province.js
Executable file
83
src/server/models/province.js
Executable file
@@ -0,0 +1,83 @@
|
||||
const mongoose = require('mongoose').set('debug', false);
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const escapeStringRegexp = require('escape-string-regexp');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = 'F';
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true;
|
||||
});
|
||||
|
||||
const ProvinceSchema = new Schema({
|
||||
_id: {
|
||||
type: Number,
|
||||
},
|
||||
prov: {
|
||||
type: String,
|
||||
unique: true,
|
||||
maxlength: 3,
|
||||
},
|
||||
descr: {
|
||||
type: String,
|
||||
},
|
||||
}, { _id : false });
|
||||
|
||||
|
||||
ProvinceSchema.statics.getFieldsForSearch = function() {
|
||||
return [
|
||||
{field: 'prov', type: tools.FieldType.string},
|
||||
{field: 'descr', type: tools.FieldType.string},
|
||||
];
|
||||
};
|
||||
|
||||
ProvinceSchema.statics.executeQueryTable = function(idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
|
||||
const strfind = params.search;
|
||||
|
||||
if (strfind === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
return tools.executeQueryTable(this, 0, params);
|
||||
};
|
||||
|
||||
ProvinceSchema.statics.executeQueryPickup = async function(idapp, params) {
|
||||
|
||||
const strfind = params.search;
|
||||
|
||||
if (strfind === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
let filterfindexact = {descr: strfind};
|
||||
const risexact = await Province.find(filterfindexact).lean();
|
||||
|
||||
let filterfind = {};
|
||||
|
||||
filterfind = {descr: {$regex: '^' + strfind, $options: 'i'}};
|
||||
|
||||
const ris = await Province.find(filterfind).lean().limit(10);
|
||||
|
||||
return [...risexact, ...ris];
|
||||
|
||||
};
|
||||
|
||||
ProvinceSchema.statics.findAllIdApp = async function(idapp) {
|
||||
const myfind = {};
|
||||
|
||||
return Province.find(myfind);
|
||||
};
|
||||
|
||||
const Province = mongoose.model('Province', ProvinceSchema);
|
||||
|
||||
module.exports = {Province};
|
||||
@@ -35,9 +35,6 @@ const SectorSchema = new Schema({
|
||||
theme: {
|
||||
type: String,
|
||||
},
|
||||
main: {
|
||||
type: Boolean,
|
||||
}
|
||||
});
|
||||
|
||||
SectorSchema.pre('save', async function (next) {
|
||||
|
||||
@@ -47,6 +47,9 @@ const UserSchema = new mongoose.Schema({
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
group: {
|
||||
type: Number,
|
||||
},
|
||||
index: {
|
||||
type: Number,
|
||||
},
|
||||
@@ -222,6 +225,9 @@ const UserSchema = new mongoose.Schema({
|
||||
username_telegram: {
|
||||
type: String,
|
||||
},
|
||||
website: {
|
||||
type: String,
|
||||
},
|
||||
teleg_id: {
|
||||
type: Number,
|
||||
},
|
||||
@@ -1196,6 +1202,7 @@ UserSchema.statics.getUserProfileByUsername = async function(idapp, username) {
|
||||
'profile.biografia': 1,
|
||||
'profile.teleg_id': 1,
|
||||
'profile.username_telegram': 1,
|
||||
'profile.website': 1,
|
||||
'profile.img': 1,
|
||||
'profile.sex': 1,
|
||||
'profile.dateofbirth': 1,
|
||||
@@ -1414,6 +1421,7 @@ function getWhatToShow(idapp, username) {
|
||||
'profile.qualifica': 1,
|
||||
'profile.biografia': 1,
|
||||
'profile.username_telegram': 1,
|
||||
'profile.website': 1,
|
||||
'profile.img': 1,
|
||||
'profile.sex': 1,
|
||||
'profile.dateofbirth': 1,
|
||||
|
||||
Reference in New Issue
Block a user