new version Visualizzazione Service

This commit is contained in:
Surya Paolo
2023-04-04 15:26:56 +02:00
parent 6d1ad4132f
commit 8a77dabc22
8 changed files with 198 additions and 63 deletions

View File

@@ -15,7 +15,10 @@ mongoose.plugin(schema => {
const MyBachecaSchema = new Schema({
_id: {
type: Number,
type: String,
default: function () {
return new ObjectID().toString();
},
},
idapp: {
type: String,
@@ -88,17 +91,6 @@ const MyBachecaSchema = new Schema({
MyBachecaSchema.pre('save', async function (next) {
if (this.isNew) {
const myrec = await MyBacheca.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();
}
@@ -171,6 +163,8 @@ MyBachecaSchema.statics.executeQueryTable = function (idapp, params, user) {
'profile.img': 1,
"profile.mygroups": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
'profile.username_telegram': 1,
reported: 1,
date_report: 1,
username_who_report: 1,
@@ -186,13 +180,21 @@ MyBachecaSchema.statics.executeQueryTable = function (idapp, params, user) {
MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
const MyBacheca = this;
let myparsid = {
$or: [
{
'_id': parseInt(idGood)
},
{
'_id': idGood,
}]
};
const query = [
{
'$match': {
'$and': [
{
'_id': parseInt(id),
},
myparsid,
],
},
},
@@ -268,6 +270,7 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},
@@ -326,6 +329,7 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},
@@ -384,6 +388,7 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},
@@ -442,6 +447,7 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},
@@ -500,6 +506,7 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},

View File

@@ -6,7 +6,7 @@ mongoose.level = 'F';
const tools = require('../tools/general');
const {ObjectID} = require('mongodb');
const { ObjectID } = require('mongodb');
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
@@ -15,13 +15,13 @@ mongoose.plugin(schema => {
const MyGoodSchema = new Schema({
_id: {
type: Number,
type: String,
},
idapp: {
type: String,
required: true,
},
userId: {type: Schema.Types.ObjectId, ref: 'User'},
userId: { type: Schema.Types.ObjectId, ref: 'User' },
idSectorGood: {
type: Number,
},
@@ -87,9 +87,9 @@ const MyGoodSchema = new Schema({
},
});
MyGoodSchema.pre('save', async function(next) {
MyGoodSchema.pre('save', async function (next) {
if (this.isNew) {
const myrec = await MyGood.findOne().limit(1).sort({_id: -1});
const myrec = await MyGood.findOne().limit(1).sort({ _id: -1 });
if (!!myrec) {
if (myrec._doc._id === 0)
this._id = 1;
@@ -106,12 +106,12 @@ MyGoodSchema.pre('save', async function(next) {
next();
});
MyGoodSchema.statics.findAllIdApp = async function(idapp) {
MyGoodSchema.statics.findAllIdApp = async function (idapp) {
const MyGood = this;
const query = [
{$match: {idapp}},
{$sort: {descr: 1}},
{ $match: { idapp } },
{ $sort: { descr: 1 } },
];
return await MyGood.aggregate(query).then((arrrec) => {
@@ -120,21 +120,21 @@ MyGoodSchema.statics.findAllIdApp = async function(idapp) {
};
MyGoodSchema.statics.getFieldsForSearch = function() {
MyGoodSchema.statics.getFieldsForSearch = function () {
return [];
};
MyGoodSchema.statics.getFieldsLastForSearch = function() {
MyGoodSchema.statics.getFieldsLastForSearch = function () {
return [
{field: 'note', type: tools.FieldType.string},
{field: 'descr', type: tools.FieldType.string},
{field: 'recGood.descr', type: tools.FieldType.string},
{field: 'MyGood.descr', type: tools.FieldType.string},
{ field: 'note', type: tools.FieldType.string },
{ field: 'descr', type: tools.FieldType.string },
{ field: 'recGood.descr', type: tools.FieldType.string },
{ field: 'MyGood.descr', type: tools.FieldType.string },
];
};
MyGoodSchema.statics.executeQueryTable = function(idapp, params, user) {
MyGoodSchema.statics.executeQueryTable = function (idapp, params, user) {
params.fieldsearch = this.getFieldsForSearch();
params.fieldsearch_last = this.getFieldsLastForSearch();
@@ -151,6 +151,7 @@ MyGoodSchema.statics.executeQueryTable = function(idapp, params, user) {
MyGood: 1,
idStatusGood: 1,
idContribType: 1,
'profile.username_telegram': 1,
idCity: 1,
pub_to_share: 1,
numLevel: 1,
@@ -172,26 +173,35 @@ MyGoodSchema.statics.executeQueryTable = function(idapp, params, user) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},
};
params = {...params, ...otherparams};
params = { ...params, ...otherparams };
return tools.executeQueryTable(this, idapp, params, user);
};
MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
MyGoodSchema.statics.getMyRecById = function (idapp, idGood) {
const MyGood = this;
let myparsid = {
$or: [
{
'_id': parseInt(idGood)
},
{
'_id': idGood,
}]
};
const query = [
{
'$match': {
'$and': [
{
'_id': parseInt(idGood),
},
myparsid,
],
},
},
@@ -266,6 +276,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},
@@ -323,6 +334,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},
@@ -381,6 +393,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},
@@ -438,6 +451,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},
@@ -495,6 +509,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},
@@ -505,7 +520,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
});
};
MyGoodSchema.statics.getCompleteRecord = function(idapp, id) {
MyGoodSchema.statics.getCompleteRecord = function (idapp, id) {
const MyGood = this;
return MyGood.getMyRecById(idapp, id);
@@ -515,4 +530,4 @@ MyGoodSchema.statics.getCompleteRecord = function(idapp, id) {
const MyGood = mongoose.model('MyGood', MyGoodSchema);
module.exports = {MyGood};
module.exports = { MyGood };

View File

@@ -15,7 +15,7 @@ mongoose.plugin(schema => {
const MyGroupSchema = new Schema({
_id: {
type: Number,
type: String,
},
idapp: {
type: String,

View File

@@ -15,7 +15,7 @@ mongoose.plugin(schema => {
const MyHospSchema = new Schema({
_id: {
type: Number,
type: String,
},
idapp: {
type: String,
@@ -172,6 +172,7 @@ MyHospSchema.statics.executeQueryTable = function(idapp, params, user) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
'mycities': 1,
reported: 1,
},
@@ -186,13 +187,27 @@ MyHospSchema.statics.executeQueryTable = function(idapp, params, user) {
MyHospSchema.statics.getMyRecById = function(idapp, id) {
const MyHosp = this;
let myparsid = {
$or: [
{
'_id': parseInt(idGood)
},
{
'_id': idGood,
}]
};
if (tools.isNumber(id)) {
myparsid = {'_id': parseInt(id)};
} else {
myparsid = {'_id': id};
}
const query = [
{
'$match': {
'$and': [
{
'_id': parseInt(id),
},
myparsid,
],
},
},
@@ -263,6 +278,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},
@@ -316,6 +332,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},
@@ -369,6 +386,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},
@@ -422,6 +440,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},
@@ -457,6 +476,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
preferences: 1,
photos: 1,
idContribType: 1,
'profile.username_telegram': 1,
idCity: 1,
pub_to_share: 1,
note: 1,
@@ -475,6 +495,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},

View File

@@ -15,7 +15,10 @@ mongoose.plugin(schema => {
const MySkillSchema = new Schema({
_id: {
type: Number,
type: String,
default: function () {
return new ObjectID().toString();
},
},
idapp: {
type: String,
@@ -92,17 +95,6 @@ const MySkillSchema = new Schema({
MySkillSchema.pre('save', async function(next) {
if (this.isNew) {
const myrec = await MySkill.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();
}
@@ -153,6 +145,7 @@ MySkillSchema.statics.executeQueryTable = function(idapp, params, user) {
myskill: 1,
idStatusSkill: 1,
idContribType: 1,
'profile.username_telegram': 1,
idCity: 1,
pub_to_share: 1,
numLevel: 1,
@@ -173,6 +166,7 @@ MySkillSchema.statics.executeQueryTable = function(idapp, params, user) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},
@@ -186,13 +180,19 @@ MySkillSchema.statics.executeQueryTable = function(idapp, params, user) {
MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
const MySkill = this;
let myparskill = {};
if (tools.isNumber(idSkill)) {
myparskill = {'_id': parseInt(idSkill)};
} else {
myparskill = {'_id': idSkill};
}
const query = [
{
'$match': {
'$and': [
{
'_id': parseInt(idSkill),
},
myparskill,
],
},
},
@@ -266,6 +266,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},
@@ -322,6 +323,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},
@@ -378,6 +380,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},
@@ -436,6 +439,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},
@@ -492,6 +496,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
"profile.mygroups": 1,
"profile.mycircuits": 1,
'profile.qualifica': 1,
'profile.resid_province': 1,
reported: 1,
},
},

View File

@@ -449,7 +449,21 @@ const UserSchema = new mongoose.Schema({
},
noFoto: {
type: Boolean,
}
},
bookmark: [
{
_id: false,
id: { type: String },
tab: { type: Number },
},
],
favorite: [
{
_id: false,
id: { type: String },
tab: { type: Number },
},
],
},
});
@@ -1882,6 +1896,33 @@ UserSchema.statics.removeReqFriend = async function (
{ $pull: { 'profile.req_friends': { username: { $in: [usernameDest] } } } });
};
// Rimuovo il Favorite
UserSchema.statics.removeFavorite = async function (
idapp, id, tab) {
return await User.updateOne({ idapp, username },
{ $pull: { 'profile.favorite': { id: { $in: [id] }, tab } } });
};
// Aggiungo il Favorite
UserSchema.statics.addFavorite = async function (
idapp, username, id, tab) {
return await User.updateOne({ idapp, username },
{ $push: { 'profile.favorite': { id, tab } } });
};
// Rimuovo il Bookmark
UserSchema.statics.removeBookmark = async function (
idapp, id, tab) {
return await User.updateOne({ idapp, username },
{ $pull: { 'profile.bookmark': { id: { $in: [id] }, tab } } });
};
// Aggiungo il Bookmark
UserSchema.statics.addBookmark = async function (
idapp, username, id, tab) {
return await User.updateOne({ idapp, username },
{ $push: { 'profile.bookmark': { id, tab } } });
};
UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, usernameDest, cmd, value, disablenotif) {
const { SendNotif } = require('../models/sendnotif');