Aggiungere "San Marino" e suoi comuni

Corretto Filtro a mano della ricerca
Creare filtro ricerca per trovare la sottocategoria o categoria -> Skill e SubSkill
This commit is contained in:
paoloar77
2022-02-12 02:20:07 +01:00
parent 2d1dfc9348
commit a71f081407
11 changed files with 789 additions and 331 deletions

67
src/server/models/adtype.js Executable file
View File

@@ -0,0 +1,67 @@
const mongoose = require('mongoose').set('debug', false);
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
mongoose.level = "";
const tools = require('../tools/general');
const {ObjectID} = require('mongodb');
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true;
});
const AdTypeSchema = new Schema({
_id: {
type: Number,
},
descr: {
type: String,
},
});
AdTypeSchema.pre('save', async function (next) {
if (this.isNew) {
const myrec = await AdType.findOne().limit(1).sort({_id:-1});
if (!!myrec) {
if (myrec._doc._id === 0)
this._id = 1;
else
this._id = myrec._doc._id + 1;
} else {
this._id = 1;
}
}
next();
});
AdTypeSchema.statics.findAllIdApp = async function(idapp) {
const AdType = this;
const query = [
{$sort: {_id: 1}},
];
return AdType.aggregate(query).then((arrrec) => {
return arrrec;
});
};
AdTypeSchema.statics.getFieldsForSearch = function() {
return [
{field: 'descr', type: tools.FieldType.string}];
};
AdTypeSchema.statics.executeQueryTable = function(idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, 0, params);
};
const AdType = mongoose.model('AdType', AdTypeSchema);
module.exports = {AdType};

View File

@@ -47,7 +47,7 @@ const CitySchema = new Schema({
}, },
country: { country: {
type: String, type: String,
maxlength: 2, maxlength: 3,
}, },
}); });

View File

