- 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');
|
||||
|
||||
@@ -51,9 +51,9 @@ const CitySchema = new Schema({
|
||||
},
|
||||
});
|
||||
|
||||
CitySchema.pre('save', async function(next) {
|
||||
CitySchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
const myrec = await City.findOne().limit(1).sort({_id: -1});
|
||||
const myrec = await City.findOne().limit(1).sort({ _id: -1 });
|
||||
if (!!myrec) {
|
||||
if (myrec._doc._id === 0)
|
||||
this._id = 1;
|
||||
@@ -68,8 +68,8 @@ CitySchema.pre('save', async function(next) {
|
||||
next();
|
||||
});
|
||||
|
||||
CitySchema.statics.getProvinceByIdCity = async function(idcity) {
|
||||
const myrec = await City.findOne({_id: idcity}).lean();
|
||||
CitySchema.statics.getProvinceByIdCity = async function (idcity) {
|
||||
const myrec = await City.findOne({ _id: idcity }).lean();
|
||||
if (myrec) {
|
||||
return myrec.prov;
|
||||
}
|
||||
@@ -77,10 +77,10 @@ CitySchema.statics.getProvinceByIdCity = async function(idcity) {
|
||||
return '';
|
||||
}
|
||||
|
||||
CitySchema.statics.getCircuitNameBystrProv = async function(strProv) {
|
||||
CitySchema.statics.getCircuitNameBystrProv = async function (strProv) {
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
const myrec = await Circuit.findOne({strProv}).lean();
|
||||
const myrec = await Circuit.findOne({ strProv }).lean();
|
||||
if (myrec) {
|
||||
return myrec.name;
|
||||
}
|
||||
@@ -88,8 +88,8 @@ CitySchema.statics.getCircuitNameBystrProv = async function(strProv) {
|
||||
return '';
|
||||
}
|
||||
|
||||
CitySchema.statics.getRegionByIdCity = async function(idcity) {
|
||||
const myrec = await City.findOne({_id: idcity}).lean();
|
||||
CitySchema.statics.getRegionByIdCity = async function (idcity) {
|
||||
const myrec = await City.findOne({ _id: idcity }).lean();
|
||||
if (myrec) {
|
||||
return myrec.reg;
|
||||
}
|
||||
@@ -97,13 +97,13 @@ CitySchema.statics.getRegionByIdCity = async function(idcity) {
|
||||
return '';
|
||||
}
|
||||
|
||||
CitySchema.statics.findByCity = function(mycity) {
|
||||
CitySchema.statics.findByCity = function (mycity) {
|
||||
|
||||
let myregexp = new RegExp(mycity.trim().replace(' ', '|'), 'ig');
|
||||
|
||||
const query = [
|
||||
{$match: {comune: {$regex: myregexp}}},
|
||||
{$sort: {descr: 1}},
|
||||
{ $match: { comune: { $regex: myregexp } } },
|
||||
{ $sort: { descr: 1 } },
|
||||
];
|
||||
|
||||
return City.aggregate(query).then((arrrec) => {
|
||||
@@ -112,17 +112,17 @@ CitySchema.statics.findByCity = function(mycity) {
|
||||
|
||||
};
|
||||
|
||||
CitySchema.statics.getFieldsForSearch = function() {
|
||||
CitySchema.statics.getFieldsForSearch = function () {
|
||||
return [
|
||||
{field: 'comune', type: tools.FieldType.string},
|
||||
{field: 'prov', type: tools.FieldType.string},
|
||||
{field: 'reg', type: tools.FieldType.string},
|
||||
{field: 'pref', type: tools.FieldType.number},
|
||||
{field: 'cap', type: tools.FieldType.number},
|
||||
{ field: 'comune', type: tools.FieldType.string },
|
||||
{ field: 'prov', type: tools.FieldType.string },
|
||||
{ field: 'reg', type: tools.FieldType.string },
|
||||
{ field: 'pref', type: tools.FieldType.number },
|
||||
{ field: 'cap', type: tools.FieldType.number },
|
||||
];
|
||||
};
|
||||
|
||||
CitySchema.statics.executeQueryTable = function(idapp, params) {
|
||||
CitySchema.statics.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
|
||||
const strfind = params.search;
|
||||
@@ -134,7 +134,7 @@ CitySchema.statics.executeQueryTable = function(idapp, params) {
|
||||
return tools.executeQueryTable(this, 0, params);
|
||||
};
|
||||
|
||||
CitySchema.statics.executeQueryPickup = async function(idapp, params) {
|
||||
CitySchema.statics.executeQueryPickup = async function (idapp, params) {
|
||||
|
||||
const strfind = params.search;
|
||||
|
||||
@@ -144,19 +144,19 @@ CitySchema.statics.executeQueryPickup = async function(idapp, params) {
|
||||
|
||||
let filterfindexact = {};
|
||||
if (strfind) {
|
||||
filterfindexact = {comune: strfind};
|
||||
filterfindexact = { comune: strfind };
|
||||
}
|
||||
|
||||
let limit = 10;
|
||||
let risexact = [];
|
||||
|
||||
let filterfind = {comune: {$regex: '^' + strfind, $options: 'i'}};
|
||||
let filterfind = { comune: { $regex: '^' + strfind, $options: 'i' } };
|
||||
|
||||
let aggr1 = [
|
||||
{
|
||||
$match: {comune: strfind},
|
||||
$match: { comune: strfind },
|
||||
},
|
||||
{ $limit : 1 },
|
||||
{ $limit: 1 },
|
||||
{
|
||||
$project: {
|
||||
comune: { $concat: ["$comune", " (", "$prov", ")"] },
|
||||
@@ -165,7 +165,7 @@ CitySchema.statics.executeQueryPickup = async function(idapp, params) {
|
||||
];
|
||||
|
||||
if (params.filter) {
|
||||
filterfind = {...params.filter, ...filterfind};
|
||||
filterfind = { ...params.filter, ...filterfind };
|
||||
limit = 200;
|
||||
} else {
|
||||
// risexact = await City.find(filterfindexact, {comune: 1, prov: 1, reg: 1}).lean();
|
||||
@@ -176,7 +176,7 @@ CitySchema.statics.executeQueryPickup = async function(idapp, params) {
|
||||
{
|
||||
$match: filterfind,
|
||||
},
|
||||
{ $limit : limit },
|
||||
{ $limit: limit },
|
||||
{
|
||||
$project: {
|
||||
comune: { $concat: ["$comune", " (", "$prov", ")"] },
|
||||
@@ -192,17 +192,18 @@ CitySchema.statics.executeQueryPickup = async function(idapp, params) {
|
||||
|
||||
};
|
||||
|
||||
|
||||
CitySchema.statics.findAllIdApp = async function(idapp) {
|
||||
CitySchema.statics.findAllIdApp = async function (idapp) {
|
||||
const myfind = {};
|
||||
|
||||
return await City.find(myfind);
|
||||
};
|
||||
|
||||
|
||||
|
||||
const City = mongoose.model('City', CitySchema);
|
||||
|
||||
City.createIndexes((err) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
|
||||
module.exports = {City};
|
||||
module.exports = { City };
|
||||
|
||||
Reference in New Issue
Block a user