Circuit table...
This commit is contained in:
@@ -7,6 +7,7 @@ mongoose.level = 'F';
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
const {User} = require('./user');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
@@ -14,6 +15,9 @@ mongoose.plugin(schema => {
|
||||
});
|
||||
|
||||
const CircuitSchema = new Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
},
|
||||
Num: {
|
||||
type: Number,
|
||||
unique: true,
|
||||
@@ -105,17 +109,47 @@ const CircuitSchema = new Schema({
|
||||
type: Number,
|
||||
},
|
||||
// -------------
|
||||
createdBy: {
|
||||
type: String,
|
||||
},
|
||||
date_created: {
|
||||
type: Date,
|
||||
},
|
||||
date_updated: {
|
||||
type: Date,
|
||||
},
|
||||
admins: [
|
||||
{
|
||||
username: {type: String},
|
||||
date: {type: Date},
|
||||
},
|
||||
],
|
||||
img_logo: {
|
||||
type: String,
|
||||
},
|
||||
req_users: [
|
||||
{
|
||||
_id: false,
|
||||
username: {type: String},
|
||||
date: {type: Date},
|
||||
}], // username
|
||||
refused_users: [
|
||||
{
|
||||
_id: false,
|
||||
username: {type: String},
|
||||
date: {type: Date},
|
||||
}], // username
|
||||
deleted: {
|
||||
type: Boolean,
|
||||
},
|
||||
});
|
||||
|
||||
CircuitSchema.statics.findAllIdApp = async function(idapp) {
|
||||
const MyCircuit = this;
|
||||
const Circuit = this;
|
||||
|
||||
const myfind = {idapp};
|
||||
|
||||
return await MyCircuit.find(myfind, (err, arrrec) => {
|
||||
return await Circuit.find(myfind, (err, arrrec) => {
|
||||
return arrrec;
|
||||
});
|
||||
};
|
||||
@@ -150,6 +184,106 @@ CircuitSchema.statics.executeQueryTable = function(idapp, params) {
|
||||
return tools.executeQueryTable(this, 0, params);
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getWhatToShow = function(idapp, username) {
|
||||
// FOR ME, PERMIT ALL
|
||||
return {
|
||||
Num: 1,
|
||||
groupnameId: 1,
|
||||
name: 1,
|
||||
subname: 1,
|
||||
longdescr: 1,
|
||||
regulation: 1,
|
||||
systemUserId: 1,
|
||||
founderUserId: 1,
|
||||
nome_valuta: 1,
|
||||
symbol: 1,
|
||||
abbrev: 1,
|
||||
data_costituz: 1,
|
||||
img_logo: 1,
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getWhatToShow_Unknown = function(idapp, username) {
|
||||
return {
|
||||
Num: 1,
|
||||
groupnameId: 1,
|
||||
name: 1,
|
||||
subname: 1,
|
||||
longdescr: 1,
|
||||
regulation: 1,
|
||||
systemUserId: 1,
|
||||
founderUserId: 1,
|
||||
nome_valuta: 1,
|
||||
symbol: 1,
|
||||
abbrev: 1,
|
||||
data_costituz: 1,
|
||||
img_logo: 1,
|
||||
};
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getCircuitsByUsername = async function(idapp, username, req) {
|
||||
|
||||
try {
|
||||
const {User} = require('../models/user');
|
||||
const {Account} = require('../models/account');
|
||||
|
||||
const whatToShow = this.getWhatToShow(idapp, username);
|
||||
const whatToShow_Unknown = this.getWhatToShow_Unknown(idapp, username);
|
||||
// const arrUsernameCircuits = await User.getUsernameCircuitsByUsername(idapp,
|
||||
// username);
|
||||
// const arrUsernameReqCircuits = await MyCircuit.getUsernameReqCircuitsByCircuitname(idapp, username);
|
||||
|
||||
let listUserAccounts = await Account.getAccountsByUsername(idapp, username);
|
||||
|
||||
let listcircuits = await Circuit.find({
|
||||
idapp,
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
{deleted: {$exists: true, $eq: false}}],
|
||||
}, whatToShow_Unknown);
|
||||
|
||||
let listSentRequestCircuits = await Circuit.find({
|
||||
idapp,
|
||||
'req_users': {
|
||||
$elemMatch: {username: {$eq: username}},
|
||||
},
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
{deleted: {$exists: true, $eq: false}}],
|
||||
}, whatToShow_Unknown);
|
||||
|
||||
let listRefusedCircuits = await Circuit.find({
|
||||
idapp,
|
||||
'refused_users': {
|
||||
$elemMatch: {username: {$eq: username}},
|
||||
},
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
{deleted: {$exists: true, $eq: false}}],
|
||||
}, whatToShow_Unknown);
|
||||
|
||||
return {
|
||||
listUserAccounts,
|
||||
listcircuits,
|
||||
listSentRequestCircuits,
|
||||
listRefusedCircuits,
|
||||
};
|
||||
|
||||
} catch (e) {
|
||||
console.log('Error', e);
|
||||
}
|
||||
|
||||
return {
|
||||
listUsersCircuit: [],
|
||||
listRequestUsersCircuit: [],
|
||||
listTrusted: [],
|
||||
listSentRequestCircuits: [],
|
||||
listRefusedCircuits: [],
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
const Circuit = mongoose.model('Circuit', CircuitSchema);
|
||||
|
||||
module.exports = {Circuit};
|
||||
|
||||
Reference in New Issue
Block a user