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

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