Lista Città (prese dal server: pickup)
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
const mongoose = require('mongoose').set('debug', false)
|
||||
const mongoose = require('mongoose').set('debug', false);
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const escapeStringRegexp = require('escape-string-regexp');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
mongoose.level = 'F';
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
const {ObjectID} = require('mongodb');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
schema.options.usePushEach = true;
|
||||
});
|
||||
|
||||
const CitySchema = new Schema({
|
||||
@@ -21,7 +23,7 @@ const CitySchema = new Schema({
|
||||
type: String,
|
||||
},
|
||||
comune: {
|
||||
type: String
|
||||
type: String,
|
||||
},
|
||||
prov: {
|
||||
type: String,
|
||||
@@ -39,7 +41,7 @@ const CitySchema = new Schema({
|
||||
maxlength: 6,
|
||||
},
|
||||
abitanti: {
|
||||
type: Number,
|
||||
type: String,
|
||||
},
|
||||
country: {
|
||||
type: String,
|
||||
@@ -47,9 +49,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;
|
||||
@@ -64,34 +66,32 @@ CitySchema.pre('save', async function (next) {
|
||||
next();
|
||||
});
|
||||
|
||||
|
||||
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) => {
|
||||
return arrrec
|
||||
})
|
||||
return City.aggregate(query).then((arrrec) => {
|
||||
return arrrec;
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
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 },
|
||||
]
|
||||
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},
|
||||
];
|
||||
};
|
||||
|
||||
CitySchema.statics.executeQueryTable = function (idapp, params) {
|
||||
CitySchema.statics.executeQueryTable = function(idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
|
||||
const strfind = params.search;
|
||||
@@ -103,13 +103,25 @@ CitySchema.statics.executeQueryTable = function (idapp, params) {
|
||||
return tools.executeQueryTable(this, 0, params);
|
||||
};
|
||||
|
||||
CitySchema.statics.findAllIdApp = async function (idapp) {
|
||||
CitySchema.statics.executeQueryPickup = async function(idapp, params) {
|
||||
|
||||
const strfind = params.search;
|
||||
|
||||
if (strfind === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
const ris = await City.find({ comune: { $regex : '^' + strfind, $options: 'i' } }, {comune: 1, prov: 1, reg: 1}).lean();
|
||||
return ris;
|
||||
|
||||
};
|
||||
|
||||
CitySchema.statics.findAllIdApp = async function(idapp) {
|
||||
const myfind = {};
|
||||
|
||||
return City.find(myfind);
|
||||
};
|
||||
|
||||
|
||||
const City = mongoose.model('City', CitySchema);
|
||||
|
||||
module.exports = { City };
|
||||
module.exports = {City};
|
||||
|
||||
@@ -139,6 +139,8 @@ MySkillSchema.statics.executeQueryTable = function(idapp, params) {
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
'profile.img': 1,
|
||||
'profile.qualifica': 1,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ const countryCodes = require('country-codes-list');
|
||||
|
||||
module.exports = {
|
||||
|
||||
async executeQueryTable(idapp, params) {
|
||||
async executeQueryPickup(idapp, params) {
|
||||
|
||||
const table = params.table;
|
||||
const strfind = params.search;
|
||||
|
||||
@@ -282,6 +282,9 @@ const UserSchema = new mongoose.Schema({
|
||||
biografia: {
|
||||
type: String,
|
||||
},
|
||||
qualifica: {
|
||||
type: String,
|
||||
},
|
||||
motivazioni: {
|
||||
type: String,
|
||||
},
|
||||
@@ -1189,6 +1192,7 @@ UserSchema.statics.getUserProfileByUsername = async function(idapp, username) {
|
||||
verified_email: 1,
|
||||
verified_by_aportador: 1,
|
||||
'profile.nationality': 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.biografia': 1,
|
||||
'profile.teleg_id': 1,
|
||||
'profile.username_telegram': 1,
|
||||
@@ -1283,7 +1287,7 @@ UserSchema.statics.setFriendsCmd = async function(
|
||||
idapp,
|
||||
username: usernameOrig,
|
||||
'profile.friends': {
|
||||
$elemMatch: {$eq: {username: usernameDest}},
|
||||
$elemMatch: {username: {$eq: usernameDest}},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1307,7 +1311,7 @@ UserSchema.statics.setFriendsCmd = async function(
|
||||
idapp,
|
||||
username: usernameDest,
|
||||
'profile.friends': {
|
||||
$elemMatch: {$eq: {username: usernameOrig}},
|
||||
$elemMatch: {username: {$eq: usernameOrig}},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1333,7 +1337,7 @@ UserSchema.statics.setFriendsCmd = async function(
|
||||
idapp,
|
||||
username: usernameDest,
|
||||
'profile.req_friends': {
|
||||
$elemMatch: {$eq: {username: usernameOrig}},
|
||||
$elemMatch: { username: {$eq: usernameOrig}},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1407,6 +1411,7 @@ function getWhatToShow(idapp, username) {
|
||||
verified_email: 1,
|
||||
verified_by_aportador: 1,
|
||||
'profile.nationality': 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.biografia': 1,
|
||||
'profile.username_telegram': 1,
|
||||
'profile.img': 1,
|
||||
@@ -1471,7 +1476,7 @@ UserSchema.statics.getAskedFriendsByUsername = async function(idapp, username) {
|
||||
return User.find({
|
||||
idapp,
|
||||
'profile.req_friends': {
|
||||
$elemMatch: {$eq: {username: username}},
|
||||
$elemMatch: {username: {$eq: username}},
|
||||
},
|
||||
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
|
||||
}, whatToShow_Unknown).then((rec) => {
|
||||
@@ -1510,7 +1515,7 @@ UserSchema.statics.getFriendsByUsername = async function(idapp, username) {
|
||||
let listSentRequestFriends = await User.find({
|
||||
idapp,
|
||||
'profile.req_friends': {
|
||||
$elemMatch: {$eq: {username: username}},
|
||||
$elemMatch: {username: {$eq: username}},
|
||||
},
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
@@ -3134,6 +3139,27 @@ UserSchema.statics.DbOp = async function(idapp, mydata) {
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.addExtraInfo = async function(idapp, recUser) {
|
||||
|
||||
try {
|
||||
const listSentMyRequestFriends = await User.find({
|
||||
idapp,
|
||||
'profile.req_friends': {
|
||||
$elemMatch: {username: {$eq: recUser.username}},
|
||||
},
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
{deleted: {$exists: true, $eq: false}}],
|
||||
}, {username: 1});
|
||||
|
||||
recUser._doc.profile.asked_friends = listSentMyRequestFriends ? listSentMyRequestFriends : [];
|
||||
}catch (e){
|
||||
console.error('Err', e);
|
||||
}
|
||||
|
||||
return recUser;
|
||||
};
|
||||
|
||||
UserSchema.statics.createNewSubRecord = async function(idapp, req) {
|
||||
const User = this;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user