2022-09-14 11:32:04 +02:00
|
|
|
const mongoose = require('mongoose').set('debug', false);
|
2022-04-07 08:19:40 +02:00
|
|
|
const Schema = mongoose.Schema;
|
|
|
|
|
|
|
|
|
|
mongoose.Promise = global.Promise;
|
|
|
|
|
mongoose.level = 'F';
|
|
|
|
|
|
|
|
|
|
const tools = require('../tools/general');
|
|
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
const { ObjectID } = require('mongodb');
|
2022-04-07 08:19:40 +02:00
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
const { Movement } = require('../models/movement');
|
|
|
|
|
const { Account } = require('../models/account');
|
2022-10-13 21:10:07 +02:00
|
|
|
|
2022-09-12 18:37:08 +02:00
|
|
|
const i18n = require('i18n');
|
|
|
|
|
|
2022-04-07 08:19:40 +02:00
|
|
|
// Resolving error Unknown modifier: $pushAll
|
|
|
|
|
mongoose.plugin(schema => {
|
|
|
|
|
schema.options.usePushEach = true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const CircuitSchema = new Schema({
|
2022-09-03 13:06:58 +02:00
|
|
|
_id: {
|
2022-09-14 11:32:04 +02:00
|
|
|
type: String,
|
2022-12-15 21:57:38 +01:00
|
|
|
default: function () {
|
2022-10-22 15:38:15 +02:00
|
|
|
return new ObjectID().toString();
|
|
|
|
|
},
|
2022-04-07 08:19:40 +02:00
|
|
|
},
|
2022-08-30 17:00:48 +02:00
|
|
|
idapp: {
|
|
|
|
|
type: String,
|
|
|
|
|
required: true,
|
|
|
|
|
},
|
2022-08-17 00:36:47 +02:00
|
|
|
groupnameId: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
2022-04-24 17:02:10 +02:00
|
|
|
name: {
|
2022-04-07 08:19:40 +02:00
|
|
|
type: String,
|
2022-04-24 17:02:10 +02:00
|
|
|
unique: true,
|
2022-04-07 08:19:40 +02:00
|
|
|
},
|
2022-08-30 17:00:48 +02:00
|
|
|
path: {
|
|
|
|
|
type: String,
|
|
|
|
|
unique: true,
|
|
|
|
|
},
|
2022-04-24 17:02:10 +02:00
|
|
|
subname: {
|
2022-04-07 08:19:40 +02:00
|
|
|
type: String,
|
|
|
|
|
},
|
2022-09-18 20:17:24 +02:00
|
|
|
idCity: [
|
|
|
|
|
{
|
|
|
|
|
type: Number,
|
|
|
|
|
}],
|
|
|
|
|
pub_to_share: {
|
2022-09-19 14:37:57 +02:00
|
|
|
type: Number, // PUB_TO_SHARE_ALL, PUB_TO_SHARE_ONLY_TABLE_FOLLOW
|
2022-09-18 20:17:24 +02:00
|
|
|
},
|
2022-09-19 14:37:57 +02:00
|
|
|
visibility: [
|
|
|
|
|
{
|
|
|
|
|
type: Number,
|
|
|
|
|
},
|
|
|
|
|
],
|
2022-08-17 00:36:47 +02:00
|
|
|
longdescr: {
|
2022-04-07 08:19:40 +02:00
|
|
|
type: String,
|
|
|
|
|
},
|
2022-08-18 05:26:50 +02:00
|
|
|
regulation: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
2022-04-07 08:19:40 +02:00
|
|
|
systemUserDescr: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
systemUserId: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
totCircolante: {
|
|
|
|
|
type: Number,
|
|
|
|
|
},
|
|
|
|
|
totTransato: {
|
|
|
|
|
type: Number,
|
|
|
|
|
},
|
|
|
|
|
nome_valuta: {
|
|
|
|
|
type: String,
|
|
|
|
|
maxlength: 20,
|
|
|
|
|
},
|
2022-04-24 17:02:10 +02:00
|
|
|
symbol: {
|
2022-04-07 08:19:40 +02:00
|
|
|
type: String,
|
2022-09-03 13:06:58 +02:00
|
|
|
maxlength: 7,
|
2022-09-12 18:37:08 +02:00
|
|
|
},
|
|
|
|
|
color: {
|
|
|
|
|
type: String,
|
2022-04-07 08:19:40 +02:00
|
|
|
},
|
2022-04-24 17:02:10 +02:00
|
|
|
abbrev: {
|
2022-04-07 08:19:40 +02:00
|
|
|
type: String,
|
2022-09-03 13:06:58 +02:00
|
|
|
maxlength: 7,
|
2022-04-07 08:19:40 +02:00
|
|
|
},
|
|
|
|
|
compara_valuta: {
|
|
|
|
|
type: Number,
|
|
|
|
|
default: 1,
|
|
|
|
|
},
|
|
|
|
|
compara_euro: {
|
|
|
|
|
type: Number,
|
|
|
|
|
default: 1,
|
|
|
|
|
},
|
|
|
|
|
valuta_per_euro: {
|
|
|
|
|
type: Number,
|
|
|
|
|
default: 1,
|
|
|
|
|
},
|
|
|
|
|
fido_scoperto_default: {
|
|
|
|
|
type: Number,
|
|
|
|
|
},
|
2022-09-11 11:45:33 +02:00
|
|
|
qta_max_default: {
|
|
|
|
|
type: Number,
|
|
|
|
|
},
|
2023-01-03 16:51:32 +01:00
|
|
|
fido_scoperto_default_grp: {
|
|
|
|
|
type: Number,
|
|
|
|
|
},
|
|
|
|
|
qta_max_default_grp: {
|
|
|
|
|
type: Number,
|
|
|
|
|
},
|
2022-04-07 08:19:40 +02:00
|
|
|
data_costituz: {
|
|
|
|
|
type: Date,
|
|
|
|
|
},
|
|
|
|
|
deperimento: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
},
|
|
|
|
|
freq_deper: { // H, D, W, M, Y
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
minuto_deper: {
|
|
|
|
|
type: Number,
|
|
|
|
|
},
|
|
|
|
|
ora_deper: {
|
|
|
|
|
type: Number,
|
|
|
|
|
},
|
|
|
|
|
giorno_deper: {
|
|
|
|
|
type: Number,
|
|
|
|
|
},
|
|
|
|
|
mese_deper: {
|
|
|
|
|
type: Number,
|
|
|
|
|
},
|
|
|
|
|
ultimo_deper: {
|
|
|
|
|
type: Date,
|
|
|
|
|
},
|
|
|
|
|
durata_deper: {
|
|
|
|
|
type: Number,
|
|
|
|
|
},
|
|
|
|
|
// -------------
|
2022-08-26 03:33:13 +02:00
|
|
|
createdBy: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
date_created: {
|
|
|
|
|
type: Date,
|
|
|
|
|
},
|
|
|
|
|
date_updated: {
|
|
|
|
|
type: Date,
|
|
|
|
|
},
|
|
|
|
|
admins: [
|
|
|
|
|
{
|
2022-12-15 21:57:38 +01:00
|
|
|
username: { type: String },
|
|
|
|
|
date: { type: Date },
|
2022-08-26 03:33:13 +02:00
|
|
|
},
|
|
|
|
|
],
|
2022-09-11 11:45:33 +02:00
|
|
|
photos: [
|
|
|
|
|
{
|
|
|
|
|
imagefile: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
alt: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
description: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
}],
|
2022-08-26 03:33:13 +02:00
|
|
|
req_users: [
|
|
|
|
|
{
|
|
|
|
|
_id: false,
|
2022-12-15 21:57:38 +01:00
|
|
|
username: { type: String },
|
|
|
|
|
date: { type: Date },
|
2022-08-26 03:33:13 +02:00
|
|
|
}], // username
|
|
|
|
|
refused_users: [
|
|
|
|
|
{
|
|
|
|
|
_id: false,
|
2022-12-15 21:57:38 +01:00
|
|
|
username: { type: String },
|
|
|
|
|
date: { type: Date },
|
2022-08-26 03:33:13 +02:00
|
|
|
}], // username
|
2023-01-03 16:51:32 +01:00
|
|
|
req_groups: [
|
|
|
|
|
{
|
|
|
|
|
_id: false,
|
|
|
|
|
groupname: { type: String },
|
|
|
|
|
date: { type: Date },
|
|
|
|
|
}], // username
|
|
|
|
|
refused_groups: [
|
|
|
|
|
{
|
|
|
|
|
_id: false,
|
|
|
|
|
groupname: { type: String },
|
|
|
|
|
date: { type: Date },
|
|
|
|
|
}], // username
|
2022-08-26 03:33:13 +02:00
|
|
|
deleted: {
|
|
|
|
|
type: Boolean,
|
2022-09-03 13:06:58 +02:00
|
|
|
default: false,
|
2022-08-26 03:33:13 +02:00
|
|
|
},
|
2022-09-22 11:06:18 +02:00
|
|
|
transactionsEnabled: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
},
|
2022-10-22 15:38:15 +02:00
|
|
|
numMembers: {
|
|
|
|
|
type: Number,
|
|
|
|
|
default: 0,
|
|
|
|
|
},
|
2022-10-08 14:25:00 +02:00
|
|
|
status: {
|
|
|
|
|
type: Number,
|
|
|
|
|
default: 0,
|
|
|
|
|
},
|
2022-09-11 11:45:33 +02:00
|
|
|
});
|
2022-04-07 08:19:40 +02:00
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
CircuitSchema.pre('save', async function (next) {
|
2022-09-02 02:25:38 +02:00
|
|
|
if (this.isNew) {
|
2022-09-14 11:32:04 +02:00
|
|
|
this._id = new ObjectID().toString();
|
2022-09-02 02:25:38 +02:00
|
|
|
|
|
|
|
|
this.date_created = new Date();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
CircuitSchema.statics.findAllIdApp = async function (idapp) {
|
2022-08-26 03:33:13 +02:00
|
|
|
const Circuit = this;
|
2022-04-07 08:19:40 +02:00
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
const myfind = { idapp, deleted: false };
|
2022-04-07 08:19:40 +02:00
|
|
|
|
2022-09-03 13:06:58 +02:00
|
|
|
const whatToShow = this.getWhatToShow(idapp, '');
|
|
|
|
|
|
2023-03-05 22:04:14 +01:00
|
|
|
return await Circuit.find(myfind, whatToShow).sort({status: -1, numMembers: -1, name: 1});
|
2022-04-07 08:19:40 +02:00
|
|
|
};
|
|
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
CircuitSchema.statics.getFieldsForSearch = function () {
|
2022-04-07 08:19:40 +02:00
|
|
|
return [
|
2023-02-06 22:58:10 +01:00
|
|
|
{ field: 'name', type: tools.FieldType.string },
|
|
|
|
|
{ field: 'subname', type: tools.FieldType.string },
|
|
|
|
|
{ field: 'path', type: tools.FieldType.string },
|
2022-12-15 21:57:38 +01:00
|
|
|
{ field: 'nome_valuta', type: tools.FieldType.string },
|
|
|
|
|
{ field: 'descr', type: tools.FieldType.string },
|
2022-12-14 22:07:17 +01:00
|
|
|
];
|
2022-04-07 08:19:40 +02:00
|
|
|
};
|
|
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
CircuitSchema.statics.executeQueryTable = function (idapp, params, user) {
|
2022-04-07 08:19:40 +02:00
|
|
|
params.fieldsearch = this.getFieldsForSearch();
|
2022-09-19 14:37:57 +02:00
|
|
|
return tools.executeQueryTable(this, idapp, params, user);
|
2022-04-07 08:19:40 +02:00
|
|
|
};
|
|
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
CircuitSchema.statics.getWhatToShow = function (idapp, username) {
|
2022-08-26 03:33:13 +02:00
|
|
|
// FOR ME, PERMIT ALL
|
|
|
|
|
return {
|
2022-09-14 11:32:04 +02:00
|
|
|
_id: 1,
|
2022-08-26 03:33:13 +02:00
|
|
|
groupnameId: 1,
|
2022-08-30 17:00:48 +02:00
|
|
|
path: 1,
|
2022-08-26 03:33:13 +02:00
|
|
|
name: 1,
|
|
|
|
|
subname: 1,
|
|
|
|
|
longdescr: 1,
|
|
|
|
|
regulation: 1,
|
2022-10-22 15:38:15 +02:00
|
|
|
numMembers: 1,
|
2022-09-14 17:37:29 +02:00
|
|
|
totCircolante: 1,
|
|
|
|
|
totTransato: 1,
|
2022-08-26 03:33:13 +02:00
|
|
|
systemUserId: 1,
|
2022-09-02 02:25:38 +02:00
|
|
|
createdBy: 1,
|
|
|
|
|
date_created: 1,
|
|
|
|
|
date_updated: 1,
|
2022-08-26 03:33:13 +02:00
|
|
|
nome_valuta: 1,
|
2022-09-12 18:37:08 +02:00
|
|
|
fido_scoperto_default: 1,
|
2023-01-03 16:51:32 +01:00
|
|
|
qta_max_default: 1,
|
|
|
|
|
fido_scoperto_default_grp: 1,
|
|
|
|
|
qta_max_default_grp: 1,
|
2022-09-22 11:06:18 +02:00
|
|
|
deperimento: 1,
|
|
|
|
|
transactionsEnabled: 1,
|
2022-10-08 14:25:00 +02:00
|
|
|
status: 1,
|
2022-09-19 19:40:30 +02:00
|
|
|
valuta_per_euro: 1,
|
2022-08-26 03:33:13 +02:00
|
|
|
symbol: 1,
|
2022-09-18 20:17:24 +02:00
|
|
|
idCity: 1,
|
|
|
|
|
pub_to_share: 1,
|
2022-09-19 14:37:57 +02:00
|
|
|
visibility: 1,
|
2022-09-12 18:37:08 +02:00
|
|
|
color: 1,
|
2022-08-26 03:33:13 +02:00
|
|
|
abbrev: 1,
|
|
|
|
|
data_costituz: 1,
|
2022-09-11 11:45:33 +02:00
|
|
|
photos: 1,
|
2022-09-02 02:25:38 +02:00
|
|
|
admins: 1,
|
|
|
|
|
req_users: 1,
|
|
|
|
|
refused_users: 1,
|
2023-01-03 16:51:32 +01:00
|
|
|
req_groups: 1,
|
|
|
|
|
refused_groups: 1,
|
2022-09-18 20:17:24 +02:00
|
|
|
'mycities': 1,
|
2022-08-26 03:33:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2022-09-20 11:14:23 +02:00
|
|
|
// Aggiungi agli Admin del Circuito
|
2022-12-15 21:57:38 +01:00
|
|
|
CircuitSchema.statics.addToAdminOfMyCircuit = async function (idapp, username, name) {
|
2022-09-20 11:14:23 +02:00
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
return await Circuit.updateOne({ idapp, name },
|
|
|
|
|
{
|
|
|
|
|
$push:
|
2022-09-20 11:14:23 +02:00
|
|
|
{
|
2022-12-15 21:57:38 +01:00
|
|
|
admins: {
|
|
|
|
|
username,
|
|
|
|
|
date: new Date(),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
2022-09-20 11:14:23 +02:00
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2022-08-30 17:00:48 +02:00
|
|
|
// Rimuovi dagli Admin del Circuito
|
2022-12-15 21:57:38 +01:00
|
|
|
CircuitSchema.statics.removeAdminOfMyCircuit = async function (idapp, username, name) {
|
2022-08-30 17:00:48 +02:00
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
return await Circuit.updateOne({ idapp, name },
|
|
|
|
|
{ $pull: { admins: { username: { $in: [username] } } } });
|
2022-08-30 17:00:48 +02:00
|
|
|
};
|
|
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
CircuitSchema.statics.getWhatToShow_Unknown = function (idapp, username) {
|
2022-08-26 03:33:13 +02:00
|
|
|
return {
|
|
|
|
|
groupnameId: 1,
|
2022-08-30 17:00:48 +02:00
|
|
|
path: 1,
|
2022-08-26 03:33:13 +02:00
|
|
|
name: 1,
|
|
|
|
|
subname: 1,
|
|
|
|
|
longdescr: 1,
|
|
|
|
|
regulation: 1,
|
2022-10-22 15:38:15 +02:00
|
|
|
numMembers: 1,
|
2022-08-26 03:33:13 +02:00
|
|
|
systemUserId: 1,
|
|
|
|
|
founderUserId: 1,
|
|
|
|
|
nome_valuta: 1,
|
2022-09-14 17:37:29 +02:00
|
|
|
totCircolante: 1,
|
|
|
|
|
totTransato: 1,
|
2022-09-12 18:37:08 +02:00
|
|
|
fido_scoperto_default: 1,
|
2023-01-03 16:51:32 +01:00
|
|
|
fido_scoperto_default_grp: 1,
|
|
|
|
|
qta_max_default_grp: 1,
|
2022-09-12 18:37:08 +02:00
|
|
|
qta_max_default: 1,
|
2022-09-19 19:40:30 +02:00
|
|
|
valuta_per_euro: 1,
|
2022-08-26 03:33:13 +02:00
|
|
|
symbol: 1,
|
2022-09-12 18:37:08 +02:00
|
|
|
color: 1,
|
2022-09-18 20:17:24 +02:00
|
|
|
idCity: 1,
|
|
|
|
|
pub_to_share: 1,
|
2022-09-19 14:37:57 +02:00
|
|
|
visibility: 1,
|
2022-08-26 03:33:13 +02:00
|
|
|
abbrev: 1,
|
|
|
|
|
data_costituz: 1,
|
2022-09-11 11:45:33 +02:00
|
|
|
photos: 1,
|
2022-09-02 02:25:38 +02:00
|
|
|
admins: 1,
|
|
|
|
|
createdBy: 1,
|
|
|
|
|
date_created: 1,
|
|
|
|
|
date_updated: 1,
|
|
|
|
|
req_users: 1,
|
|
|
|
|
refused_users: 1,
|
2023-01-03 16:51:32 +01:00
|
|
|
req_groups: 1,
|
|
|
|
|
refused_groups: 1,
|
2022-09-24 20:21:37 +02:00
|
|
|
transactionsEnabled: 1,
|
2022-10-08 14:25:00 +02:00
|
|
|
status: 1,
|
2022-09-18 20:17:24 +02:00
|
|
|
'mycities': 1,
|
2022-08-26 03:33:13 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
CircuitSchema.statics.getCircuitsByUsername = async function (idapp, username, user) {
|
2022-08-26 03:33:13 +02:00
|
|
|
|
|
|
|
|
try {
|
2022-12-15 21:57:38 +01:00
|
|
|
const { User } = require('../models/user');
|
|
|
|
|
const { Account } = require('../models/account');
|
2022-08-26 03:33:13 +02:00
|
|
|
|
|
|
|
|
const whatToShow = this.getWhatToShow(idapp, username);
|
|
|
|
|
const whatToShow_Unknown = this.getWhatToShow_Unknown(idapp, username);
|
2022-09-02 02:25:38 +02:00
|
|
|
// const arrUsernameCircuits = await User.getUsernameCircuitsByUsername(idapp, username);
|
2022-08-26 03:33:13 +02:00
|
|
|
// const arrUsernameReqCircuits = await MyCircuit.getUsernameReqCircuitsByCircuitname(idapp, username);
|
|
|
|
|
|
2022-09-02 02:25:38 +02:00
|
|
|
const manage_mycircuits = await Circuit.find({
|
|
|
|
|
idapp,
|
|
|
|
|
'admins': {
|
2022-12-15 21:57:38 +01:00
|
|
|
$elemMatch: { username: { $eq: username } },
|
2022-09-02 02:25:38 +02:00
|
|
|
},
|
|
|
|
|
$or: [
|
2022-12-15 21:57:38 +01:00
|
|
|
{ deleted: { $exists: false } },
|
|
|
|
|
{ deleted: { $exists: true, $eq: false } }],
|
2023-03-05 22:04:14 +01:00
|
|
|
}).sort({status: -1, numMembers: -1, name: 1}).lean();
|
2022-09-02 02:25:38 +02:00
|
|
|
|
2022-08-26 03:33:13 +02:00
|
|
|
let listcircuits = await Circuit.find({
|
|
|
|
|
idapp,
|
|
|
|
|
$or: [
|
2022-12-15 21:57:38 +01:00
|
|
|
{ deleted: { $exists: false } },
|
|
|
|
|
{ deleted: { $exists: true, $eq: false } }],
|
2023-03-05 22:04:14 +01:00
|
|
|
}, whatToShow_Unknown).sort({status: -1, numMembers: -1, name: 1}).lean();
|
2022-08-26 03:33:13 +02:00
|
|
|
|
2022-09-02 02:25:38 +02:00
|
|
|
let asked_circuits = await Circuit.find({
|
2022-08-26 03:33:13 +02:00
|
|
|
idapp,
|
|
|
|
|
'req_users': {
|
2022-12-15 21:57:38 +01:00
|
|
|
$elemMatch: { username: { $eq: username } },
|
2022-08-26 03:33:13 +02:00
|
|
|
},
|
|
|
|
|
$or: [
|
2022-12-15 21:57:38 +01:00
|
|
|
{ deleted: { $exists: false } },
|
|
|
|
|
{ deleted: { $exists: true, $eq: false } }],
|
2023-03-05 22:04:14 +01:00
|
|
|
}, whatToShow_Unknown).sort({status: -1}).lean();
|
2022-08-26 03:33:13 +02:00
|
|
|
|
2022-09-02 02:25:38 +02:00
|
|
|
let refused_circuits = await Circuit.find({
|
2022-08-26 03:33:13 +02:00
|
|
|
idapp,
|
|
|
|
|
'refused_users': {
|
2022-12-15 21:57:38 +01:00
|
|
|
$elemMatch: { username: { $eq: username } },
|
2022-08-26 03:33:13 +02:00
|
|
|
},
|
|
|
|
|
$or: [
|
2022-12-15 21:57:38 +01:00
|
|
|
{ deleted: { $exists: false } },
|
|
|
|
|
{ deleted: { $exists: true, $eq: false } }],
|
2023-03-05 22:04:14 +01:00
|
|
|
}, whatToShow_Unknown).sort({status: -1}).lean();
|
2022-08-26 03:33:13 +02:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
listcircuits,
|
2022-09-02 02:25:38 +02:00
|
|
|
asked_circuits,
|
|
|
|
|
refused_circuits,
|
|
|
|
|
manage_mycircuits,
|
2022-09-14 11:32:04 +02:00
|
|
|
mycircuits: user.profile.mycircuits,
|
2022-08-26 03:33:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} catch (e) {
|
2022-09-02 02:25:38 +02:00
|
|
|
console.log('Error getCircuitsByUsername', e);
|
2022-08-26 03:33:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
listUsersCircuit: [],
|
|
|
|
|
listRequestUsersCircuit: [],
|
|
|
|
|
listTrusted: [],
|
2022-09-02 02:25:38 +02:00
|
|
|
asked_circuits: [],
|
|
|
|
|
refused_circuits: [],
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
CircuitSchema.statics.getInfoCircuitByName = async function (idapp, name) {
|
2022-09-02 02:25:38 +02:00
|
|
|
|
|
|
|
|
const whatToShow = this.getWhatToShow(idapp, '');
|
2022-08-26 03:33:13 +02:00
|
|
|
|
2022-09-02 02:25:38 +02:00
|
|
|
const myfind = {
|
|
|
|
|
idapp,
|
|
|
|
|
name,
|
2022-08-26 03:33:13 +02:00
|
|
|
};
|
2022-09-02 02:25:38 +02:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
return await Circuit.findOne(myfind, whatToShow).lean();
|
|
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
CircuitSchema.statics.getCircuitByName = async function (idapp, name) {
|
2022-09-03 13:06:58 +02:00
|
|
|
|
|
|
|
|
const myfind = {
|
|
|
|
|
idapp,
|
|
|
|
|
name,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try {
|
2022-09-14 17:37:29 +02:00
|
|
|
return await Circuit.findOne(myfind);
|
2022-09-03 13:06:58 +02:00
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
CircuitSchema.statics.getCircuitById = async function (circuitId) {
|
2022-09-11 11:45:33 +02:00
|
|
|
|
|
|
|
|
const myfind = {
|
2022-09-14 11:32:04 +02:00
|
|
|
_id: circuitId,
|
2022-09-11 11:45:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try {
|
2022-09-14 17:37:29 +02:00
|
|
|
return await Circuit.findOne(myfind);
|
2022-09-11 11:45:33 +02:00
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
CircuitSchema.statics.deleteCircuit = async function (idapp, usernameOrig, name) {
|
2022-09-02 02:25:38 +02:00
|
|
|
console.log('Circuito ' + name + ' rimosso da ' + usernameOrig);
|
2022-12-15 21:57:38 +01:00
|
|
|
return await Circuit.findOneAndRemove({ idapp, name });
|
2022-08-26 03:33:13 +02:00
|
|
|
};
|
|
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
CircuitSchema.statics.getUserCircuits = async function (idapp, username) {
|
2022-09-12 18:37:08 +02:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
let aggr1 = [
|
|
|
|
|
{
|
2022-10-22 15:38:15 +02:00
|
|
|
$match: {
|
|
|
|
|
idapp, username,
|
2022-09-18 20:17:24 +02:00
|
|
|
$or: [
|
2022-12-15 21:57:38 +01:00
|
|
|
{ deleted: { $exists: false } },
|
|
|
|
|
{ deleted: { $exists: true, $eq: false } }],
|
2022-09-18 20:17:24 +02:00
|
|
|
},
|
2022-09-12 18:37:08 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
$lookup: {
|
|
|
|
|
from: 'circuits',
|
|
|
|
|
localField: 'circuitId',
|
|
|
|
|
foreignField: '_id',
|
|
|
|
|
as: 'circuit',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
'$replaceRoot': {
|
|
|
|
|
'newRoot': {
|
|
|
|
|
'$mergeObjects': [
|
|
|
|
|
{
|
|
|
|
|
'$arrayElemAt': [
|
|
|
|
|
'$circuit',
|
|
|
|
|
0,
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
'$$ROOT',
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
/*
|
|
|
|
|
{
|
|
|
|
|
$project: {
|
|
|
|
|
"circuit.name": 1,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
ris = await this.aggregate(aggr1);
|
|
|
|
|
|
|
|
|
|
return ris;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('e', e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
CircuitSchema.statics.getUsersSingleCircuit = async function (idapp, username, circuitname, circuitId) {
|
2022-11-06 13:39:01 +01:00
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
const { User } = require('../models/user');
|
2022-11-06 13:39:01 +01:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
let aggr1 = [
|
|
|
|
|
{
|
|
|
|
|
$match: {
|
|
|
|
|
idapp: idapp,
|
|
|
|
|
'profile.mycircuits': {
|
2022-12-15 21:57:38 +01:00
|
|
|
$elemMatch: { circuitname: { $eq: circuitname } },
|
2022-11-06 13:39:01 +01:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/*{
|
|
|
|
|
$lookup: {
|
|
|
|
|
from: 'circuits',
|
|
|
|
|
as: 'circuit',
|
|
|
|
|
let: {circuitname: circuitname, idapp: '$idapp'},
|
|
|
|
|
pipeline: [
|
|
|
|
|
{
|
|
|
|
|
$match:
|
|
|
|
|
{
|
|
|
|
|
$expr:
|
|
|
|
|
{
|
|
|
|
|
$and:
|
|
|
|
|
[
|
|
|
|
|
{$eq: ['$name', '$$circuitname']},
|
|
|
|
|
{$eq: ['$idapp', '$$idapp']},
|
|
|
|
|
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
{$unwind: '$circuit'},
|
|
|
|
|
*/
|
|
|
|
|
{
|
2022-12-15 21:57:38 +01:00
|
|
|
$project: {
|
|
|
|
|
username: 1,
|
|
|
|
|
name: 1,
|
|
|
|
|
surname: 1,
|
2023-02-23 17:20:46 +01:00
|
|
|
profile: 1,
|
|
|
|
|
idapp: 1 /*, 'circuit.name': 1, 'circuit._id': 1*/
|
2022-12-15 21:57:38 +01:00
|
|
|
},
|
2022-11-06 13:39:01 +01:00
|
|
|
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
$lookup: {
|
|
|
|
|
from: 'accounts',
|
|
|
|
|
as: 'account',
|
2022-12-15 21:57:38 +01:00
|
|
|
let: { username: '$username', idapp: '$idapp', circuitId: circuitId /*, circuitId: '$circuit._id' */ },
|
2022-11-06 13:39:01 +01:00
|
|
|
pipeline: [
|
|
|
|
|
{
|
|
|
|
|
$match:
|
2022-12-15 21:57:38 +01:00
|
|
|
{
|
|
|
|
|
$expr:
|
|
|
|
|
{
|
|
|
|
|
$and:
|
|
|
|
|
[
|
|
|
|
|
{ $eq: ['$$username', '$username'] },
|
|
|
|
|
{ $eq: ['$$idapp', '$idapp'] },
|
|
|
|
|
{ $eq: ['$$circuitId', '$circuitId'] },
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-11-06 13:39:01 +01:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-12-15 21:57:38 +01:00
|
|
|
{ $unwind: '$account' },
|
2022-11-06 13:39:01 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
ris = await User.aggregate(aggr1);
|
|
|
|
|
|
|
|
|
|
return ris;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('e', e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
CircuitSchema.statics.getCircolanteSingolaTransaz = function (accountorigTable, accountdestTable) {
|
2022-09-14 17:37:29 +02:00
|
|
|
|
|
|
|
|
let circolante = 0;
|
|
|
|
|
if (accountdestTable.saldo > 0)
|
|
|
|
|
circolante += accountdestTable.saldo;
|
|
|
|
|
if (accountorigTable.saldo > 0)
|
|
|
|
|
circolante += accountorigTable.saldo;
|
|
|
|
|
|
|
|
|
|
return circolante;
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
CircuitSchema.statics.sendCoins = async function (onlycheck, idapp, usernameOrig, extrarec) {
|
2022-09-03 13:06:58 +02:00
|
|
|
|
2022-09-12 18:37:08 +02:00
|
|
|
let ris = {
|
2022-09-14 17:37:29 +02:00
|
|
|
result: false,
|
2022-09-12 18:37:08 +02:00
|
|
|
cansend: true,
|
|
|
|
|
errormsg: '',
|
2022-09-13 12:28:49 +02:00
|
|
|
rec: null,
|
|
|
|
|
useraccounts: [],
|
2022-09-12 18:37:08 +02:00
|
|
|
};
|
|
|
|
|
|
2022-09-03 13:06:58 +02:00
|
|
|
try {
|
2022-09-14 17:37:29 +02:00
|
|
|
let circuittable = null;
|
2022-09-12 18:37:08 +02:00
|
|
|
if (extrarec.circuitname)
|
2022-09-14 17:37:29 +02:00
|
|
|
circuittable = await Circuit.getCircuitByName(idapp, extrarec.circuitname);
|
2022-09-12 18:37:08 +02:00
|
|
|
if (extrarec.circuitId)
|
2022-09-14 17:37:29 +02:00
|
|
|
circuittable = await Circuit.getCircuitById(idapp, extrarec.circuitId);
|
|
|
|
|
|
|
|
|
|
if (circuittable) {
|
|
|
|
|
const myqty = Math.abs(extrarec.qty);
|
2022-09-03 13:06:58 +02:00
|
|
|
|
2023-02-01 16:36:10 +01:00
|
|
|
const accountdestTable = await Account.getAccountByUsernameAndCircuitId(idapp, extrarec.dest, circuittable._id, true, extrarec.groupdest, extrarec.contoComDest);
|
|
|
|
|
const accountorigTable = await Account.getAccountByUsernameAndCircuitId(idapp, usernameOrig, circuittable._id, true, extrarec.grouporig, extrarec.contoComOrig);
|
2022-09-03 13:06:58 +02:00
|
|
|
|
2022-09-14 17:37:29 +02:00
|
|
|
const circolantePrec = this.getCircolanteSingolaTransaz(accountorigTable, accountdestTable);
|
2022-09-12 18:37:08 +02:00
|
|
|
|
|
|
|
|
// Check if Sender has enough money
|
2022-09-14 17:37:29 +02:00
|
|
|
if (accountorigTable.saldo - myqty < -accountorigTable.fidoConcesso) {
|
2022-09-12 18:37:08 +02:00
|
|
|
ris.cansend = false;
|
2022-09-16 17:38:49 +02:00
|
|
|
ris.errormsg = i18n.__('CIRCUIT_AMOUNT_EXCEED_FIDO', usernameOrig);
|
2022-09-12 18:37:08 +02:00
|
|
|
}
|
2022-09-18 01:21:04 +02:00
|
|
|
|
2022-09-14 17:37:29 +02:00
|
|
|
if (accountdestTable.saldo + myqty > accountorigTable.qta_maxConcessa) {
|
2022-09-12 18:37:08 +02:00
|
|
|
ris.cansend = false;
|
2022-09-16 17:38:49 +02:00
|
|
|
ris.errormsg = i18n.__('CIRCUIT_AMOUNT_EXCEED_QTAMAX', extrarec.dest);
|
2022-09-12 18:37:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!onlycheck) {
|
|
|
|
|
// Add a Transaction !
|
2022-09-16 17:38:49 +02:00
|
|
|
if (ris.cansend) {
|
2022-10-13 21:10:07 +02:00
|
|
|
ris.rec = await Movement.addMov(idapp, accountorigTable, accountdestTable, myqty, extrarec.causal, extrarec.notifId);
|
2022-09-16 17:38:49 +02:00
|
|
|
}
|
2022-09-13 12:28:49 +02:00
|
|
|
|
2022-09-14 17:37:29 +02:00
|
|
|
if (ris.cansend && ris.rec) {
|
|
|
|
|
|
|
|
|
|
const circolanteAtt = this.getCircolanteSingolaTransaz(accountorigTable, accountdestTable);
|
|
|
|
|
|
|
|
|
|
// Somma di tutte le transazioni
|
|
|
|
|
circuittable.totTransato += myqty;
|
2022-09-19 15:10:23 +02:00
|
|
|
// circuittable.totCircolante = circuittable.totCircolante + (circolanteAtt - circolantePrec);
|
|
|
|
|
circuittable.totCircolante = await Account.calcTotCircolante(idapp, circuittable._id);
|
2022-10-13 21:10:07 +02:00
|
|
|
// await circuittable.save();
|
|
|
|
|
paramstoupdate = {
|
|
|
|
|
totTransato: circuittable.totTransato,
|
|
|
|
|
totCircolante: circuittable.totCircolante,
|
|
|
|
|
};
|
2022-12-15 21:57:38 +01:00
|
|
|
await Circuit.updateOne({ _id: circuittable }, { $set: paramstoupdate });
|
2022-09-14 17:37:29 +02:00
|
|
|
|
2023-02-06 22:58:10 +01:00
|
|
|
extrarec.saldoOrig = accountorigTable.saldo;
|
|
|
|
|
extrarec.saldoDest = accountdestTable.saldo;
|
|
|
|
|
|
2023-02-06 23:26:30 +01:00
|
|
|
let orig = usernameOrig + (extrarec.grouporig ? extrarec.grouporig : '') + (extrarec.contoComOrig ? extrarec.contoComOrig : '');
|
|
|
|
|
let dest = (extrarec.dest ? extrarec.dest : '') + (extrarec.groupDest ? extrarec.groupDest : '') + (extrarec.contoComDest ? extrarec.contoComDest : '');
|
2023-02-06 22:58:10 +01:00
|
|
|
|
2022-09-14 17:37:29 +02:00
|
|
|
ris.result = true;
|
2023-02-06 23:26:30 +01:00
|
|
|
let msg = 'Inviate Monete da ' + orig + ' a ' + dest + ' ' + myqty + ' ' + circuittable.symbol + ' [causale: ' + extrarec.causal + `] [Saldo ${orig}: ` + extrarec.saldoOrig + ' ' + circuittable.symbol + '] ' + ` [Saldo ${dest}: ` + extrarec.saldoDest + ' ' + circuittable.symbol + ']';
|
2023-02-06 22:58:10 +01:00
|
|
|
console.log(msg);
|
2022-09-14 17:37:29 +02:00
|
|
|
|
|
|
|
|
ris.useraccounts = await Account.getUserAccounts(idapp, usernameOrig);
|
2022-09-12 18:37:08 +02:00
|
|
|
|
2023-02-06 22:58:10 +01:00
|
|
|
tools.writeTransactionLog(msg);
|
|
|
|
|
|
|
|
|
|
tools.sendMsgTelegramToAdmin(idapp, msg);
|
2022-09-18 20:17:24 +02:00
|
|
|
|
2022-09-12 18:37:08 +02:00
|
|
|
} else {
|
2023-02-06 22:58:10 +01:00
|
|
|
// console.log('NON Inviate Monete da', usernameOrig, extrarec.grouporig, extrarec.dest, extrarec.groupdest, myqty, extrarec.causal);
|
2022-09-12 18:37:08 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ris;
|
2022-09-03 13:06:58 +02:00
|
|
|
|
2022-09-11 11:45:33 +02:00
|
|
|
}
|
|
|
|
|
} catch (e) {
|
2022-09-03 13:06:58 +02:00
|
|
|
console.error('Err sendCoins', e);
|
2022-09-14 17:37:29 +02:00
|
|
|
ris.result = false;
|
|
|
|
|
return ris;
|
2022-09-03 13:06:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2022-09-02 02:25:38 +02:00
|
|
|
// Rimuovo la Richiesta del Circuito
|
2022-12-15 21:57:38 +01:00
|
|
|
CircuitSchema.statics.removeReqCircuit = async function (idapp, username, name) {
|
2022-09-02 02:25:38 +02:00
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
return await Circuit.updateOne({ idapp, name },
|
|
|
|
|
{ $pull: { req_users: { username: { $in: [username] } } } });
|
2022-09-02 02:25:38 +02:00
|
|
|
};
|
|
|
|
|
|
2023-01-03 16:51:32 +01:00
|
|
|
// Rimuovo la Richiesta del Gruppo sul Circuito
|
|
|
|
|
CircuitSchema.statics.removeReqGroupCircuit = async function (idapp, groupname, name) {
|
|
|
|
|
|
|
|
|
|
return await Circuit.updateOne({ idapp, name },
|
|
|
|
|
{ $pull: { req_groups: { groupname: { $in: [groupname] } } } });
|
|
|
|
|
};
|
|
|
|
|
|
2022-09-02 02:25:38 +02:00
|
|
|
// Aggiungi agli utenti Rifiutati del Circuito
|
2022-10-22 15:38:15 +02:00
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
CircuitSchema.statics.refuseReqCircuit = async function (idapp, username, name) {
|
2022-09-02 02:25:38 +02:00
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
return await Circuit.updateOne({ idapp, name },
|
|
|
|
|
{
|
|
|
|
|
$push:
|
2022-09-02 02:25:38 +02:00
|
|
|
{
|
2022-12-15 21:57:38 +01:00
|
|
|
refused_users: {
|
|
|
|
|
username,
|
|
|
|
|
date: new Date(),
|
2023-01-03 16:51:32 +01:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CircuitSchema.statics.refuseReqGroupCircuit = async function (idapp, groupname, name) {
|
|
|
|
|
|
|
|
|
|
return await Circuit.updateOne({ idapp, name },
|
|
|
|
|
{
|
|
|
|
|
$push:
|
|
|
|
|
{
|
|
|
|
|
refused_groups: {
|
|
|
|
|
groupname,
|
|
|
|
|
date: new Date(),
|
2022-12-15 21:57:38 +01:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
2022-09-02 02:25:38 +02:00
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
CircuitSchema.statics.updateData = async function (idapp, circuitname) {
|
2022-10-22 15:38:15 +02:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
const { User } = require('./user');
|
2022-10-22 15:38:15 +02:00
|
|
|
|
|
|
|
|
let aggr1 = [
|
|
|
|
|
{
|
|
|
|
|
$match: {
|
|
|
|
|
idapp,
|
|
|
|
|
'profile.mycircuits': {
|
2022-12-15 21:57:38 +01:00
|
|
|
$elemMatch: { circuitname: { $eq: circuitname } },
|
2022-10-22 15:38:15 +02:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-12-15 21:57:38 +01:00
|
|
|
{ $group: { _id: null, count: { $sum: 1 } } },
|
2022-10-22 15:38:15 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const ris = await User.aggregate(aggr1);
|
|
|
|
|
|
|
|
|
|
let numMembers = ris ? ris[0].count : 0;
|
|
|
|
|
|
|
|
|
|
let paramstoupdate = {
|
|
|
|
|
numMembers: numMembers,
|
|
|
|
|
};
|
2022-12-15 21:57:38 +01:00
|
|
|
const risult = await this.updateOne({ idapp, name: circuitname }, { $set: paramstoupdate });
|
2022-10-22 15:38:15 +02:00
|
|
|
|
2022-11-06 13:39:01 +01:00
|
|
|
console.log('risult', risult);
|
2022-10-22 15:38:15 +02:00
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('Err', e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
CircuitSchema.statics.setDeperimentoOff = async function () {
|
2022-11-10 19:33:23 +01:00
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
return await Circuit.updateMany({}, { $set: { 'deperimento': false } },
|
|
|
|
|
{ new: false });
|
2022-11-10 19:33:23 +01:00
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2023-02-06 22:58:10 +01:00
|
|
|
CircuitSchema.statics.getNameByCircuitId = async function (circuitId) {
|
|
|
|
|
|
|
|
|
|
let circuit = await Circuit.findOne({ _id: circuitId });
|
|
|
|
|
if (circuit)
|
|
|
|
|
return circuit.name;
|
|
|
|
|
|
|
|
|
|
return '';
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CircuitSchema.statics.getCircuitByCircuitId = async function (circuitId) {
|
|
|
|
|
|
|
|
|
|
return await Circuit.findOne({ _id: circuitId });
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2023-02-01 16:36:10 +01:00
|
|
|
CircuitSchema.statics.getListAdminsByCircuitPath = async function (idapp, circuitPath) {
|
2023-02-06 22:58:10 +01:00
|
|
|
|
2023-02-01 16:36:10 +01:00
|
|
|
let arr = await Circuit.findOne({
|
|
|
|
|
idapp,
|
|
|
|
|
path: circuitPath,
|
|
|
|
|
$or: [
|
|
|
|
|
{ deleted: { $exists: false } },
|
|
|
|
|
{ deleted: { $exists: true, $eq: false } }],
|
2023-02-06 22:58:10 +01:00
|
|
|
}, { admins: 1 }).lean();
|
2023-02-01 16:36:10 +01:00
|
|
|
|
|
|
|
|
return arr && arr.admins ? arr.admins : [];
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2023-02-06 22:58:10 +01:00
|
|
|
// Imposta a tutti i Conti Collettivi, i seguenti minimi e massimi
|
|
|
|
|
CircuitSchema.statics.SetDefMinMaxCollettivi = async function (idapp, valmin, valmax) {
|
|
|
|
|
|
|
|
|
|
ris = await Circuit.updateMany({ idapp, contocom: { "$nin": [null, ""] } },
|
|
|
|
|
{
|
|
|
|
|
$set:
|
|
|
|
|
{
|
|
|
|
|
fido_scoperto_default: valmin,
|
|
|
|
|
qta_max_default: valmax,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Imposta a tutti i Conti Personali, i seguenti minimi e massimi
|
|
|
|
|
CircuitSchema.statics.SetDefMinMaxPersonali = async function (idapp, valmin, valmax) {
|
|
|
|
|
|
|
|
|
|
ris = await Circuit.updateMany({ idapp },
|
|
|
|
|
{
|
|
|
|
|
$set:
|
|
|
|
|
{
|
|
|
|
|
fido_scoperto_default: valmin,
|
|
|
|
|
qta_max_default: valmax,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Imposta a tutti i Conti Collettivi, i seguenti minimi e massimi
|
|
|
|
|
CircuitSchema.statics.SetDefMinMaxCollettivi = async function (idapp, valmin, valmax) {
|
|
|
|
|
|
|
|
|
|
ris = await Circuit.updateMany({ idapp },
|
|
|
|
|
{
|
|
|
|
|
$set:
|
|
|
|
|
{
|
|
|
|
|
fido_scoperto_default_grp: valmin,
|
|
|
|
|
qta_max_default_grp: valmax,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2022-04-07 08:19:40 +02:00
|
|
|
const Circuit = mongoose.model('Circuit', CircuitSchema);
|
|
|
|
|
|
2022-12-15 21:57:38 +01:00
|
|
|
module.exports = { Circuit };
|