- Poter impostare per ogni Provincia un Circuito RIS specifico, anziché quello provinciale:

Esempio: Napoli: (Circuito RIS Campania) e Sud Sardegna: Cagliari.
This commit is contained in:
Surya Paolo
2025-07-21 19:08:43 +02:00
parent e118c30f47
commit a189aeb99c
5 changed files with 62 additions and 61 deletions

View File

@@ -13,53 +13,55 @@ const { ObjectId } = require('mongodb');
const shared_consts = require('../tools/shared_nodejs');
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
mongoose.plugin((schema) => {
schema.options.usePushEach = true;
});
const ProvinceSchema = new Schema({
_id: {
type: Number,
},
reg: {
type: String,
},
prov: {
type: String,
// unique: true,
maxlength: 3,
},
descr: {
type: String,
},
link_grp: {
type: String,
},
card: {
type: String,
},
const ProvinceSchema = new Schema(
{
_id: {
type: Number,
},
reg: {
type: String,
},
prov: {
type: String,
// unique: true,
maxlength: 3,
},
idCircuitToAssign: {
type: String,
},
descr: {
type: String,
},
link_grp: {
type: String,
},
card: {
type: String,
},
link_telegram: {
type: String,
link_telegram: {
type: String,
},
lat: {
type: Number,
},
long: {
type: Number,
},
},
lat: {
type: Number,
},
long: {
type: Number,
},
}, { _id: false });
{ _id: false }
);
ProvinceSchema.pre('save', async function (next) {
if (this.isNew) {
const myrec = await Province.findOne().limit(1).sort({ _id: -1 });
if (!!myrec) {
if (myrec._doc._id === 0)
this._id = 1;
else
this._id = myrec._doc._id + 1;
if (myrec._doc._id === 0) this._id = 1;
else this._id = myrec._doc._id + 1;
} else {
this._id = 1;
}
@@ -75,7 +77,7 @@ ProvinceSchema.statics.getRegionByStrProvince = async function (strprovince) {
}
return '';
}
};
ProvinceSchema.statics.getStrProvinceByProv = async function (prov) {
const myrec = await Province.findOne({ prov }).lean();
@@ -84,7 +86,7 @@ ProvinceSchema.statics.getStrProvinceByProv = async function (prov) {
}
return '';
}
};
ProvinceSchema.statics.getFieldsForSearch = function () {
return [
@@ -106,7 +108,6 @@ ProvinceSchema.statics.executeQueryTable = function (idapp, params) {
};
ProvinceSchema.statics.executeQueryPickup = async function (idapp, params) {
const strfind = params.search;
if (strfind === '') {
@@ -123,7 +124,6 @@ ProvinceSchema.statics.executeQueryPickup = async function (idapp, params) {
const ris = await Province.find(filterfind).lean().limit(10);
return [...risexact, ...ris];
};
ProvinceSchema.statics.findAllIdApp = async function (idapp) {
@@ -133,7 +133,6 @@ ProvinceSchema.statics.findAllIdApp = async function (idapp) {
};
ProvinceSchema.statics.setCoordinatesOnDB = async function () {
const arrprov = await Province.find({}).lean();
// Funzione per ottenere le coordinate di tutte le città
@@ -141,20 +140,23 @@ ProvinceSchema.statics.setCoordinatesOnDB = async function () {
if (!prov.lat) {
let coord = await tools.getCityCoordinates(prov);
if (coord) {
let ris = await Province.findOneAndUpdate({ _id: prov._id }, { $set: { lat: coord.lat, long: coord.long } }, { new: true });
let ris = await Province.findOneAndUpdate(
{ _id: prov._id },
{ $set: { lat: coord.lat, long: coord.long } },
{ new: true }
);
console.log(' *** Update ', prov.descr, 'lat', ris.lat, 'long', ris.long);
}
}
}
};
const Province = mongoose.model('Province', ProvinceSchema);
Province.createIndexes()
.then(() => { })
.catch((err) => { throw err; });
.then(() => {})
.catch((err) => {
throw err;
});
module.exports = { Province };