nuova veste grafica: myskills, mygoods, mybachecas, myhosps,

- cambiato id (da numero a stringa)
This commit is contained in:
Surya Paolo
2023-04-07 02:45:21 +02:00
parent 8a77dabc22
commit 94ef2c4c85
15 changed files with 1582 additions and 972 deletions

View File

@@ -6,7 +6,8 @@ mongoose.level = 'F';
const tools = require('../tools/general');
const {ObjectID} = require('mongodb');
const shared_consts = require('../tools/shared_nodejs');
const { ObjectID } = require('mongodb');
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
@@ -21,7 +22,7 @@ const MyHospSchema = new Schema({
type: String,
required: true,
},
userId: {type: Schema.Types.ObjectId, ref: 'User'},
userId: { type: Schema.Types.ObjectId, ref: 'User' },
visibile: {
type: Boolean
},
@@ -85,38 +86,27 @@ const MyHospSchema = new Schema({
},
date_created: {
type: Date,
default: Date.now,
},
date_updated: {
type: Date,
},
});
MyHospSchema.pre('save', async function(next) {
MyHospSchema.pre('save', async function (next) {
if (this.isNew) {
const myrec = await MyHosp.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;
}
this.date_created = new Date();
if (!this.date_created)
this.date_created = new Date();
}
next();
});
MyHospSchema.statics.findAllIdApp = async function(idapp) {
MyHospSchema.statics.findAllIdApp = async function (idapp) {
const MyHosp = this;
const query = [
{$match: {idapp}},
{$sort: {descr: 1}},
{ $match: { idapp } },
{ $sort: { descr: 1 } },
];
return await MyHosp.aggregate(query).then((arrrec) => {
@@ -125,18 +115,18 @@ MyHospSchema.statics.findAllIdApp = async function(idapp) {
};
MyHospSchema.statics.getFieldsForSearch = function() {
MyHospSchema.statics.getFieldsForSearch = function () {
return [];
};
MyHospSchema.statics.getFieldsLastForSearch = function() {
MyHospSchema.statics.getFieldsLastForSearch = function () {
return [
{field: 'descr', type: tools.FieldType.string},
{field: 'note', type: tools.FieldType.string},
{ field: 'descr', type: tools.FieldType.string },
{ field: 'note', type: tools.FieldType.string },
];
};
MyHospSchema.statics.executeQueryTable = function(idapp, params, user) {
MyHospSchema.statics.executeQueryTable = function (idapp, params, user) {
params.fieldsearch = this.getFieldsForSearch();
params.fieldsearch_last = this.getFieldsLastForSearch();
@@ -147,69 +137,24 @@ MyHospSchema.statics.executeQueryTable = function(idapp, params, user) {
lk_FF: '_id',
lk_as: 'user',
af_objId_tab: 'myId',
lk_proj: {
visibile: 1,
typeHosp: 1,
numMaxPeopleHosp: 1,
accomodation: 1,
preferences: 1,
photos: 1,
idContribType: 1,
idCity: 1,
pub_to_share: 1,
note: 1,
website: 1,
link_maplocation: 1,
descr: 1,
date_created: 1,
date_updated: 1,
userId: 1,
username: 1,
name: 1,
surname: 1,
lasttimeonline: 1,
'profile.img': 1,
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
'mycities': 1,
reported: 1,
},
lk_proj: this.getProject(),
},
};
params = {...params, ...otherparams};
params = { ...params, ...otherparams };
return tools.executeQueryTable(this, idapp, params, user);
};
MyHospSchema.statics.getMyRecById = function(idapp, id) {
MyHospSchema.statics.getMyRecById = function (idapp, id) {
const MyHosp = this;
let myparsid = {
$or: [
{
'_id': parseInt(idGood)
},
{
'_id': idGood,
}]
};
const myparsid = { '_id': id };
if (tools.isNumber(id)) {
myparsid = {'_id': parseInt(id)};
} else {
myparsid = {'_id': id};
}
const query = [
let query = [
{
'$match': {
'$and': [
'$match':
myparsid,
],
},
},
{
'$match': {
@@ -252,35 +197,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
},
},
{
'$project': {
visibile: 1,
typeHosp: 1,
numMaxPeopleHosp: 1,
accomodation: 1,
preferences: 1,
photos: 1,
idContribType: 1,
idCity: 1,
pub_to_share: 1,
note: 1,
website: 1,
link_maplocation: 1,
descr: 1,
date_created: 1,
date_updated: 1,
'userId': 1,
'username': 1,
'name': 1,
'surname': 1,
'comune': 1,
'mycities': 1,
'profile.img': 1,
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
$project: this.getProject(),
},
{
'$lookup': {
@@ -306,35 +223,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
},
},
{
'$project': {
visibile: 1,
typeHosp: 1,
numMaxPeopleHosp: 1,
accomodation: 1,
preferences: 1,
photos: 1,
idContribType: 1,
idCity: 1,
pub_to_share: 1,
note: 1,
website: 1,
link_maplocation: 1,
descr: 1,
date_created: 1,
date_updated: 1,
'userId': 1,
'username': 1,
'name': 1,
'surname': 1,
'comune': 1,
'mycities': 1,
'profile.img': 1,
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
$project: this.getProject(),
},
{
'$lookup': {
@@ -360,35 +249,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
},
},
{
'$project': {
visibile: 1,
typeHosp: 1,
numMaxPeopleHosp: 1,
accomodation: 1,
preferences: 1,
photos: 1,
idContribType: 1,
idCity: 1,
pub_to_share: 1,
note: 1,
website: 1,
link_maplocation: 1,
descr: 1,
date_created: 1,
date_updated: 1,
'userId': 1,
'username': 1,
'name': 1,
'surname': 1,
'comune': 1,
'mycities': 1,
'profile.img': 1,
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
$project: this.getProject(),
},
/*{
'$lookup': {
@@ -414,35 +275,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
},
},
{
'$project': {
visibile: 1,
typeHosp: 1,
numMaxPeopleHosp: 1,
accomodation: 1,
preferences: 1,
photos: 1,
idContribType: 1,
idCity: 1,
pub_to_share: 1,
note: 1,
website: 1,
link_maplocation: 1,
descr: 1,
date_created: 1,
date_updated: 1,
'userId': 1,
'username': 1,
'name': 1,
'surname': 1,
'comune': 1,
'mycities': 1,
'profile.img': 1,
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
$project: this.getProject(),
},
{
'$lookup': {
@@ -467,38 +300,17 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
},
},
},
];
let numtab = tools.getNumTabByTable(shared_consts.TABLES_MYHOSPS);
const objadd = tools.addNumFavoriteAndBookmarkToQuery(idapp, numtab);
query = [...query, ...objadd.query];
query = [...query,
{
'$project': {
visibile: 1,
typeHosp: 1,
numMaxPeopleHosp: 1,
accomodation: 1,
preferences: 1,
photos: 1,
idContribType: 1,
'profile.username_telegram': 1,
idCity: 1,
pub_to_share: 1,
note: 1,
website: 1,
link_maplocation: 1,
descr: 1,
date_created: 1,
date_updated: 1,
'userId': 1,
'username': 1,
'name': 1,
'surname': 1,
'comune': 1,
'mycities': 1,
'profile.img': 1,
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},
$project: this.getProject(objadd.proj),
}
];
return MyHosp.aggregate(query).then((rec) => {
@@ -506,13 +318,34 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
});
};
MyHospSchema.statics.getCompleteRecord = function(idapp, id) {
MyHospSchema.statics.getCompleteRecord = function (idapp, id) {
const MyHosp = this;
return MyHosp.getMyRecById(idapp, id);
};
MyHospSchema.statics.getProject = function () {
let proj = {
visibile: 1,
typeHosp: 1,
numMaxPeopleHosp: 1,
accomodation: 1,
preferences: 1,
photos: 1,
website: 1,
link_maplocation: 1,
//**ADDFIELD_MYHOSP
};
const proj_add = shared_consts.getProjectForAll()
return Object.assign({}, proj, proj_add);
}
const MyHosp = mongoose.model('MyHosp', MyHospSchema);
module.exports = {MyHosp};
module.exports = { MyHosp };