- Codice internazionale numero + Country
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
"bluebird": "^3.7.2",
|
||||
"body-parser": "^1.19.0",
|
||||
"cors": "^2.8.5",
|
||||
"country-codes-list": "^1.6.8",
|
||||
"crypto-js": "^4.1.1",
|
||||
"dotenv": "^10.0.0",
|
||||
"ejs": "^3.1.6",
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
|
||||
class CParamsQuery {
|
||||
constructor(params) {
|
||||
this.table = params.table;
|
||||
this.startRow = params.startRow;
|
||||
this.endRow = params.endRow;
|
||||
this.filter = params.filter;
|
||||
this.filterand = params.filterand;
|
||||
this.filtersearch = params.filtersearch;
|
||||
this.filtercustom = params.filtercustom;
|
||||
this.sortBy = params.sortBy;
|
||||
this.descending = params.descending;
|
||||
this.userId = params.userId;
|
||||
this.codeId = params.codeId;
|
||||
this.lk_tab = params.lk_tab;
|
||||
this.af_objId_tab = params.af_objId_tab;
|
||||
this.lk_LF = params.lk_LF;
|
||||
this.lk_FF = params.lk_FF;
|
||||
this.lk_as = params.lk_as;
|
||||
this.lk_proj = params.lk_proj;
|
||||
this.lk_col2 = params.lk_col2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Query blog posts by user -> paginated results and a total count.
|
||||
* @param userId {ObjectId} ID of user to retrieve blog posts for
|
||||
* @param startRow {Number} First row to return in results
|
||||
* @param endRow {Number} Last row to return in results
|
||||
* @param [filter] {Object} Optional extra matching query object
|
||||
* @param [sort] {Object} Optional sort query object
|
||||
* @returns {Object} Object -> `{ rows, count }`
|
||||
*/
|
||||
|
||||
function queryBlogPostsByUser (userId, startRow, endRow, filter = {}, sort = false) {
|
||||
const User = this;
|
||||
|
||||
if (!(user instanceof mongoose.Types.ObjectId)) {
|
||||
throw new Error('userId must be ObjectId')
|
||||
} else if (typeof startRow !== 'number') {
|
||||
throw new Error('startRow must be number')
|
||||
} else if (typeof endRow !== 'number') {
|
||||
throw new Error('endRow must be number')
|
||||
}
|
||||
|
||||
const query = [
|
||||
// more lookups go here if you need them
|
||||
// we have a many-to-one from blogPost -> user
|
||||
{ $lookup: {
|
||||
from: 'users',
|
||||
localField: 'user',
|
||||
foreignField: '_id',
|
||||
as: 'user'
|
||||
} },
|
||||
// each blog has a single user (author) so flatten it using $unwind
|
||||
{ $unwind: '$user' },
|
||||
// filter the results by our userId
|
||||
{ $match: Object.assign({ 'user._id': userId }, filter) }
|
||||
];
|
||||
|
||||
if (sort) {
|
||||
// maybe we want to sort by blog title or something
|
||||
query.push({ $sort: sort })
|
||||
}
|
||||
|
||||
query.push(
|
||||
{ $group: {
|
||||
_id: null,
|
||||
// get a count of every result that matches until now
|
||||
count: { $sum: 1 },
|
||||
// keep our results for the next operation
|
||||
results: { $push: '$$ROOT' }
|
||||
} },
|
||||
// and finally trim the results to within the range given by start/endRow
|
||||
{ $project: {
|
||||
count: 1,
|
||||
rows: { $slice: ['$results', startRow, endRow] }
|
||||
} }
|
||||
);
|
||||
|
||||
return User
|
||||
.aggregate(query)
|
||||
.then(([{ count, rows }]) => ({ count, rows }))
|
||||
};
|
||||
|
||||
|
||||
module.exports = { CParamsQuery, queryBlogPostsByUser };
|
||||
@@ -7,7 +7,6 @@ const _ = require('lodash');
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
const queryclass = require('../classes/queryclass');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ const { Nave } = require('./nave');
|
||||
const { Settings } = require('./settings');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
const queryclass = require('../classes/queryclass');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ const { Graduatoria } = require('./graduatoria');
|
||||
const actions = require('../router/api/actions');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
const queryclass = require('../classes/queryclass');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
|
||||
|
||||
@@ -30,6 +30,10 @@ const MySkillSchema = new Schema({
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
idContribType: [
|
||||
{
|
||||
type: String,
|
||||
}],
|
||||
idCity: [
|
||||
{
|
||||
type: Number,
|
||||
@@ -109,25 +113,28 @@ MySkillSchema.statics.executeQueryTable = function(idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
|
||||
const otherparams = {
|
||||
lk_tab: 'users',
|
||||
lk_LF: 'userId',
|
||||
lk_FF: '_id',
|
||||
lk_as: 'user',
|
||||
af_objId_tab: 'myId',
|
||||
lk_proj: {
|
||||
idSkill: 1,
|
||||
idStatusSkill: 1,
|
||||
idCity: 1,
|
||||
numLevel: 1,
|
||||
photos: 1,
|
||||
note: 1,
|
||||
subTitle: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
userId: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
lookup1: {
|
||||
lk_tab: 'users',
|
||||
lk_LF: 'userId',
|
||||
lk_FF: '_id',
|
||||
lk_as: 'user',
|
||||
af_objId_tab: 'myId',
|
||||
lk_proj: {
|
||||
idSkill: 1,
|
||||
idStatusSkill: 1,
|
||||
idContribType: 1,
|
||||
idCity: 1,
|
||||
numLevel: 1,
|
||||
photos: 1,
|
||||
note: 1,
|
||||
subTitle: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
userId: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
58
src/server/models/pickup.js
Executable file
58
src/server/models/pickup.js
Executable file
@@ -0,0 +1,58 @@
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const countryCodes = require('country-codes-list');
|
||||
|
||||
module.exports = {
|
||||
|
||||
async executeQueryTable(idapp, params) {
|
||||
|
||||
const table = params.table;
|
||||
const strfind = params.search;
|
||||
|
||||
if (strfind === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
let myCountryArr = [];
|
||||
|
||||
let out = {};
|
||||
|
||||
if (table === shared_consts.TAB_COUNTRY) {
|
||||
// '[{countryCode}] {countryNameLocal}: +{countryCallingCode}'
|
||||
out = {
|
||||
id: '{countryCode}',
|
||||
value: '{countryNameLocal}',
|
||||
flag: '{flag}',
|
||||
};
|
||||
|
||||
} else if (table === shared_consts.TAB_PHONES) {
|
||||
out = {
|
||||
id: '{countryCode}',
|
||||
value: '{countryNameLocal} +{countryCallingCode}',
|
||||
code: '+{countryCallingCode}',
|
||||
flag: '{flag}',
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
// const myCountryArr = countryCodes.filter('countryNameLocal', strfind);
|
||||
// const myCountryArr = countryCodes.customList.filter()
|
||||
|
||||
// myCountryArr = countryCodes.customList('countryCode', lavueout, { filter: ((countryData) => { return countryData['countryNameLocal'].toLocaleLowerCase().indexOf(strfind) >= 0 })} );
|
||||
myCountryArr = countryCodes.customArray(out, {
|
||||
filter: ((countryData) => {
|
||||
return countryData['countryNameLocal'].toLocaleLowerCase().
|
||||
startsWith(strfind) || countryData['countryNameEn'].toLocaleLowerCase().
|
||||
startsWith(strfind);
|
||||
}),
|
||||
});
|
||||
|
||||
} catch (e) {
|
||||
console.log('err', e);
|
||||
}
|
||||
|
||||
return myCountryArr;
|
||||
},
|
||||
};
|
||||
@@ -56,6 +56,24 @@ const SiteSchema = new Schema({
|
||||
pathreg_add: {
|
||||
type: String,
|
||||
},
|
||||
who: {
|
||||
type: String
|
||||
},
|
||||
status: {
|
||||
type: String
|
||||
},
|
||||
note: {
|
||||
type: String
|
||||
},
|
||||
domain_provider: {
|
||||
type: String,
|
||||
},
|
||||
domain_expiring: {
|
||||
type: Date
|
||||
},
|
||||
next_payment: {
|
||||
type: Date
|
||||
},
|
||||
});
|
||||
|
||||
var Site = module.exports = mongoose.model('Site', SiteSchema);
|
||||
|
||||
@@ -17,7 +17,6 @@ const {NavePersistente} = require('../models/navepersistente');
|
||||
const {ObjectID} = require('mongodb');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
const queryclass = require('../classes/queryclass');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
|
||||
@@ -229,6 +228,18 @@ const UserSchema = new mongoose.Schema({
|
||||
dateofbirth: {
|
||||
type: Date,
|
||||
},
|
||||
born_city: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
born_province: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
born_country: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
my_dream: {
|
||||
type: String,
|
||||
},
|
||||
@@ -1504,32 +1515,6 @@ UserSchema.statics.getUsersList = function(idapp) {
|
||||
);
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsersListByParams = function(params) {
|
||||
const User = this;
|
||||
|
||||
myclParamQuery = new queryclass.CParamsQuery(params);
|
||||
|
||||
const filterMatchBefore = `${myclParamQuery.filter}`;
|
||||
|
||||
return User.find(
|
||||
{$match: filterMatchBefore},
|
||||
{'idapp': idapp},
|
||||
{
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
verified_email: 1,
|
||||
made_gift: 1,
|
||||
perm: 1,
|
||||
email: 1,
|
||||
date_reg: 1,
|
||||
img: 1,
|
||||
lasttimeonline: 1,
|
||||
news_on: 1,
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Query blog posts by user -> paginated results and a total count.
|
||||
* @returns {Object} Object -> `{ rows, count }`
|
||||
|
||||
@@ -47,6 +47,7 @@ const {StatusSkill} = require('../models/statusSkill');
|
||||
const {City} = require('../models/city');
|
||||
const {Sector} = require('../models/sector');
|
||||
const {Level} = require('../models/level');
|
||||
const Pickup = require('../models/pickup');
|
||||
const {Newstosent} = require('../models/newstosent');
|
||||
const {MyPage} = require('../models/mypage');
|
||||
const {CalZoom} = require('../models/calzoom');
|
||||
@@ -259,7 +260,7 @@ function getTableByTableName(tablename) {
|
||||
mytable = Where;
|
||||
else if (tablename === 'myevents')
|
||||
mytable = MyEvent;
|
||||
else if (tablename === 'contribtype')
|
||||
else if (tablename === 'contribtypes')
|
||||
mytable = Contribtype;
|
||||
else if (tablename === 'paymenttypes')
|
||||
mytable = PaymentType;
|
||||
@@ -307,6 +308,8 @@ function getTableByTableName(tablename) {
|
||||
mytable = Sector;
|
||||
else if (tablename === 'levels')
|
||||
mytable = Level;
|
||||
else if (shared_consts.TablePickup.includes(tablename))
|
||||
mytable = Pickup;
|
||||
|
||||
return mytable;
|
||||
}
|
||||
@@ -318,17 +321,6 @@ router.post('/settable', authenticate, (req, res) => {
|
||||
|
||||
mydata.idapp = req.user.idapp;
|
||||
|
||||
if (shared_consts.TABLES_ID_NUMBER.includes(params.table)) {
|
||||
//if (mydata['_id'] === undefined) {
|
||||
// mydata._id = 1;
|
||||
//}
|
||||
} else if (params.table === 'hours') {
|
||||
|
||||
} else {
|
||||
if (mydata['_id'] === undefined) {
|
||||
mydata._id = new ObjectID();
|
||||
}
|
||||
}
|
||||
|
||||
if (shared_consts.TABLES_USER_ID.includes(params.table)) {
|
||||
mydata.userId = req.user._id;
|
||||
@@ -346,6 +338,15 @@ router.post('/settable', authenticate, (req, res) => {
|
||||
mytablerec.isNew = false;
|
||||
}
|
||||
|
||||
if (shared_consts.TABLES_ID_NUMBER.includes(params.table)) {
|
||||
} else if (params.table === 'hours') {
|
||||
|
||||
} else {
|
||||
if (mydata['_id'] === undefined) {
|
||||
mydata._id = new ObjectID();
|
||||
}
|
||||
}
|
||||
|
||||
return mytablerec.save().then(rec => {
|
||||
// tools.mylog('rec', rec);
|
||||
return res.send(rec);
|
||||
@@ -441,6 +442,25 @@ router.post('/gettable', authenticate, (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.post('/pickup', authenticate, (req, res) => {
|
||||
const params = req.body;
|
||||
const mytable = getTableByTableName(params.table);
|
||||
// console.log('mytable', mytable);
|
||||
if (!mytable) {
|
||||
console.log(`Table ${params.table} not found`);
|
||||
return res.status(400).send({});
|
||||
}
|
||||
|
||||
return mytable.executeQueryTable(req.user.idapp, params).then(ris => {
|
||||
return res.send(ris);
|
||||
|
||||
}).catch((e) => {
|
||||
console.log(e.message);
|
||||
res.status(400).send(e);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
router.post('/getpage', async (req, res) => {
|
||||
const params = req.body;
|
||||
const idapp = req.body.idapp;
|
||||
|
||||
@@ -1106,6 +1106,56 @@ module.exports = {
|
||||
return (myapp) ? myapp.telegram_key : '';
|
||||
},
|
||||
|
||||
getLookup: function(params, num, pass_proj) {
|
||||
const query = []
|
||||
|
||||
if (!params)
|
||||
return;
|
||||
|
||||
let mylkLF = params.lk_LF;
|
||||
if (params.af_objId_tab) {
|
||||
const myobj = {}
|
||||
myobj['myId' + num] = {'$toObjectId': '$' + params.lk_LF};
|
||||
query.push(
|
||||
{'$addFields': myobj},
|
||||
);
|
||||
mylkLF = 'myId' + num;
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
if (params.lk_tab) {
|
||||
let proj = params.lk_proj
|
||||
if (!!pass_proj) {
|
||||
proj = pass_proj
|
||||
}
|
||||
query.push(
|
||||
{
|
||||
$lookup: {
|
||||
from: params.lk_tab,
|
||||
localField: mylkLF, // field in my collection
|
||||
foreignField: params.lk_FF, // field in the 'from' collection
|
||||
as: params.lk_as,
|
||||
},
|
||||
},
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
'$' + params.lk_as, 0],
|
||||
}, '$$ROOT'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{$project: proj},
|
||||
);
|
||||
}
|
||||
|
||||
return query;
|
||||
},
|
||||
|
||||
getQueryTable: function(idapp, params) {
|
||||
|
||||
if (typeof params.startRow !== 'number') {
|
||||
@@ -1114,7 +1164,14 @@ module.exports = {
|
||||
throw new Error('endRow must be number');
|
||||
}
|
||||
|
||||
let newvers = true;
|
||||
|
||||
if (params.lk_LF)
|
||||
newvers = false;
|
||||
|
||||
let query = [];
|
||||
|
||||
|
||||
if (params.filter && params.fieldsearch) {
|
||||
|
||||
let myregexp = {};
|
||||
@@ -1285,38 +1342,30 @@ module.exports = {
|
||||
if (numrowend < 0)
|
||||
numrowend = 1;
|
||||
|
||||
let mylkLF = params.lk_LF;
|
||||
if (params.af_objId_tab) {
|
||||
query.push(
|
||||
{'$addFields': {'myId': {'$toObjectId': '$' + params.lk_LF}}},
|
||||
);
|
||||
mylkLF = 'myId';
|
||||
|
||||
if (newvers) {
|
||||
// NUOVA VERSIONE
|
||||
let proj = params.lookup2 ? params.lookup2.lk_proj : null;
|
||||
|
||||
const q1 = this.getLookup(params.lookup1, 1, proj);
|
||||
if (q1) query = [...query, ...q1]
|
||||
|
||||
const q2 = this.getLookup(params.lookup2, 2, proj);
|
||||
if (q2) query = [...query, ...q2];
|
||||
|
||||
const q3 = this.getLookup(params.lookup3, 3, proj);
|
||||
if (q3) query = [...query, ...q3];
|
||||
|
||||
if (params.filtersearch2.length > 0) {
|
||||
query.push({$match: {$and: params.filtersearch2}});
|
||||
}
|
||||
|
||||
} else {
|
||||
// VECCHIA VERSIONE
|
||||
const q1 = this.getLookup(params, 1);
|
||||
if (q1) query = [...query, ...q1]
|
||||
}
|
||||
|
||||
if (params.lk_tab) {
|
||||
query.push(
|
||||
{
|
||||
$lookup: {
|
||||
from: params.lk_tab,
|
||||
localField: mylkLF, // field in my collection
|
||||
foreignField: params.lk_FF, // field in the 'from' collection
|
||||
as: params.lk_as,
|
||||
},
|
||||
},
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
'$' + params.lk_as, 0],
|
||||
}, '$$ROOT'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{$project: params.lk_proj},
|
||||
);
|
||||
}
|
||||
|
||||
query.push(
|
||||
{
|
||||
@@ -1347,6 +1396,7 @@ module.exports = {
|
||||
let query = this.getQueryTable(idapp, params);
|
||||
|
||||
try {
|
||||
// console.log('query', query);
|
||||
const [ris] = await mythistable.aggregate(query);
|
||||
|
||||
if (ris) {
|
||||
|
||||
@@ -34,6 +34,11 @@ module.exports = {
|
||||
REPORT_FILT_RESP: 1,
|
||||
REPORT_FILT_ATTIVITA: 2,
|
||||
|
||||
TAB_COUNTRY: 'countries',
|
||||
TAB_PHONES: 'phones',
|
||||
|
||||
TablePickup: ['countries', 'phones'],
|
||||
|
||||
PaymentTypes: [
|
||||
'Nessuno',
|
||||
'Bonifico Bancario',
|
||||
|
||||
@@ -2566,6 +2566,11 @@ cors@^2.8.5:
|
||||
object-assign "^4"
|
||||
vary "^1"
|
||||
|
||||
country-codes-list@^1.6.8:
|
||||
version "1.6.8"
|
||||
resolved "https://registry.yarnpkg.com/country-codes-list/-/country-codes-list-1.6.8.tgz#c6ff506d3c0511f645fdc0997d0b4fa6773d043e"
|
||||
integrity sha512-wsqH44Yx3pTyPA77jYt2Nxso6kXziMwxI37fJFQLcd/3ome8Gqz6areaeG1w8zfeU9i+cZvJA3k2Mo5EW7rAtg==
|
||||
|
||||
cross-spawn@^7.0.3:
|
||||
version "7.0.3"
|
||||
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
|
||||
|
||||
Reference in New Issue
Block a user