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

@@ -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 };