@@ -50,6 +50,9 @@ const MySkillSchema = new Schema({
type: Number, type: Number,
default: 0, default: 0,
}, },
adType: {
type: Number,
},
photos: [ photos: [
{ {
imagefile: { imagefile: {
@@ -66,9 +69,6 @@ const MySkillSchema = new Schema({
type: String, type: String,
default: '', default: '',
}, },
subTitle: {
type: String,
},
descr: { descr: {
type: String, type: String,
}, },
@@ -116,15 +116,21 @@ MySkillSchema.statics.findAllIdApp = async function(idapp) {
}; };
MySkillSchema.statics.getFieldsForSearch = function() { MySkillSchema.statics.getFieldsForSearch = function() {
return [];
};
MySkillSchema.statics.getFieldsLastForSearch = function() {
return [ return [
{field: 'idSkill', type: tools.FieldType.Number} {field: 'note', type: tools.FieldType.string},
, {field: 'note', type: tools.FieldType.String} {field: 'descr', type: tools.FieldType.string},
, {field: 'subTitle', type: tools.FieldType.String}, {field: 'recSkill.descr', type: tools.FieldType.string},
{field: 'myskill.descr', type: tools.FieldType.string},
]; ];
}; };
MySkillSchema.statics.executeQueryTable = function(idapp, params) { MySkillSchema.statics.executeQueryTable = function(idapp, params) {
params.fieldsearch = this.getFieldsForSearch(); params.fieldsearch = this.getFieldsForSearch();
params.fieldsearch_last = this.getFieldsLastForSearch();
const otherparams = { const otherparams = {
lookup1: { lookup1: {
@@ -135,13 +141,15 @@ MySkillSchema.statics.executeQueryTable = function(idapp, params) {
af_objId_tab: 'myId', af_objId_tab: 'myId',
lk_proj: { lk_proj: {
idSkill: 1, idSkill: 1,
idSubSkill: 1,
myskill: 1,
idStatusSkill: 1, idStatusSkill: 1,
idContribType: 1, idContribType: 1,
idCity: 1, idCity: 1,
numLevel: 1, numLevel: 1,
photos: 1, photos: 1,
note: 1, note: 1,
subTitle: 1, descr: 1,
date_created: 1, date_created: 1,
date_updated: 1, date_updated: 1,
userId: 1, userId: 1,
@@ -159,289 +167,288 @@ MySkillSchema.statics.executeQueryTable = function(idapp, params) {
return tools.executeQueryTable(this, idapp, params); return tools.executeQueryTable(this, idapp, params);
}; };
MySkillSchema.statics.getMySkillByIdkill = function (idapp, idSkill) { MySkillSchema.statics.getMySkillByIdkill = function(idapp, idSkill) {
const MySkill = this; const MySkill = this;
const query = [ const query = [
{ {
"$match": { '$match': {
"$and": [ '$and': [
{ {
"_id": parseInt(idSkill) '_id': parseInt(idSkill),
} },
] ],
} },
}, },
{ {
"$match": { '$match': {
"idapp": idapp 'idapp': idapp,
} },
}, },
{ {
"$sort": { '$sort': {
"desc": 1 'desc': 1,
} },
}, },
{ {
"$addFields": { '$addFields': {
"myId1": { 'myId1': {
"$toObjectId": "$userId" '$toObjectId': '$userId',
} },
} },
}, },
{ {
"$lookup": { '$lookup': {
"from": "users", 'from': 'users',
"localField": "myId1", 'localField': 'myId1',
"foreignField": "_id", 'foreignField': '_id',
"as": "user" 'as': 'user',
} },
}, },
{ {
"$replaceRoot": { '$replaceRoot': {
"newRoot": { 'newRoot': {
"$mergeObjects": [ '$mergeObjects': [
{ {
"$arrayElemAt": [ '$arrayElemAt': [
"$user", '$user',
0 0,
] ],
},
'$$ROOT',
],
},
}, },
"$$ROOT"
]
}
}
}, },
{ {
"$project": { '$project': {
"recSkill": 1, 'recSkill': 1,
"sector": 1, 'sector': 1,
"idSector": 1, 'idSector': 1,
"idSkill": 1, 'idSkill': 1,
"idSubSkill": 1, 'idSubSkill': 1,
"idStatusSkill": 1, 'idStatusSkill': 1,
"idContribType": 1, 'idContribType': 1,
"idCity": 1, 'idCity': 1,
"numLevel": 1, 'numLevel': 1,
"photos": 1, 'photos': 1,
"note": 1, 'note': 1,
"subTitle": 1, 'descr': 1,
"date_created": 1, 'date_created': 1,
"date_updated": 1, 'date_updated': 1,
"userId": 1, 'userId': 1,
"username": 1, 'username': 1,
"name": 1, 'name': 1,
"surname": 1, 'surname': 1,
"comune": 1, 'comune': 1,
"mycities": 1, 'mycities': 1,
"profile.img": 1, 'profile.img': 1,
"profile.qualifica": 1 'profile.qualifica': 1,
} },
}, },
{ {
"$lookup": { '$lookup': {
"from": "skills", 'from': 'skills',
"localField": "idSkill", 'localField': 'idSkill',
"foreignField": "_id", 'foreignField': '_id',
"as": "recSkill" 'as': 'recSkill',
} },
}, },
{ {
"$replaceRoot": { '$replaceRoot': {
"newRoot": { 'newRoot': {
"$mergeObjects": [ '$mergeObjects': [
{ {
"$arrayElemAt": [ '$arrayElemAt': [
"$recSkill", '$recSkill',
0 0,
] ],
},
'$$ROOT',
],
},
}, },
"$$ROOT"
]
}
}
}, },
{ {
"$project": { '$project': {
"recSkill": 1, 'recSkill': 1,
"sector": 1, 'sector': 1,
"idSector": 1, 'idSector': 1,
"idSkill": 1, 'idSkill': 1,
"idSubSkill": 1, 'idSubSkill': 1,
"idStatusSkill": 1, 'idStatusSkill': 1,
"idContribType": 1, 'idContribType': 1,
"idCity": 1, 'idCity': 1,
"numLevel": 1, 'numLevel': 1,
"photos": 1, 'photos': 1,
"note": 1, 'note': 1,
"subTitle": 1, 'descr': 1,
"date_created": 1, 'date_created': 1,
"date_updated": 1, 'date_updated': 1,
"userId": 1, 'userId': 1,
"username": 1, 'username': 1,
"name": 1, 'name': 1,
"surname": 1, 'surname': 1,
"comune": 1, 'comune': 1,
"mycities": 1, 'mycities': 1,
"profile.img": 1, 'profile.img': 1,
"profile.qualifica": 1 'profile.qualifica': 1,
} },
}, },
{ {
"$lookup": { '$lookup': {
"from": "sectors", 'from': 'sectors',
"localField": "recSkill.idSector", 'localField': 'recSkill.idSector',
"foreignField": "_id", 'foreignField': '_id',
"as": "sector" 'as': 'sector',
} },
}, },
{ {
"$replaceRoot": { '$replaceRoot': {
"newRoot": { 'newRoot': {
"$mergeObjects": [ '$mergeObjects': [
{ {
"$arrayElemAt": [ '$arrayElemAt': [
"$sector", '$sector',
0 0,
] ],
},
'$$ROOT',
],
},
}, },
"$$ROOT"
]
}
}
}, },
{ {
"$project": { '$project': {
"recSkill": 1, 'recSkill': 1,
"sector": 1, 'sector': 1,
"idSector": 1, 'idSector': 1,
"idSkill": 1, 'idSkill': 1,
"idSubSkill": 1, 'idSubSkill': 1,
"idStatusSkill": 1, 'idStatusSkill': 1,
"idContribType": 1, 'idContribType': 1,
"idCity": 1, 'idCity': 1,
"numLevel": 1, 'numLevel': 1,
"photos": 1, 'photos': 1,
"note": 1, 'note': 1,
"subTitle": 1, 'descr': 1,
"date_created": 1, 'date_created': 1,
"date_updated": 1, 'date_updated': 1,
"userId": 1, 'userId': 1,
"username": 1, 'username': 1,
"name": 1, 'name': 1,
"surname": 1, 'surname': 1,
"comune": 1, 'comune': 1,
"mycities": 1, 'mycities': 1,
"profile.img": 1, 'profile.img': 1,
"profile.qualifica": 1 'profile.qualifica': 1,
} },
}, },
{ {
"$lookup": { '$lookup': {
"from": "subskills", 'from': 'subskills',
"localField": "idSubSkill", 'localField': 'idSubSkill',
"foreignField": "_id", 'foreignField': '_id',
"as": "myskill" 'as': 'myskill',
} },
}, },
{ {
"$replaceRoot": { '$replaceRoot': {
"newRoot": { 'newRoot': {
"$mergeObjects": [ '$mergeObjects': [
{ {
"$arrayElemAt": [ '$arrayElemAt': [
"$myskill", '$myskill',
0 0,
] ],
},
'$$ROOT',
],
},
}, },
"$$ROOT"
]
}
}
}, },
{ {
"$project": { '$project': {
"recSkill": 1, 'recSkill': 1,
"sector": 1, 'sector': 1,
"idSector": 1, 'idSector': 1,
"idSkill": 1, 'idSkill': 1,
"idSubSkill": 1, 'idSubSkill': 1,
"idStatusSkill": 1, 'idStatusSkill': 1,
"idContribType": 1, 'idContribType': 1,
"idCity": 1, 'idCity': 1,
"numLevel": 1, 'numLevel': 1,
"photos": 1, 'photos': 1,
"note": 1, 'note': 1,
"subTitle": 1, 'descr': 1,
"date_created": 1, 'date_created': 1,
"date_updated": 1, 'date_updated': 1,
"userId": 1, 'userId': 1,
"username": 1, 'username': 1,
"name": 1, 'name': 1,
"surname": 1, 'surname': 1,
"comune": 1, 'comune': 1,
"mycities": 1, 'mycities': 1,
"profile.img": 1, 'profile.img': 1,
"profile.qualifica": 1 'profile.qualifica': 1,
} },
}, },
{ {
"$lookup": { '$lookup': {
"from": "cities", 'from': 'cities',
"localField": "idCity", 'localField': 'idCity',
"foreignField": "_id", 'foreignField': '_id',
"as": "mycities" 'as': 'mycities',
} },
}, },
{ {
"$replaceRoot": { '$replaceRoot': {
"newRoot": { 'newRoot': {
"$mergeObjects": [ '$mergeObjects': [
{ {
"$arrayElemAt": [ '$arrayElemAt': [
"$mycities", '$mycities',
0 0,
] ],
},
'$$ROOT',
],
},
}, },
"$$ROOT"
]
}
}
}, },
{ {
"$project": { '$project': {
"recSkill": 1, 'recSkill': 1,
"sector": 1, 'sector': 1,
"idSector": 1, 'idSector': 1,
"idSkill": 1, 'idSkill': 1,
"idSubSkill": 1, 'idSubSkill': 1,
"idStatusSkill": 1, 'idStatusSkill': 1,
"idContribType": 1, 'idContribType': 1,
"idCity": 1, 'idCity': 1,
"numLevel": 1, 'numLevel': 1,
"photos": 1, 'photos': 1,
"note": 1, 'note': 1,
"subTitle": 1, 'descr': 1,
"date_created": 1, 'date_created': 1,
"date_updated": 1, 'date_updated': 1,
"userId": 1, 'userId': 1,
"username": 1, 'username': 1,
"name": 1, 'name': 1,
"surname": 1, 'surname': 1,
"comune": 1, 'comune': 1,
"mycities": 1, 'mycities': 1,
"profile.img": 1, 'profile.img': 1,
"profile.qualifica": 1 'profile.qualifica': 1,
} },
} },
] ];
return MySkill.aggregate(query).then((rec) => { return MySkill.aggregate(query).then((rec) => {
return rec ? rec[0] : null; return rec ? rec[0] : null;
}); });
}; };
const MySkill = mongoose.model('MySkill', MySkillSchema); const MySkill = mongoose.model('MySkill', MySkillSchema);
module.exports = {MySkill}; module.exports = {MySkill};

View File

@@ -0,0 +1,6 @@
module.exports = {
list: [
{_id: 1, descr: 'Offro'},
{_id: 2, descr: 'Cerco'},
],
};

View File

@@ -89012,5 +89012,269 @@ module.exports = {
abitanti: 'M204', abitanti: 'M204',
country: 'IT', country: 'IT',
}, },
{
_id: 8094,
istat: '',
comune: 'Acquaviva',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47892',
abitanti: '',
country: 'RSM',
},
{
_id: 8095,
istat: '',
comune: 'Borgo Maggiore',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47893',
abitanti: '',
country: 'RSM',
},
{
_id: 8096,
istat: '',
comune: 'Ca\' Rigo',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47893',
abitanti: '',
country: 'RSM',
},
{
_id: 8097,
istat: '',
comune: 'Cailungo',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47893',
abitanti: '',
country: 'RSM',
},
{
_id: 8098,
istat: '',
comune: 'Casole',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47890',
abitanti: '',
country: 'RSM',
},
{
_id: 8099,
istat: '',
comune: 'Cerbaiola',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47898',
abitanti: '',
country: 'RSM',
},
{
_id: 8100,
istat: '',
comune: 'Chiesanuova',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47894',
abitanti: '',
country: 'RSM',
},
{
_id: 8101,
istat: '',
comune: 'Città di San Marino',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47890',
abitanti: '',
country: 'RSM',
},
{
_id: 8102,
istat: '',
comune: 'Dogana',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47891',
abitanti: '',
country: 'RSM',
},
{
_id: 8103,
istat: '',
comune: 'Domagnano',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47895',
abitanti: '',
country: 'RSM',
},
{
_id: 8104,
istat: '',
comune: 'Faetano',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47896',
abitanti: '',
country: 'RSM',
},
{
_id: 8105,
istat: '',
comune: 'Falciano',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47897',
abitanti: '',
country: 'RSM',
},
{
_id: 8106,
istat: '',
comune: 'Galazzano',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47891',
abitanti: '',
country: 'RSM',
},
{
_id: 8107,
istat: '',
comune: 'Gualdicciolo',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47892',
abitanti: '',
country: 'RSM',
},
{
_id: 8108,
istat: '',
comune: 'Montegiardino',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47898',
abitanti: '',
country: 'RSM',
},
{
_id: 8109,
istat: '',
comune: 'Murata',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47890',
abitanti: '',
country: 'RSM',
},
{
_id: 8110,
istat: '',
comune: 'Rovereta',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47891',
abitanti: '',
country: 'RSM',
},
{
_id: 8111,
istat: '',
comune: 'San Giovanni',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47893',
abitanti: '',
country: 'RSM',
},
{
_id: 8112,
istat: '',
comune: 'Santa Mustiola',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47890',
abitanti: '',
country: 'RSM',
},
{
_id: 8113,
istat: '',
comune: 'Serravalle',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47899',
abitanti: '',
country: 'RSM',
},
{
_id: 8114,
istat: '',
comune: 'Teglio',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47894',
abitanti: '',
country: 'RSM',
},
{
_id: 8115,
istat: '',
comune: 'Torraccia',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47895',
abitanti: '',
country: 'RSM',
},
{
_id: 8116,
istat: '',
comune: 'Valdragone',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47893',
abitanti: '',
country: 'RSM',
},
{
_id: 8117,
istat: '',
comune: 'Ventoso',
prov: 'RSM',
reg: 'RSM',
pref: '0549',
cap: '47893',
abitanti: '',
country: 'RSM',
},
], ],
}; };

View File

@@ -5,80 +5,66 @@ module.exports = {
{ {
"_id" : ObjectID("615a353c002c8298f4495be7"), "_id" : ObjectID("615a353c002c8298f4495be7"),
"idapp" : "1", "idapp" : "1",
"__v" : 0,
"label" : "Dono" "label" : "Dono"
}, },
{ {
"_id" : ObjectID("61bc466567de9a1f54b25494"), "_id" : ObjectID("61bc466567de9a1f54b25494"),
"idapp" : "1", "idapp" : "1",
"__v" : 0,
"label" : "Offerta Libera" "label" : "Offerta Libera"
}, },
{ {
"_id" : ObjectID("61bc454867de9a1f54b25462"), "_id" : ObjectID("61bc454867de9a1f54b25462"),
"idapp" : "1", "idapp" : "1",
"__v" : 0, "label" : "Baratto (scambio Beni o Servizi)"
"label" : "Baratto"
},
{
"_id" : ObjectID("61bc482667de9a1f54b2549b"),
"idapp" : "1",
"__v" : 0,
"label" : "Euro"
},
{
"_id" : ObjectID("61bc482667de9a1f54b2549b"),
"idapp" : "1",
"__v" : 0,
"label" : "Scambio di Beni"
}, },
{ {
"_id" : ObjectID("61bc482667de9a1f54b2549c"), "_id" : ObjectID("61bc482667de9a1f54b2549c"),
"idapp" : "1", "idapp" : "1",
"__v" : 0, "label" : "Scambio Lavoro"
"label" : "Scambio di Lavoro" },
{
"_id" : ObjectID("61bc482667de9a1f54b2649c"),
"idapp" : "1",
"label" : "Monete Alternative"
},
{
"_id" : ObjectID("61bc482667de9a1f54b3549e"),
"idapp" : "1",
"label" : "Euro"
}, },
{ {
"_id" : ObjectID("615a353c002c8298f4495bf7"), "_id" : ObjectID("615a353c002c8298f4495bf7"),
"idapp" : "12", "idapp" : "12",
"__v" : 0,
"label" : "Dono" "label" : "Dono"
}, },
{ {
"_id" : ObjectID("61bc466567de9a1f54b254f4"), "_id" : ObjectID("61bc466567de9a1f54b254f4"),
"idapp" : "12", "idapp" : "12",
"__v" : 0,
"label" : "Offerta Libera" "label" : "Offerta Libera"
}, },
{ {
"_id" : ObjectID("61bc454867de9a1f54b254f2"), "_id" : ObjectID("61bc454867de9a1f54b254f2"),
"idapp" : "12", "idapp" : "12",
"__v" : 0, "label" : "Baratto (scambio Beni o Servizi)"
"label" : "Baratto"
},
{
"_id" : ObjectID("61bc482667de9a1f54b254fb"),
"idapp" : "12",
"__v" : 0,
"label" : "Euro"
},
{
"_id" : ObjectID("61bc482667de9a1f54b25411"),
"idapp" : "12",
"__v" : 0,
"label" : "Scambio di Beni"
}, },
{ {
"_id" : ObjectID("61bc482667de9a1f54b25412"), "_id" : ObjectID("61bc482667de9a1f54b25412"),
"idapp" : "12", "idapp" : "12",
"__v" : 0, "label" : "Scambio Lavoro"
"label" : "Scambio di Lavoro" },
{
"_id" : ObjectID("61bc482667de9a1f64b254ab"),
"idapp" : "12",
"label" : "Monete Alternative"
},
{
"_id" : ObjectID("61bc482667de9a1f64b254fb"),
"idapp" : "12",
"label" : "Euro"
}, },
] ]
} }

View File

@@ -24,11 +24,17 @@ module.exports = {
}, },
async insertIntoDb_NoDuplicate(tablename, table, field) { async insertIntoDb_NoDuplicate(attiva, tablename, table, field) {
let numrec = 0;
try { try {
if (!attiva && await table.countDocuments({}) > 0)
return;
const pathfile = Path.join(__dirname, tablename + '.js'); const pathfile = Path.join(__dirname, tablename + '.js');
if (tools.isFileExists(pathfile)) { if (tools.isFileExists(pathfile)) {
const mydbfile = require(pathfile); const mydbfile = require(pathfile);
if (mydbfile && mydbfile.list) { if (mydbfile && mydbfile.list) {
@@ -38,10 +44,17 @@ module.exports = {
var mynewrec = new table(rec); var mynewrec = new table(rec);
if (rec.hasOwnProperty('idapp')) {
obj.idapop = rec['idapp'];
}
const exist = await table.find(obj); const exist = await table.find(obj);
if (exist.length <= 0) { if (exist.length <= 0) {
try { try {
await mynewrec.save(); const ris = await mynewrec.save();
if (ris) {
numrec++;
}
}catch (e){ }catch (e){
console.log('error ', e); console.log('error ', e);
} }
@@ -50,12 +63,63 @@ module.exports = {
} }
} }
if (numrec > 0)
console.log('*** Insert', numrec, 'record on '+tablename);
} }
} }
}catch (e){ }catch (e){
console.log('error insertIntoDb', e); console.log('error insertIntoDb', e);
} }
},
async rewriteTable(table) {
let mytab = null;
let field = '';
const {City} = require('../models/city');
const {Province} = require('../models/province');
const {Sector} = require('../models/sector');
const {Skill} = require('../models/skill');
const {SubSkill} = require('../models/subskill');
const {Contribtype} = require('../models/contribtype');
const {Level} = require('../models/level');
if (table === 'cities') {
mytab = City;
field = 'comune';
} else if (table === 'provinces') {
mytab = Province;
field = 'descr';
} else if (table === 'sectors') {
mytab = Sector;
field = 'descr';
} else if (table === 'skills') {
mytab = Skill;
field = 'descr';
} else if (table === 'subskills') {
mytab = SubSkill;
field = 'descr';
} else if (table === 'contribtypes') {
mytab = Contribtype;
field = 'label';
} else if (table === 'levels') {
mytab = Level;
field = 'descr';
}
if (mytab) {
console.log('Delete ', table)
await mytab.deleteMany({});
await this.insertIntoDb_NoDuplicate(false, table, mytab, field)
}
return true;
}, },
async popolaTabelleNuove() { async popolaTabelleNuove() {
@@ -65,45 +129,51 @@ module.exports = {
let ris = null; let ris = null;
try { try {
if (abilita) { const {City} = require('../models/city');
const {Province} = require('../models/province');
console.log('INIZIO - popolaTabelleNuove')
// Sectors // Sectors
const {Sector} = require('../models/sector'); const {Sector} = require('../models/sector');
await this.insertIntoDb_NoDuplicate('sectors', Sector, 'descr') await this.insertIntoDb_NoDuplicate(abilita, 'sectors', Sector, 'descr')
// CatGrps // CatGrps
const {CatGrp} = require('../models/catgrp'); const {CatGrp} = require('../models/catgrp');
await this.insertIntoDb_NoDuplicate('catgrps', CatGrp, 'descr') await this.insertIntoDb_NoDuplicate(abilita, 'catgrps', CatGrp, 'descr')
// Skills (Competenze) // Skills (Competenze)
const {Skill} = require('../models/skill'); const {Skill} = require('../models/skill');
await this.insertIntoDb_NoDuplicate('skills', Skill, 'descr') await this.insertIntoDb_NoDuplicate(abilita, 'skills', Skill, 'descr')
// SubSectors // SubSectors
const {SubSkill} = require('../models/subskill'); const {SubSkill} = require('../models/subskill');
await this.insertIntoDb_NoDuplicate('subskills', SubSkill, 'descr') await this.insertIntoDb_NoDuplicate(abilita, 'subskills', SubSkill, 'descr')
// Levels // Levels
const {Level} = require('../models/level'); const {Level} = require('../models/level');
await this.insertIntoDb_NoDuplicate('levels', Level, 'descr') await this.insertIntoDb_NoDuplicate(abilita, 'levels', Level, 'descr')
// Status // Status
const {StatusSkill} = require('../models/statusSkill'); const {StatusSkill} = require('../models/statusSkill');
await this.insertIntoDb_NoDuplicate('statusskills', StatusSkill, 'descr') await this.insertIntoDb_NoDuplicate(abilita, 'statusskills', StatusSkill, 'descr')
if (scrivi_citta) {
// Cities // Cities
const {City} = require('../models/city'); await this.insertIntoDb_NoDuplicate(scrivi_citta, 'cities', City, 'comune')
await this.insertIntoDb('cities', City)
// Province // Province
const {Province} = require('../models/province'); await this.insertIntoDb_NoDuplicate(scrivi_citta, 'provinces', Province, 'descr')
await this.insertIntoDb('provinces', Province) console.log('FINE - Scrivo le Città')
}
// Contribtypes // Contribtypes
const {Contribtype} = require('../models/contribtype'); const {Contribtype} = require('../models/contribtype');
await this.insertIntoDb_NoDuplicate('contribtypes', Contribtype, 'label') await this.insertIntoDb_NoDuplicate(abilita, 'contribtypes', Contribtype, 'label')
}
const {AdType} = require('../models/adtype');
await this.insertIntoDb_NoDuplicate(abilita, 'adtypes', AdType, 'descr')
console.log('FINE - popolaTabelleNuove')
}catch (e) { }catch (e) {
console.error('Err: ' + e); console.error('Err: ' + e);
} }

View File

@@ -52,6 +52,7 @@ const {Province} = require('../models/province');
const {Sector} = require('../models/sector'); const {Sector} = require('../models/sector');
const {CatGrp} = require('../models/catgrp'); const {CatGrp} = require('../models/catgrp');
const {Level} = require('../models/level'); const {Level} = require('../models/level');
const {AdType} = require('../models/adtype');
const Pickup = require('../models/pickup'); const Pickup = require('../models/pickup');
const {Newstosent} = require('../models/newstosent'); const {Newstosent} = require('../models/newstosent');
const {MyPage} = require('../models/mypage'); const {MyPage} = require('../models/mypage');
@@ -1099,6 +1100,7 @@ function load(req, res, version) {
// SKILLS: // SKILLS:
let levels = Level.findAllIdApp(idapp); let levels = Level.findAllIdApp(idapp);
let adtypes = AdType.findAllIdApp(idapp);
let skills = Skill.findAllIdApp(idapp); let skills = Skill.findAllIdApp(idapp);
let subSkills = SubSkill.findAllIdApp(idapp); let subSkills = SubSkill.findAllIdApp(idapp);
let statusSkills = StatusSkill.findAllIdApp(idapp); let statusSkills = StatusSkill.findAllIdApp(idapp);
@@ -1162,6 +1164,7 @@ function load(req, res, version) {
cities, cities,
myuserextra, myuserextra,
catgrps, catgrps,
adtypes,
]).then((arrdata) => { ]).then((arrdata) => {
// console.table(arrdata); // console.table(arrdata);
let myuser = req.user; let myuser = req.user;
@@ -1235,6 +1238,7 @@ function load(req, res, version) {
cities: arrdata[29], cities: arrdata[29],
// myuser arrdata[30] // myuser arrdata[30]
catgrps: arrdata[31], catgrps: arrdata[31],
adtypes: arrdata[32],
}); });
} }

View File

@@ -562,6 +562,8 @@ async function eseguiDbOp(idapp, mydata, locale) {
let ris = await User.DbOp(idapp, mydata); let ris = await User.DbOp(idapp, mydata);
const populate = require('../populate/populate');
let mystr = ''; let mystr = '';
try { try {
@@ -866,15 +868,46 @@ async function eseguiDbOp(idapp, mydata, locale) {
await User.setVerifiedByAportadorToALL(); await User.setVerifiedByAportadorToALL();
} else if (mydata.dbop === 'RewriteContribType') {
populate.rewriteTable('contribtypes');
} else if (mydata.dbop === 'emptyDbSkill') { } else if (mydata.dbop === 'emptyDbSkill') {
const {Sector} = require('../models/sector'); const {Sector} = require('../models/sector');
const {Skill} = require('../models/skill'); const {Skill} = require('../models/skill');
const {SubSkill} = require('../models/subskill'); const {SubSkill} = require('../models/subskill');
const {City} = require('../models/city');
const {Province} = require('../models/province');
await Sector.remove({}); await Sector.deleteMany({});
await Skill.remove({}); await Skill.deleteMany({});
await SubSkill.remove({}); await SubSkill.deleteMany({});
await City.deleteMany({});
await Province.deleteMany({});
} else if (mydata.dbop === 'PopulateTables') {
populate.popolaTabelleNuove();
} else if (mydata.dbop === 'RewriteCitiesTable') {
populate.rewriteTable('cities');
} else if (mydata.dbop === 'RewriteLevelTable') {
populate.rewriteTable('levels');
} else if (mydata.dbop === 'RewriteLevelsTable') {
populate.rewriteTable('provinces');
} else if (mydata.dbop === 'emptyCityProvinces') {
const {City} = require('../models/city');
const {Province} = require('../models/province');
await City.remove({});
await Province.remove({});
/*} else if (mydata.dbop === 'visuNave') { /*} else if (mydata.dbop === 'visuNave') {
mystr = await Nave.getNavePos(idapp, parseInt(mydata.riga), parseInt(mydata.col)); mystr = await Nave.getNavePos(idapp, parseInt(mydata.riga), parseInt(mydata.col));

View File

@@ -3,7 +3,7 @@ const tools = require('../tools/general');
const appTelegram = [tools.FREEPLANET]; const appTelegram = [tools.FREEPLANET];
const appTelegram_TEST = [tools.FREEPLANET, tools.PDNM]; const appTelegram_TEST = [tools.FREEPLANET, tools.PDNM];
const appTelegram_DEVELOP = [tools.FREEPLANET]; const appTelegram_DEVELOP = [tools.PDNM];
const appTelegramFinti = ['2', tools.CNM]; const appTelegramFinti = ['2', tools.CNM];
const appTelegramDest = [tools.FREEPLANET, tools.FREEPLANET]; const appTelegramDest = [tools.FREEPLANET, tools.FREEPLANET];

View File

@@ -1199,6 +1199,36 @@ module.exports = {
return query; return query;
}, },
getFilterParam: function(filter, fieldsearch) {
let myregexp = {};
myregexp = new RegExp(filter.trim().replace(' ', '|'), 'ig');
let query = [];
const myfilters = [];
for (const rec of fieldsearch){
let data = {};
if (rec.type === this.FieldType.exact) {
data[rec.field] = filter.trim();
} else if (rec.type === this.FieldType.string) {
data[rec.field] = myregexp;
} else if ((rec.type === this.FieldType.number) ||
(rec.type === this.FieldType.hours)) {
data[rec.field] = parseFloat(filter.trim());
}
if (data)
myfilters.push(data);
}
if (myfilters.length > 0) {
query = [
{$match: {$or: myfilters}},
];
}
return query;
},
getQueryTable: function(idapp, params) { getQueryTable: function(idapp, params) {
if (typeof params.startRow !== 'number') { if (typeof params.startRow !== 'number') {
@@ -1212,27 +1242,10 @@ module.exports = {
let query = []; let query = [];
if (params.filter && params.fieldsearch) { if (params.filter && params.fieldsearch) {
const querytemp = this.getFilterParam(params.filter, params.fieldsearch);
let myregexp = {}; if (querytemp){
myregexp = new RegExp(params.filter.trim().replace(' ', '|'), 'ig'); query = [...query, ...querytemp]
const myfilters = [];
params.fieldsearch.forEach((rec) => {
const data = {};
if (rec.type === this.FieldType.exact) {
data[rec.field] = params.filter.trim();
} else if (rec.type === this.FieldType.string) {
data[rec.field] = myregexp;
} else if ((rec.type === this.FieldType.number) ||
(rec.type === this.FieldType.hours)) {
data[rec.field] = parseFloat(params.filter.trim());
} }
myfilters.push(data);
});
query = [
{$match: {$or: myfilters}},
];
} }
let filtriadded = []; let filtriadded = [];
@@ -1505,6 +1518,13 @@ module.exports = {
} }
} }
if (params.filter && params.fieldsearch_last) {
const querytemp = this.getFilterParam(params.filter, params.fieldsearch_last);
if (querytemp){
query = [...query, ...querytemp]
}
}
} else { } else {
// VECCHIA VERSIONE // VECCHIA VERSIONE
const q1 = this.getLookup(params, 1); const q1 = this.getLookup(params, 1);
@@ -2447,6 +2467,7 @@ module.exports = {
sulServer() { sulServer() {
return process.env.LOCALE !== '1' return process.env.LOCALE !== '1'
} },
}; };