- fixed quantità
- creazione mappa numero utenti per provincia !
This commit is contained in:
@@ -8,7 +8,7 @@ mongoose.level = 'F';
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
@@ -35,18 +35,25 @@ const ProvinceSchema = new Schema({
|
||||
link_grp: {
|
||||
type: String,
|
||||
},
|
||||
card : {
|
||||
card: {
|
||||
type: String,
|
||||
},
|
||||
|
||||
|
||||
link_telegram: {
|
||||
type: String,
|
||||
},
|
||||
}, { _id : false });
|
||||
lat: {
|
||||
type: Number,
|
||||
},
|
||||
long: {
|
||||
type: Number,
|
||||
},
|
||||
|
||||
}, { _id: false });
|
||||
|
||||
ProvinceSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
const myrec = await Province.findOne().limit(1).sort({_id:-1});
|
||||
const myrec = await Province.findOne().limit(1).sort({ _id: -1 });
|
||||
if (!!myrec) {
|
||||
if (myrec._doc._id === 0)
|
||||
this._id = 1;
|
||||
@@ -61,8 +68,8 @@ ProvinceSchema.pre('save', async function (next) {
|
||||
next();
|
||||
});
|
||||
|
||||
ProvinceSchema.statics.getRegionByStrProvince = async function(strprovince) {
|
||||
const myrec = await Province.findOne({prov: strprovince}).lean();
|
||||
ProvinceSchema.statics.getRegionByStrProvince = async function (strprovince) {
|
||||
const myrec = await Province.findOne({ prov: strprovince }).lean();
|
||||
if (myrec) {
|
||||
return myrec.reg;
|
||||
}
|
||||
@@ -70,8 +77,8 @@ ProvinceSchema.statics.getRegionByStrProvince = async function(strprovince) {
|
||||
return '';
|
||||
}
|
||||
|
||||
ProvinceSchema.statics.getStrProvinceByProv = async function(prov) {
|
||||
const myrec = await Province.findOne({prov}).lean();
|
||||
ProvinceSchema.statics.getStrProvinceByProv = async function (prov) {
|
||||
const myrec = await Province.findOne({ prov }).lean();
|
||||
if (myrec) {
|
||||
return myrec.descr;
|
||||
}
|
||||
@@ -79,14 +86,14 @@ ProvinceSchema.statics.getStrProvinceByProv = async function(prov) {
|
||||
return '';
|
||||
}
|
||||
|
||||
ProvinceSchema.statics.getFieldsForSearch = function() {
|
||||
ProvinceSchema.statics.getFieldsForSearch = function () {
|
||||
return [
|
||||
{field: 'prov', type: tools.FieldType.string},
|
||||
{field: 'descr', type: tools.FieldType.string},
|
||||
{ field: 'prov', type: tools.FieldType.string },
|
||||
{ field: 'descr', type: tools.FieldType.string },
|
||||
];
|
||||
};
|
||||
|
||||
ProvinceSchema.statics.executeQueryTable = function(idapp, params) {
|
||||
ProvinceSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
|
||||
const strfind = params.search;
|
||||
@@ -98,7 +105,7 @@ ProvinceSchema.statics.executeQueryTable = function(idapp, params) {
|
||||
return tools.executeQueryTable(this, 0, params);
|
||||
};
|
||||
|
||||
ProvinceSchema.statics.executeQueryPickup = async function(idapp, params) {
|
||||
ProvinceSchema.statics.executeQueryPickup = async function (idapp, params) {
|
||||
|
||||
const strfind = params.search;
|
||||
|
||||
@@ -106,12 +113,12 @@ ProvinceSchema.statics.executeQueryPickup = async function(idapp, params) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let filterfindexact = {descr: strfind};
|
||||
let filterfindexact = { descr: strfind };
|
||||
const risexact = await Province.find(filterfindexact).lean();
|
||||
|
||||
let filterfind = {};
|
||||
|
||||
filterfind = {descr: {$regex: '^' + strfind, $options: 'i'}};
|
||||
filterfind = { descr: { $regex: '^' + strfind, $options: 'i' } };
|
||||
|
||||
const ris = await Province.find(filterfind).lean().limit(10);
|
||||
|
||||
@@ -119,16 +126,34 @@ ProvinceSchema.statics.executeQueryPickup = async function(idapp, params) {
|
||||
|
||||
};
|
||||
|
||||
ProvinceSchema.statics.findAllIdApp = async function(idapp) {
|
||||
ProvinceSchema.statics.findAllIdApp = async function (idapp) {
|
||||
const myfind = {};
|
||||
|
||||
return Province.find(myfind).sort({descr: 1});
|
||||
return Province.find(myfind).sort({ descr: 1 });
|
||||
};
|
||||
|
||||
ProvinceSchema.statics.setCoordinatesOnDB = async function () {
|
||||
|
||||
const arrprov = await Province.find({}).lean();
|
||||
|
||||
// Funzione per ottenere le coordinate di tutte le città
|
||||
for (const prov of arrprov) {
|
||||
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 });
|
||||
console.log(' *** Update ', prov.descr, 'lat', ris.lat, 'long', ris.long);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const Province = mongoose.model('Province', ProvinceSchema);
|
||||
|
||||
Province.createIndexes((err) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
|
||||
module.exports = {Province};
|
||||
module.exports = { Province };
|
||||
|
||||
Reference in New Issue
Block a user