2022-04-07 08:19:40 +02:00
|
|
|
const mongoose = require('mongoose').set('debug', false);
|
|
|
|
|
const Schema = mongoose.Schema;
|
|
|
|
|
|
|
|
|
|
mongoose.Promise = global.Promise;
|
|
|
|
|
mongoose.level = 'F';
|
|
|
|
|
|
|
|
|
|
const tools = require('../tools/general');
|
|
|
|
|
|
|
|
|
|
const {ObjectID} = require('mongodb');
|
|
|
|
|
|
|
|
|
|
// Resolving error Unknown modifier: $pushAll
|
|
|
|
|
mongoose.plugin(schema => {
|
|
|
|
|
schema.options.usePushEach = true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const CircuitSchema = new Schema({
|
2022-06-16 20:34:42 +02:00
|
|
|
Num: {
|
2022-04-07 08:19:40 +02:00
|
|
|
type: Number,
|
2022-04-24 17:02:10 +02:00
|
|
|
unique: true,
|
2022-04-07 08:19:40 +02:00
|
|
|
},
|
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-04-24 17:02:10 +02:00
|
|
|
subname: {
|
2022-04-07 08:19:40 +02:00
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
descr: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
systemUserDescr: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
systemUserId: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
founderUserId: {
|
|
|
|
|
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,
|
|
|
|
|
maxlength: 3,
|
|
|
|
|
},
|
2022-04-24 17:02:10 +02:00
|
|
|
abbrev: {
|
2022-04-07 08:19:40 +02:00
|
|
|
type: String,
|
|
|
|
|
maxlength: 3,
|
|
|
|
|
},
|
|
|
|
|
compara_valuta: {
|
|
|
|
|
type: Number,
|
|
|
|
|
default: 1,
|
|
|
|
|
},
|
|
|
|
|
compara_euro: {
|
|
|
|
|
type: Number,
|
|
|
|
|
default: 1,
|
|
|
|
|
},
|
|
|
|
|
valuta_per_euro: {
|
|
|
|
|
type: Number,
|
|
|
|
|
default: 1,
|
|
|
|
|
},
|
|
|
|
|
fido_scoperto_default: {
|
|
|
|
|
type: Number,
|
|
|
|
|
},
|
|
|
|
|
data_costituz: {
|
|
|
|
|
type: Date,
|
|
|
|
|
},
|
|
|
|
|
deperimento: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: true,
|
|
|
|
|
},
|
|
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
// -------------
|
|
|
|
|
img_logo: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
CircuitSchema.statics.findAllIdApp = async function(idapp) {
|
|
|
|
|
const MyCircuit = this;
|
|
|
|
|
|
|
|
|
|
const myfind = {idapp};
|
|
|
|
|
|
|
|
|
|
return await MyCircuit.find(myfind, (err, arrrec) => {
|
|
|
|
|
return arrrec;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CircuitSchema.pre('save', async function(next) {
|
|
|
|
|
if (this.isNew) {
|
2022-06-16 20:34:42 +02:00
|
|
|
const myrec = await Circuit.findOne().limit(1).sort({Num: -1});
|
2022-04-07 08:19:40 +02:00
|
|
|
if (!!myrec) {
|
2022-06-16 20:34:42 +02:00
|
|
|
if (myrec._doc.Num === 0)
|
|
|
|
|
this.Num = 1;
|
2022-04-07 08:19:40 +02:00
|
|
|
else
|
2022-06-16 20:34:42 +02:00
|
|
|
this.Num = myrec._doc.Num + 1;
|
2022-04-07 08:19:40 +02:00
|
|
|
|
|
|
|
|
} else {
|
2022-06-16 20:34:42 +02:00
|
|
|
this.Num = 1;
|
2022-04-07 08:19:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
CircuitSchema.statics.getFieldsForSearch = function() {
|
|
|
|
|
return [
|
|
|
|
|
{field: 'nome_circuito', type: tools.FieldType.string},
|
|
|
|
|
{field: 'sotto_nome', type: tools.FieldType.string},
|
|
|
|
|
{field: 'nome_valuta', type: tools.FieldType.string},
|
|
|
|
|
{field: 'descr', type: tools.FieldType.string}];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CircuitSchema.statics.executeQueryTable = function(idapp, params) {
|
|
|
|
|
params.fieldsearch = this.getFieldsForSearch();
|
|
|
|
|
return tools.executeQueryTable(this, 0, params);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const Circuit = mongoose.model('Circuit', CircuitSchema);
|
|
|
|
|
|
|
|
|
|
module.exports = {Circuit};
|