Aggiunto il filtro per Provincia

This commit is contained in:
paoloar77
2022-01-23 23:25:34 +01:00
parent 66eaca6d41
commit 632534eed1
15 changed files with 89399 additions and 24 deletions

83
src/server/models/province.js Executable file
View 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};