Circuits...

Circuits Fido e Max Qta
Fixed error eslint: 7.0.0 is OK
This commit is contained in:
Paolo Arena
2022-09-11 11:45:33 +02:00
parent d262f94315
commit d62888083b
100 changed files with 3699 additions and 2774 deletions

View File

@@ -1,7 +1,7 @@
/*
Account is a User's single Circuit
*/
const mongoose = require('mongoose').set('debug', false);
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -35,6 +35,12 @@ const AccountSchema = new Schema({
deperibile: {
type: Boolean,
},
fidoConcesso: {
type: Number,
},
qta_maxConcessa: {
type: Number,
},
importo_iniziale: {
type: Number,
},
@@ -138,11 +144,14 @@ AccountSchema.statics.getUserAccounts = async function(idapp, username) {
},
},
},
/*
{
$project: {
"circuit.name": 1,
},
},
*/
];
ris = await this.aggregate(aggr1);
@@ -164,7 +173,7 @@ AccountSchema.statics.addtoSaldo = async function(id, amount) {
if (myaccount) {
myaccount.saldo = myaccount.saldo + amount;
myaccount.date_updated = new Date();
return myaccount.save();
return await myaccount.save();
}
@@ -174,6 +183,8 @@ AccountSchema.statics.addtoSaldo = async function(id, amount) {
AccountSchema.statics.getAccountByUsernameAndCircuitId = async function(idapp, username, circuitId, createifnotexist) {
const Account = this;
const {Circuit} = require('../models/circuit');
if (username === undefined)
return false;
@@ -183,6 +194,8 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function(idapp, u
circuitId,
};
const mycircuit = await Circuit.getCircuitById(circuitId);
let myaccount = await Account.findOne(myquery).lean();
if (!myaccount && createifnotexist) {
@@ -191,11 +204,13 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function(idapp, u
username,
circuitId,
deperibile: false,
fidoConcesso: mycircuit.fido_scoperto_default,
qta_maxConcessa: mycircuit.qta_max_default,
importo_iniziale: 0,
saldo: 0,
});
return myaccount.save();
return await myaccount.save();
}
return myaccount;

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false);
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -46,7 +46,7 @@ AdTypeSchema.statics.findAllIdApp = async function(idapp) {
{$sort: {_id: 1}},
];
return AdType.aggregate(query).then((arrrec) => {
return await AdType.aggregate(query).then((arrrec) => {
return arrrec;
});

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false);
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -46,7 +46,7 @@ AdTypeGoodSchema.statics.findAllIdApp = async function(idapp) {
{$sort: {_id: 1}},
];
return AdTypeGood.aggregate(query).then((arrrec) => {
return await AdTypeGood.aggregate(query).then((arrrec) => {
return arrrec;
});

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false);
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const Schema = mongoose.Schema;
const tools = require('../tools/general');
@@ -61,8 +61,8 @@ BotSchema.statics.executeQueryTable = function(idapp, params) {
BotSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
return tools.DuplicateAllRecords(this, idapporig, idappdest);
schermi
return await tools.DuplicateAllRecords(this, idapporig, idappdest);
};
@@ -71,7 +71,7 @@ BotSchema.statics.findAllIdApp = async function(idapp) {
const myfind = {idapp};
return Bot.find(myfind).sort({page: 1, lang: 1, riga: 1, index: 1}).lean();
return await Bot.find(myfind).sort({page: 1, lang: 1, riga: 1, index: 1}).lean();
};
const MyBot = mongoose.model('Bot', BotSchema);

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false);
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const Schema = mongoose.Schema;
const shared_consts = require('../tools/shared_nodejs');
@@ -98,7 +98,7 @@ module.exports.updateCartByCartId = async function(cartId, newCart) {
const modify_at = new Date();
return Cart.findOneAndUpdate({_id: cartId}, {
return await Cart.findOneAndUpdate({_id: cartId}, {
$set: {
items,
totalPrice,

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -60,7 +60,7 @@ CatGrpSchema.statics.findAllIdApp = async function (idapp) {
{ $sort: { descr: 1 } }
];
return CatGrp
return await CatGrp
.aggregate(query)
.then((arrrec) => {
return arrrec

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -31,7 +31,7 @@ const CfgServerSchema = new Schema({
CfgServerSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
return tools.DuplicateAllRecords(this, idapporig, idappdest);
return await tools.DuplicateAllRecords(this, idapporig, idappdest);
};

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false);
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -15,11 +15,7 @@ mongoose.plugin(schema => {
const CircuitSchema = new Schema({
_id: {
type: String,
},
Num: {
type: Number,
unique: true,
},
idapp: {
type: String,
@@ -84,6 +80,9 @@ const CircuitSchema = new Schema({
fido_scoperto_default: {
type: Number,
},
qta_max_default: {
type: Number,
},
data_costituz: {
type: Date,
},
@@ -128,9 +127,18 @@ const CircuitSchema = new Schema({
date: {type: Date},
},
],
img_logo: {
type: String,
},
photos: [
{
imagefile: {
type: String,
},
alt: {
type: String,
},
description: {
type: String,
},
}],
req_users: [
{
_id: false,
@@ -147,19 +155,19 @@ const CircuitSchema = new Schema({
type: Boolean,
default: false,
},
}, );
});
CircuitSchema.pre('save', async function(next) {
if (this.isNew) {
const myrec = await Circuit.findOne().limit(1).sort({_id: -1});
if (!!myrec) {
if (myrec._doc.Num === 0)
this.Num = 1;
if (myrec._doc._id === 0)
this._id = 1;
else
this.Num = myrec._doc.Num + 1;
this._id = myrec._doc._id + 1;
} else {
this.Num = 1;
this._id = 1;
}
this.date_created = new Date();
@@ -168,7 +176,6 @@ CircuitSchema.pre('save', async function(next) {
next();
});
CircuitSchema.statics.findAllIdApp = async function(idapp) {
const Circuit = this;
@@ -181,23 +188,6 @@ CircuitSchema.statics.findAllIdApp = async function(idapp) {
});
};
CircuitSchema.pre('save', async function(next) {
if (this.isNew) {
const myrec = await Circuit.findOne().limit(1).sort({Num: -1});
if (!!myrec) {
if (myrec._doc.Num === 0)
this.Num = 1;
else
this.Num = myrec._doc.Num + 1;
} else {
this.Num = 1;
}
}
next();
});
CircuitSchema.statics.getFieldsForSearch = function() {
return [
{field: 'nome_circuito', type: tools.FieldType.string},
@@ -230,7 +220,7 @@ CircuitSchema.statics.getWhatToShow = function(idapp, username) {
symbol: 1,
abbrev: 1,
data_costituz: 1,
img_logo: 1,
photos: 1,
admins: 1,
req_users: 1,
refused_users: 1,
@@ -241,11 +231,10 @@ CircuitSchema.statics.getWhatToShow = function(idapp, username) {
// Rimuovi dagli Admin del Circuito
CircuitSchema.statics.removeAdminOfMyCircuit = async function(idapp, username, name) {
return Circuit.updateOne({idapp, name},
return await Circuit.updateOne({idapp, name},
{$pull: {admins: {username: {$in: [username]}}}});
};
CircuitSchema.statics.getWhatToShow_Unknown = function(idapp, username) {
return {
Num: 1,
@@ -262,7 +251,7 @@ CircuitSchema.statics.getWhatToShow_Unknown = function(idapp, username) {
symbol: 1,
abbrev: 1,
data_costituz: 1,
img_logo: 1,
photos: 1,
admins: 1,
createdBy: 1,
date_created: 1,
@@ -379,9 +368,24 @@ CircuitSchema.statics.getCircuitByName = async function(idapp, name) {
};
CircuitSchema.statics.getCircuitById = async function(circuitId) {
const myfind = {
circuitId
};
try {
return await Circuit.findOne(myfind).lean();
} catch (e) {
return null;
}
};
CircuitSchema.statics.deleteCircuit = async function(idapp, usernameOrig, name) {
console.log('Circuito ' + name + ' rimosso da ' + usernameOrig);
return Circuit.findOneAndRemove({idapp, name});
return await Circuit.findOneAndRemove({idapp, name});
};
CircuitSchema.statics.sendCoins = async function(idapp, usernameOrig, extrarec) {
@@ -391,18 +395,21 @@ CircuitSchema.statics.sendCoins = async function(idapp, usernameOrig, extrarec)
const {Account} = require('../models/account');
try {
const reccircuit = Circuit.getCircuitByName(extrarec.circuitname);
const reccircuit = await Circuit.getCircuitByName(idapp, extrarec.circuitname);
const myqty = extrarec.qty;
if (reccircuit) {
const myqty = extrarec.qty;
const accountdest = await Account.getAccountByUsernameAndCircuitId(idapp, extrarec.dest, reccircuit._id, true);
const accountorig = await Account.getAccountByUsernameAndCircuitId(idapp, usernameOrig, reccircuit._id, true);
const accountdest = await Account.getAccountByUsernameAndCircuitId(idapp, extrarec.dest, reccircuit._id, true);
const accountorig = await Account.getAccountByUsernameAndCircuitId(idapp, usernameOrig, reccircuit._id, true);
// Add a Transaction !
Movement.addMov(accountorig, accountdest, myqty, extrarec.causal);
// Add a Transaction !
return await Movement.addMov(idapp, accountorig, accountdest, myqty, extrarec.causal);
}catch (e) {
}
} catch (e) {
console.error('Err sendCoins', e);
return false;
}
};
@@ -410,14 +417,14 @@ CircuitSchema.statics.sendCoins = async function(idapp, usernameOrig, extrarec)
// Rimuovo la Richiesta del Circuito
CircuitSchema.statics.removeReqCircuit = async function(idapp, username, name) {
return Circuit.updateOne({idapp, name},
return await Circuit.updateOne({idapp, name},
{$pull: {req_users: {username: {$in: [username]}}}});
};
// Aggiungi agli utenti Rifiutati del Circuito
CircuitSchema.statics.refuseReqCircuit = async function(idapp, username, name) {
return Circuit.updateOne({idapp, name},
return await Circuit.updateOne({idapp, name},
{
$push:
{
@@ -430,7 +437,6 @@ CircuitSchema.statics.refuseReqCircuit = async function(idapp, username, name) {
};
const Circuit = mongoose.model('Circuit', CircuitSchema);
module.exports = {Circuit};

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false);
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const Schema = mongoose.Schema;
const escapeStringRegexp = require('escape-string-regexp');
@@ -185,7 +185,7 @@ CitySchema.statics.executeQueryPickup = async function(idapp, params) {
CitySchema.statics.findAllIdApp = async function(idapp) {
const myfind = {};
return City.find(myfind);
return await City.find(myfind);
};
const City = mongoose.model('City', CitySchema);

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');
@@ -35,7 +35,7 @@ ContribtypeSchema.statics.executeQueryTable = function (idapp, params) {
ContribtypeSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
return tools.DuplicateAllRecords(this, idapporig, idappdest);
return await tools.DuplicateAllRecords(this, idapporig, idappdest);
};
@@ -45,7 +45,7 @@ ContribtypeSchema.statics.findAllIdApp = async function (idapp) {
const myfind = { idapp };
return Contribtype.find(myfind, (err, arrrec) => {
return await Contribtype.find(myfind, (err, arrrec) => {
return arrrec
});
};

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -63,7 +63,7 @@ DisciplineSchema.statics.findAllIdApp = async function (idapp) {
{ $sort: { order: 1 } }
];
return Discipline
return await Discipline
.aggregate(query)
.then((arrrec) => {
return arrrec
@@ -100,7 +100,7 @@ DisciplineSchema.statics.executeQueryTable = function (idapp, params) {
DisciplineSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
return tools.DuplicateAllRecords(this, idapporig, idappdest);
return await tools.DuplicateAllRecords(this, idapporig, idappdest);
};

View File

@@ -1,5 +1,5 @@
var bcrypt = require('bcryptjs');
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const validator = require('validator');
const jwt = require('jsonwebtoken');
const _ = require('lodash');
@@ -227,14 +227,14 @@ ExtraListSchema.statics.findAllIdApp = async function (idapp) {
const myfind = { idapp };
return ExtraList.find(myfind, (err, arrrec) => {
return await ExtraList.find(myfind, (err, arrrec) => {
return arrrec
});
};
ExtraListSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
return tools.DuplicateAllRecords(this, idapporig, idappdest);
return await tools.DuplicateAllRecords(this, idapporig, idappdest);
};

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -38,7 +38,7 @@ GoodSchema.statics.findAllIdApp = async function (idapp) {
{ $sort: { descr: 1 } }
];
const res = Good
const res = await Good
.aggregate(query)
.then((arrrec) => {
return arrrec

View File

@@ -1,5 +1,5 @@
const bcrypt = require('bcryptjs');
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const validator = require('validator');
const jwt = require('jsonwebtoken');
const _ = require('lodash');
@@ -312,7 +312,7 @@ GraduatoriaSchema.statics.findAllIdApp = async function (idapp) {
const myfind = { idapp };
return Graduatoria.find(myfind, (err, arrrec) => {
return await Graduatoria.find(myfind, (err, arrrec) => {
return arrrec
});
};
@@ -381,7 +381,7 @@ GraduatoriaSchema.statics.getPosizioneInGraduatoria = async function (idapp, ind
const totposiz = await Graduatoria.countDocuments({ idapp });
return Graduatoria.findOne({ idapp, username, ind_order, num_tess }).then((rec) => {
return await Graduatoria.findOne({ idapp, username, ind_order, num_tess }).then((rec) => {
if (!!rec) {

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');
@@ -58,7 +58,7 @@ module.exports.executeQueryTable = function (idapp, params) {
module.exports.findAllIdApp = async function (idapp) {
const myfind = { idapp };
return Hours.find(myfind);
return await Hours.find(myfind);
};
module.exports.correggiHours = async function (idapp) {

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false);
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -55,7 +55,7 @@ LevelSchema.statics.findAllIdApp = async function(idapp) {
{$sort: {_id: 1}},
];
return Level.aggregate(query).then((arrrec) => {
return await Level.aggregate(query).then((arrrec) => {
return arrrec;
});

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false);
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -7,6 +7,7 @@ mongoose.level = 'F';
const tools = require('../tools/general');
const {ObjectID} = require('mongodb');
const {Account} = require('../models/account');
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
@@ -17,8 +18,11 @@ const MovementSchema = new Schema({
_id: {
type: Number,
},
idapp: {
type: String,
},
transactionDate: {
type: Date
type: Date,
},
accountFromId: {
type: Number,
@@ -42,7 +46,7 @@ const MovementSchema = new Schema({
type: Number,
},
expiringDate: {
type: Date
type: Date,
},
});
@@ -51,7 +55,7 @@ MovementSchema.statics.findAllIdApp = async function(idapp) {
const myfind = {idapp};
return MyMovement.find(myfind, (err, arrrec) => {
return await MyMovement.find(myfind, (err, arrrec) => {
return arrrec;
});
};
@@ -85,28 +89,150 @@ MovementSchema.statics.executeQueryTable = function(idapp, params) {
return tools.executeQueryTable(this, 0, params);
};
MovementSchema.statics.addMov = async function(accountFromId, accountToId, amount, causal) {
MovementSchema.statics.addMov = async function(idapp, accountFromId, accountToId, amount, causal) {
const {Account} = require('../models/account');
try {
let mymov = Movement(
{
idapp,
transactionDate: new Date(),
accountFromId: accountFromId._id,
accountToId: accountToId._id,
amount,
causal,
residual: 0,
// expiringDate:
},
);
let mymov = Movement(
{
transactionDate: new Date(),
accountFromId,
accountToId,
amount,
causal,
residual: 0,
// expiringDate:
}
);
// Update saldo dell'Account
Account.addtoSaldo(accountToId, amount);
// Update saldo dell'Account
Account.addtoSaldo(accountToId, amount);
Account.addtoSaldo(accountFromId, -amount);
Account.addtoSaldo(accountFromId, -amount);
return await mymov.save();
} catch (e) {
console.error('Error in addMov', e.message);
}
};
return mymov.save();
MovementSchema.statics.getQueryMovsByCircuitId = async function(idapp, username, circuitId) {
const myaccount = await Account.getAccountByUsernameAndCircuitId(idapp, username, circuitId, false);
if (myaccount) {
try {
let aggr1 = [
{
$match: {
idapp,
$or: [
{accountFromId: myaccount._id},
{accountToId: myaccount._id}],
},
},
{
$lookup: {
from: 'accounts',
localField: 'accountFromId',
foreignField: '_id',
as: 'accfrom',
},
},
{$unwind: '$accfrom'},
{
$lookup: {
from: 'users',
let: {username: '$accfrom.username', idapp: '$accfrom.idapp'},
pipeline: [
{
$match:
{
$expr:
{
$and:
[
{$eq: ['$$username', '$username']},
{$eq: ['$$idapp', '$idapp']},
],
},
},
},
],
as: 'userfrom',
},
},
{$unwind: '$userfrom'},
{
$lookup: {
from: 'accounts',
localField: 'accountToId',
foreignField: '_id',
as: 'accto',
},
},
{$unwind: '$accto'},
{
$lookup: {
from: 'users',
let: {username: '$accto.username', idapp: '$accto.idapp'},
pipeline: [
{
$match:
{
$expr:
{
$and:
[
{$eq: ['$$username', '$username']},
{$eq: ['$$idapp', '$idapp']},
],
},
},
},
],
as: 'userto',
},
},
{$unwind: '$userto'},
{
$project:
{
transactionDate: 1,
amount: 1,
causal: 1,
'userfrom.username': 1,
'userfrom.profile.img': 1,
'userto.username': 1,
'userto.profile.img': 1,
},
},
];
return aggr1;
} catch (e) {
return [];
}
}
return [];
};
MovementSchema.statics.getMovsByCircuitId = async function(idapp, username, circuitId) {
const MyMovement = this;
const myquery = await MyMovement.getQueryMovsByCircuitId(idapp, username, circuitId);
if (myquery) {
ris = await MyMovement.aggregate(myquery);
return ris;
}
return [];
};
const Movement = mongoose.model('Movement', MovementSchema);

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false);
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -113,7 +113,7 @@ MyBachecaSchema.statics.findAllIdApp = async function(idapp) {
{$sort: {descr: 1}},
];
return MyBacheca.aggregate(query).then((arrrec) => {
return await MyBacheca.aggregate(query).then((arrrec) => {
return arrrec;
});

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false);
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -114,7 +114,7 @@ MyGoodSchema.statics.findAllIdApp = async function(idapp) {
{$sort: {descr: 1}},
];
return MyGood.aggregate(query).then((arrrec) => {
return await MyGood.aggregate(query).then((arrrec) => {
return arrrec;
});

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false);
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const Schema = mongoose.Schema;
const tools = require('../tools/general');
@@ -177,14 +177,14 @@ MyGroupSchema.statics.findAllGroups = async function(idapp) {
// Rimuovo la Richiesta del Gruppo
MyGroupSchema.statics.removeReqGroup = async function(idapp, username, groupnameDest) {
return MyGroup.updateOne({idapp, groupname: groupnameDest},
return await MyGroup.updateOne({idapp, groupname: groupnameDest},
{$pull: {req_users: {username: {$in: [username]}}}});
};
// Aggiungi agli utenti Rifiutati del Gruppo
MyGroupSchema.statics.refuseReqGroup = async function(idapp, username, groupnameDest) {
return MyGroup.updateOne({idapp, groupname: groupnameDest},
return await MyGroup.updateOne({idapp, groupname: groupnameDest},
{
$push:
{
@@ -200,7 +200,7 @@ MyGroupSchema.statics.refuseReqGroup = async function(idapp, username, groupname
// Aggiungi agli Admin del Gruppo
MyGroupSchema.statics.addToAdminOfMyGroup = async function(idapp, username, groupnameDest) {
return MyGroup.updateOne({idapp, groupname: groupnameDest},
return await MyGroup.updateOne({idapp, groupname: groupnameDest},
{
$push:
{
@@ -216,7 +216,7 @@ MyGroupSchema.statics.addToAdminOfMyGroup = async function(idapp, username, grou
// Rimuovi dagli Admin del Gruppo
MyGroupSchema.statics.removeAdminOfMyGroup = async function(idapp, username, groupnameDest) {
return MyGroup.updateOne({idapp, groupname: groupnameDest},
return await MyGroup.updateOne({idapp, groupname: groupnameDest},
{$pull: {admins: {username: {$in: [username]}}}});
};
@@ -338,7 +338,7 @@ MyGroupSchema.statics.getInfoGroupByGroupname = async function(idapp, groupname)
MyGroupSchema.statics.deleteGroup = async function(idapp, usernameOrig, groupname) {
console.log('Gruppo ' + groupname + ' rimosso da ' + usernameOrig);
return MyGroup.findOneAndRemove({idapp, groupname});
return await MyGroup.findOneAndRemove({idapp, groupname});
};
MyGroupSchema.statics.getGroupsByUsername = async function(idapp, username, req) {

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false);
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -119,7 +119,7 @@ MyHospSchema.statics.findAllIdApp = async function(idapp) {
{$sort: {descr: 1}},
];
return MyHosp.aggregate(query).then((arrrec) => {
return await MyHosp.aggregate(query).then((arrrec) => {
return arrrec;
});

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');
@@ -140,7 +140,7 @@ MyPageSchema.statics.findAllIdApp = async function (idapp) {
});
};
MyPageSchema.statics.findOnlyStruttRec = async function (idapp) {
MyPageSchema.statics.findOnlyStruttRec = function (idapp) {
const MyPage = this;
const myfind = { idapp };
@@ -169,7 +169,7 @@ MyPageSchema.statics.findInternalPages = async function (idapp) {
internalpage: { $exists: true, $eq: true }
};
return MyPage.find(myfind, {
return await MyPage.find(myfind, {
title: 1,
path: 1,
onlyif_logged: 1,

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false);
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -117,7 +117,7 @@ MySkillSchema.statics.findAllIdApp = async function(idapp) {
{$sort: {descr: 1}},
];
return MySkill.aggregate(query).then((arrrec) => {
return await MySkill.aggregate(query).then((arrrec) => {
return arrrec;
});

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');
@@ -140,7 +140,7 @@ NewstosentSchema.statics.findAllIdApp = async function (idapp) {
// Extract only the Teacher where in the users table the field permissions is set 'Teacher' bit.
return Newstosent.find(myfind, (err, arrrec) => {
return await Newstosent.find(myfind, (err, arrrec) => {
return arrrec
});
};

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');
@@ -103,7 +103,7 @@ OperatorSchema.statics.executeQueryTable = function (idapp, params) {
return tools.executeQueryTable(this, idapp, params);
};
OperatorSchema.statics.findAllIdApp = async function (idapp) {
OperatorSchema.statics.findAllIdApp = function (idapp) {
const Operator = this;
const myfind = { idapp };

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const shared_consts = require('../tools/shared_nodejs');
@@ -50,7 +50,7 @@ var OrdersCart = module.exports = mongoose.model('OrdersCart', OrdersCartSchema)
module.exports.findAllIdApp = async function (idapp, userId) {
const myfind = { idapp, userId };
return await OrdersCart.find(myfind);
return await await OrdersCart.find(myfind);
};
module.exports.executeQueryTable = function (idapp, params) {

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');
@@ -38,7 +38,7 @@ PaymentTypeSchema.statics.findAllIdApp = async function (idapp) {
const myfind = { idapp };
return PaymentType.find(myfind, (err, arrrec) => {
return await PaymentType.find(myfind, (err, arrrec) => {
return arrrec
});
};

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');
@@ -50,7 +50,7 @@ PermissionSchema.statics.findAllIdApp = async function () {
const myfind = { };
return Permission.find(myfind, (err, arrrec) => {
return await Permission.find(myfind, (err, arrrec) => {
return arrrec
});
};

View File

@@ -1,4 +1,4 @@
mongoose = require('mongoose').set('debug', false)
mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');

View File

@@ -1,4 +1,4 @@
mongoose = require('mongoose').set('debug', false)
mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');

View File

@@ -1,4 +1,4 @@
var mongoose = require('mongoose').set('debug', false)
var mongoose = require('mongoose').set('debug', process.env.DEBUG)
const _ = require('lodash');
@@ -373,7 +373,7 @@ ProjectSchema.statics.enabletoModify = async function (userId, idProj) {
let obj = [];
return Project.findOne({
return await Project.findOne({
'_id': idProj,
$or: [{
privacywrite: { $ne: server_constants.Privacy.onlyme },

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false);
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const Schema = mongoose.Schema;
const escapeStringRegexp = require('escape-string-regexp');

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -60,7 +60,7 @@ SectorGoodSchema.statics.findAllIdApp = async function (idapp) {
{ $sort: { descr: 1 } }
];
return SectorGood
return await SectorGood
.aggregate(query)
.then((arrrec) => {
return arrrec

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false);
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -308,6 +308,9 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ', recnotif.paramsObj.username_action, recnotif.paramsObj.extrarec.qty, recnotif.paramsObj.extrarec.symbol);
tag = 'sendcoin';
recnotif.openUrl = '/circuit/' + recnotif.paramsObj.path; //++Todo: dove lo mando ?
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_ACCEPTED) {
newdescr = i18n.__('ID_CIRCUIT_COINS_ACCEPTED', recnotif.paramsObj.extrarec.qty, recnotif.paramsObj.extrarec.symbol, recnotif.paramsObj.username_action);
tag = 'sendcoin';
}
}
@@ -460,6 +463,12 @@ sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysa
newstatus = shared_consts.CircuitsNotif.STATUS_BLOCKED;
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_DELETE_USER) {
newstatus = shared_consts.CircuitsNotif.STATUS_DELETED;
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_ACCEPTED) {
typeidsearch = shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ;
newstatus = shared_consts.CircuitsNotif.STATUS_COINS_ACCEPTED;
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_REFUSED) {
typeidsearch = shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ;
newstatus = shared_consts.CircuitsNotif.STATUS_COINS_REFUSED;
}
}
@@ -511,7 +520,7 @@ sendNotifSchema.statics.saveNotif = async function(myrecnotif) {
if (!myrecout)
return null;
return myrecout.save().then((writeresult) => {
return await myrecout.save().then((writeresult) => {
let idobj = writeresult._id;
return SendNotif.findById(idobj).lean().then(async (recnotif) => {
return recnotif;

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');
@@ -84,7 +84,7 @@ SettingsSchema.statics.getValDbSettings = function (idapp, key, def) {
SettingsSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
return tools.DuplicateAllRecords(this, idapporig, idappdest);
return await tools.DuplicateAllRecords(this, idapporig, idappdest);
};

View File

@@ -1,4 +1,4 @@
mongoose = require('mongoose').set('debug', false)
mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');
@@ -6,7 +6,7 @@ const tools = require('../tools/general');
mongoose.Promise = global.Promise;
mongoose.level = "F";
mongoose.set('debug', false);
mongoose.set('debug', process.env.DEBUG);
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -38,7 +38,7 @@ SkillSchema.statics.findAllIdApp = async function (idapp) {
{ $sort: { descr: 1 } }
];
return Skill
return await Skill
.aggregate(query)
.then((arrrec) => {
return arrrec

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -55,7 +55,7 @@ StatusSkillSchema.statics.findAllIdApp = async function (idapp) {
{ $sort: { descr: 1 } }
];
return StatusSkill
return await StatusSkill
.aggregate(query)
.then((arrrec) => {
return arrrec

View File

@@ -1,4 +1,4 @@
mongoose = require('mongoose').set('debug', false)
mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -38,7 +38,7 @@ SubSkillSchema.statics.findAllIdApp = async function (idapp) {
{ $sort: { descr: 1 } }
];
return SubSkill
return await SubSkill
.aggregate(query)
.then((arrrec) => {
return arrrec

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');
@@ -51,7 +51,7 @@ TemplEmailSchema.statics.executeQueryTable = function (idapp, params) {
TemplEmailSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
return tools.DuplicateAllRecords(this, idapporig, idappdest);
return await tools.DuplicateAllRecords(this, idapporig, idappdest);
};
@@ -61,7 +61,7 @@ TemplEmailSchema.statics.findAllIdApp = async function (idapp) {
const myfind = { idapp };
return TemplEmail.find(myfind).lean();
return await TemplEmail.find(myfind).lean();
};

View File

@@ -1,4 +1,4 @@
var mongoose = require('mongoose').set('debug', false)
var mongoose = require('mongoose').set('debug', process.env.DEBUG)
const _ = require('lodash');

View File

@@ -1,5 +1,5 @@
const bcrypt = require('bcryptjs');
const mongoose = require('mongoose').set('debug', false);
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const validator = require('validator');
const jwt = require('jsonwebtoken');
const _ = require('lodash');
@@ -470,7 +470,7 @@ UserSchema.statics.setZoomPresenza = async function(idapp, id, presenza) {
allData.precDataUser = await User.getInfoUser(idapp,
allData.myuser.username);
return User.findByIdAndUpdate(id,
return await User.findByIdAndUpdate(id,
{$set: {'profile.saw_zoom_presentation': presenza}}).then((rec) => {
if (presenza) {
const messaggio = tools.get__('ZOOM_CONFERMATO');
@@ -663,15 +663,15 @@ UserSchema.statics.findByUsername = async function(idapp, username, alsoemail, o
//++TODO: Set only the necessary fields to get in memory
return User.findOne({
return await User.findOne({
idapp: idapp,
username: {$regex: regexusername},
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}).then((ris) => {
}).then(async (ris) => {
if ((!ris) && (alsoemail)) {
regexemail = new RegExp(['^', username.toLowerCase(), '$'].join(''), 'i');
return User.findOne({
return await User.findOne({
'idapp': idapp,
'email': {$regex: regexemail},
$or: [
@@ -1009,7 +1009,7 @@ UserSchema.statics.setaportador_solidario = async function(
UserSchema.statics.setVerifiedByAportadorToALL = async function() {
return User.updateMany({}, {$set: {'verified_by_aportador': true}},
return await User.updateMany({}, {$set: {'verified_by_aportador': true}},
{new: false});
};
@@ -1051,7 +1051,7 @@ UserSchema.statics.isUserQualified9 = async function(idapp, username) {
UserSchema.statics.getnumPaymentOk = function (idapp) {
const User = this;
return User.count({
return await User.count({
idapp,
$and: [
{
@@ -1146,7 +1146,7 @@ UserSchema.statics.createNewRequestPwd = function(idapp, email) {
toString();
user.date_tokenforgot = new Date();
user.lasttimeonline = new Date();
return user.save().then(async () => {
return await user.save().then(async () => {
await sendemail.sendEmail_RequestNewPassword(user.lang, user, user.email, user.idapp, user.tokenforgot);
return true;
@@ -1172,7 +1172,7 @@ UserSchema.statics.createNewRequestPwdByUsernameAndGetLink = async function(idap
user.date_tokenforgot = new Date();
user.lasttimeonline = new Date();
return user.save().then(() => {
return await user.save().then(() => {
return tools.getlinkRequestNewPassword(idapp, user.email, user.tokenforgot);
});
}
@@ -1294,7 +1294,7 @@ UserSchema.methods.removeToken = function(token) {
UserSchema.statics.getEmailByUsername = async function(idapp, username) {
const User = this;
return User.findOne({
return await User.findOne({
idapp, username,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}).then((arrrec) => {
@@ -1307,7 +1307,7 @@ UserSchema.statics.getEmailByUsername = async function(idapp, username) {
UserSchema.statics.getUsernameById = async function(idapp, id) {
const User = this;
return User.findOne({
return await User.findOne({
idapp, _id: id,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}, {username: 1}).then((myuser) => {
@@ -1340,7 +1340,7 @@ UserSchema.statics.isMyFriend = async function(idapp, username, myusername) {
const myfriends = await User.getUsernameFriendsByUsername(idapp, myusername);
if (myfriends) {
return myfriends.includes(username);
return await myfriends.includes(username);
} else {
return false;
}
@@ -1576,7 +1576,7 @@ UserSchema.statics.getArrUsernameFromFieldByUsername = async function(
UserSchema.statics.getUsernameReqFriendsByUsername = async function(
idapp, username) {
return this.getArrUsernameFromFieldByUsername(idapp, username, 'profile',
return await this.getArrUsernameFromFieldByUsername(idapp, username, 'profile',
'req_friends');
};
@@ -1584,7 +1584,7 @@ UserSchema.statics.getUsernameReqFriendsByUsername = async function(
UserSchema.statics.getUsernameFriendsByUsername = async function(
idapp, username) {
return this.getArrUsernameFromFieldByUsername(idapp, username, 'profile',
return await this.getArrUsernameFromFieldByUsername(idapp, username, 'profile',
'friends');
};
@@ -1592,14 +1592,14 @@ UserSchema.statics.getUsernameFriendsByUsername = async function(
UserSchema.statics.getUsernameGroupsByUsername = async function(
idapp, username) {
return this.getArrUsernameFromFieldByUsername(idapp, username, 'profile',
return await this.getArrUsernameFromFieldByUsername(idapp, username, 'profile',
'mygroups');
};
UserSchema.statics.getUsernameCircuitsByUsername = async function(
idapp, username) {
return this.getArrUsernameFromFieldByUsername(idapp, username, 'profile',
return await this.getArrUsernameFromFieldByUsername(idapp, username, 'profile',
'mycircuits');
};
@@ -1607,39 +1607,39 @@ UserSchema.statics.getUsernameCircuitsByUsername = async function(
// Rimuovo l'Amicizia
UserSchema.statics.removeFriend = async function(
idapp, username, usernameDest) {
return User.updateOne({idapp, username},
return await User.updateOne({idapp, username},
{$pull: {'profile.friends': {username: {$in: [usernameDest]}}}});
};
// Rimuovo il Gruppo
UserSchema.statics.removeFromMyGroups = async function(
idapp, username, groupnameDest) {
return User.updateOne({idapp, username},
return await User.updateOne({idapp, username},
{$pull: {'profile.mygroups': {groupname: {$in: [groupnameDest]}}}});
};
// Rimuovo il Gruppo
UserSchema.statics.removeFromCircuits = async function(idapp, username, circuitname) {
return User.updateOne({idapp, username},
return await User.updateOne({idapp, username},
{$pull: {'profile.mycircuits': {circuitname: {$in: [circuitname]}}}});
};
// Rimuovo il Gruppo per Tutti gli Utenti
UserSchema.statics.removeAllUsersFromMyGroups = async function(idapp, groupnameDest) {
return User.updateMany({idapp},
return await User.updateMany({idapp},
{$pull: {'profile.mygroups': {groupname: {$in: [groupnameDest]}}}});
};
// Rimuovo il Circuito per Tutti gli Utenti
UserSchema.statics.removeAllUsersFromMyCircuits = async function(idapp, circuitname) {
return User.updateMany({idapp},
return await User.updateMany({idapp},
{$pull: {'profile.mycircuits': {circuitname: {$in: [circuitname]}}}});
};
// Rimuovo la Richiesta di Amicizia
UserSchema.statics.removeReqFriend = async function(
idapp, username, usernameDest) {
return User.updateOne({idapp, username: username},
return await User.updateOne({idapp, username: username},
{$pull: {'profile.req_friends': {username: {$in: [usernameDest]}}}});
};
@@ -1665,7 +1665,7 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user
await this.setFriendsCmd(req, idapp, usernameOrig, usernameDest,
shared_consts.FRIENDSCMD.SETFRIEND, value);
return User.updateOne({idapp, username: usernameDest},
return await User.updateOne({idapp, username: usernameDest},
{$set: {verified_by_aportador: value, trust_modified: new Date()}},
{new: false});
@@ -1890,7 +1890,7 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user
UserSchema.statics.ifAlreadyInGroup = async function(idapp, usernameOrig, groupnameDest) {
// Controllo se è stato già inserito
return User.findOne({
return await User.findOne({
idapp,
username: usernameOrig,
'profile.mygroups': {
@@ -1903,7 +1903,7 @@ UserSchema.statics.ifAlreadyInGroup = async function(idapp, usernameOrig, groupn
UserSchema.statics.ifAlreadyInCircuit = async function(idapp, usernameOrig, circuitname) {
// Controllo se è stato già inserito
return User.findOne({
return await User.findOne({
idapp,
username: usernameOrig,
'profile.mycircuits': {
@@ -1915,7 +1915,7 @@ UserSchema.statics.ifAlreadyInCircuit = async function(idapp, usernameOrig, circ
UserSchema.statics.countUsersInGroup = async function(idapp, groupnameDest) {
// Controllo se è stato già inserito
return User.countDocuments({
return await User.countDocuments({
idapp,
'profile.mygroups': {
$elemMatch: {groupname: {$eq: groupnameDest}},
@@ -1927,7 +1927,7 @@ UserSchema.statics.countUsersInGroup = async function(idapp, groupnameDest) {
UserSchema.statics.countUsersInCircuit = async function(idapp, circuitname) {
// Controllo se è stato già inserito
return User.countDocuments({
return await User.countDocuments({
idapp,
'profile.mycircuits': {
$elemMatch: {circuitname: {$eq: circuitname}},
@@ -2190,13 +2190,13 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
} else if (cmd === shared_consts.CIRCUITCMD.REMOVEADMIN) {
ris = await Circuit.removeAdminOfCircuit(idapp, usernameOrig, circuitname); // Rimuovo la richiesta di entrare nel gruppo
w
// Invia una notifica alla persona
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
} else if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REQ) {
// Invia una notifica di moneta alla persona
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
ris = await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
} else if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT) {
ris = await Circuit.sendCoins(idapp, usernameOrig, extrarec);
@@ -2296,7 +2296,7 @@ UserSchema.statics.getInfoFriendByUsername = async function(idapp, username) {
const whatToShow = getWhatToShow(idapp, username);
return User.findOne({
return await User.findOne({
idapp,
username,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
@@ -2309,7 +2309,7 @@ UserSchema.statics.getInfoAskFriendByUsername = async function(
const whatToShow = getWhatToShow_Unknown(idapp, username);
return User.findOne({
return await User.findOne({
idapp,
username,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
@@ -2321,7 +2321,7 @@ UserSchema.statics.getAskedFriendsByUsername = async function(idapp, username) {
const whatToShow_Unknown = getWhatToShow_Unknown(idapp, username);
return User.find({
return await User.find({
idapp,
'profile.req_friends': {
$elemMatch: {username: {$eq: username}},
@@ -2402,7 +2402,7 @@ UserSchema.statics.getAportadorSolidarioByUsername = async function(
idapp, username) {
const User = this;
return User.findOne({
return await User.findOne({
idapp, username,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}).then((rec) => {
@@ -2415,7 +2415,7 @@ UserSchema.statics.getAportadorSolidarioByUsername = async function(
UserSchema.statics.UserByIdTelegram = async function(idapp, teleg_id) {
const User = this;
return User.findOne({
return await User.findOne({
idapp, 'profile.teleg_id': teleg_id,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}).lean().then((rec) => {
@@ -2428,7 +2428,7 @@ UserSchema.statics.UserByIdTelegram = async function(idapp, teleg_id) {
UserSchema.statics.UsersByIdTelegram = async function(idapp, teleg_id) {
const User = this;
return User.find({
return await User.find({
idapp, 'profile.teleg_id': teleg_id,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}).lean().then((rec) => {
@@ -2445,7 +2445,7 @@ UserSchema.statics.setPicProfile = async function(idapp, username, imgpic) {
'profile.img': imgpic,
};
return User.findOneAndUpdate({
return await User.findOneAndUpdate({
idapp, username,
}, {$set: fields_to_update}, {new: false}).lean().then((record) => {
return !!record;
@@ -2456,7 +2456,7 @@ UserSchema.statics.setPicProfile = async function(idapp, username, imgpic) {
UserSchema.statics.TelegIdByUsername = async function(idapp, username) {
const User = this;
return User.findOne({
return await User.findOne({
idapp, username,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}, {'profile.teleg_id': 1}).lean().then((rec) => {
@@ -2469,7 +2469,7 @@ UserSchema.statics.TelegIdByUsername = async function(idapp, username) {
UserSchema.statics.TelegIdById = async function(idapp, id) {
const User = this;
return User.findOne({
return await User.findOne({
idapp,
_id: id,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
@@ -2481,7 +2481,7 @@ UserSchema.statics.TelegIdById = async function(idapp, id) {
};
UserSchema.statics.notAsk_VerifByUsername = async function(idapp, username) {
return User.findOne({
return await User.findOne({
idapp, username,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}, {'notask_verif': 1}).lean().then((rec) => {
@@ -2500,7 +2500,7 @@ UserSchema.statics.SetTelegramCheckCode = async function(
'profile.teleg_checkcode': teleg_checkcode,
};
return User.findOneAndUpdate({
return await User.findOneAndUpdate({
_id: id,
}, {$set: fields_to_update}, {new: false}).lean().then((record) => {
return !!record;
@@ -2515,7 +2515,7 @@ UserSchema.statics.NonVoglioImbarcarmi = async function(idapp, username) {
non_voglio_imbarcarmi: true,
};
return User.findOneAndUpdate({
return await User.findOneAndUpdate({
idapp,
username,
}, {$set: fields_to_update}, {new: false}).then((record) => {
@@ -2533,7 +2533,7 @@ UserSchema.statics.SetTelegramIdSuccess = async function(idapp, id, teleg_id) {
'profile.teleg_checkcode': 0,
};
return User.findOneAndUpdate({
return await User.findOneAndUpdate({
idapp,
_id: id,
}, {$set: fields_to_update}, {new: false}).lean().then((record) => {
@@ -2560,7 +2560,7 @@ UserSchema.statics.setUsernameTelegram = async function(
'profile.lastname_telegram': lastname_telegram,
};
return User.findOneAndUpdate({
return await User.findOneAndUpdate({
idapp,
_id: id,
}, {$set: fields_to_update}, {new: false}).then((record) => {
@@ -2576,7 +2576,7 @@ UserSchema.statics.SetLang = async function(idapp, id, lang) {
lang,
};
return User.findOneAndUpdate({
return await User.findOneAndUpdate({
_id: id,
}, {$set: fields_to_update}, {new: false}).then((record) => {
return record;
@@ -2608,7 +2608,7 @@ UserSchema.statics.getNameSurnameByUsername = async function(
idapp, username, reale = false) {
const User = this;
return User.findOne({
return await User.findOne({
idapp, username,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}, {username: 1, name: 1, surname: 1}).then((rec) => {
@@ -2636,7 +2636,7 @@ UserSchema.statics.getIdByUsername = async function(idapp, username) {
let regexp = new RegExp(`^${username}$`, 'i');
return User.findOne({
return await User.findOne({
idapp,
username: {$regex: regexp},
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
@@ -2652,7 +2652,7 @@ UserSchema.statics.getRealUsernameByUsername = async function(idapp, username) {
let regexp = new RegExp(`^${username}$`, 'i');
return User.findOne({
return await User.findOne({
idapp,
username:
{$regex: regexp},
@@ -2667,7 +2667,7 @@ UserSchema.statics.getRealUsernameByUsername = async function(idapp, username) {
UserSchema.statics.getRecLangAndIdByUsername = async function(idapp, username) {
const User = this;
return User.findOne({
return await User.findOne({
idapp, username,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}, {lang: 1, _id: 1}).then((rec) => {
@@ -2680,7 +2680,7 @@ UserSchema.statics.getRecLangAndIdByUsername = async function(idapp, username) {
UserSchema.statics.getNameSurnameById = async function(idapp, userId) {
const User = this;
return User.findOne({
return await User.findOne({
idapp,
_id: userId,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
@@ -2694,7 +2694,7 @@ UserSchema.statics.getNameSurnameById = async function(idapp, userId) {
UserSchema.statics.getusersManagers = async function(idapp) {
const User = this;
return User.find({idapp, 'profile.manage_telegram': true},
return await User.find({idapp, 'profile.manage_telegram': true},
{username: 1, 'profile.teleg_id': 1, perm: 1}).then((arrrec) => {
return (!!arrrec) ? arrrec : null;
}).catch((e) => {
@@ -2705,7 +2705,7 @@ UserSchema.statics.getusersManagers = async function(idapp) {
UserSchema.statics.getusersRespList = async function(idapp) {
const User = this;
return User.find({idapp, 'profile.resplist': true},
return await User.find({idapp, 'profile.resplist': true},
{_id: 1, username: 1, name: 1, surname: 1}).then((arrrec) => {
return (!!arrrec) ? arrrec : null;
}).catch((e) => {
@@ -2716,7 +2716,7 @@ UserSchema.statics.getusersRespList = async function(idapp) {
UserSchema.statics.getusersWorkersList = async function(idapp) {
const User = this;
return User.find({idapp, 'profile.workerslist': true},
return await User.find({idapp, 'profile.workerslist': true},
{_id: 1, username: 1, name: 1, surname: 1}).then((arrrec) => {
return (!!arrrec) ? arrrec : null;
}).catch((e) => {
@@ -2727,7 +2727,7 @@ UserSchema.statics.getusersWorkersList = async function(idapp) {
UserSchema.statics.getusersManagersAndZoomeri = async function(idapp) {
const User = this;
return User.find(
return await User.find(
{
idapp,
or: [
@@ -2754,7 +2754,7 @@ UserSchema.statics.getUsersTelegALL = async function(idapp, username) {
const User = this;
if (!!username) {
return User.find({idapp, username, 'profile.teleg_id': {$gt: 0}}).lean();
return await User.find({idapp, username, 'profile.teleg_id': {$gt: 0}}).lean();
then((arrrec) => {
return (!!arrrec) ? arrrec : null;
}).
@@ -2762,7 +2762,7 @@ UserSchema.statics.getUsersTelegALL = async function(idapp, username) {
console.error('getUsersTelegALL', e);
});
} else {
return User.find({idapp, 'profile.teleg_id': {$gt: 0}}).
return await User.find({idapp, 'profile.teleg_id': {$gt: 0}}).
lean().
then((arrrec) => {
return (!!arrrec) ? arrrec : null;
@@ -2777,7 +2777,7 @@ UserSchema.statics.getUsersTelegALL = async function(idapp, username) {
UserSchema.statics.isManagerByIdTeleg = async function(idapp, idtelegram) {
const User = this;
return User.findOne({
return await User.findOne({
idapp,
'profile.manage_telegram': true,
'profile.teleg_id': idtelegram,
@@ -2792,7 +2792,7 @@ UserSchema.statics.isManagerByIdTeleg = async function(idapp, idtelegram) {
UserSchema.statics.isAdminByIdTeleg = async function(idapp, idtelegram) {
const User = this;
return User.findOne({
return await User.findOne({
idapp,
username: 'paoloar77',
'profile.manage_telegram': true,
@@ -2884,14 +2884,14 @@ UserSchema.statics.findAllIdApp = async function(idapp) {
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
};
return User.find(myfind, (err, arrrec) => {
return await User.find(myfind, (err, arrrec) => {
return arrrec;
});
};
UserSchema.statics.DuplicateAllRecords = async function(idapporig, idappdest) {
return tools.DuplicateAllRecords(this, idapporig, idappdest);
return await tools.DuplicateAllRecords(this, idapporig, idappdest);
};
@@ -3005,7 +3005,7 @@ UserSchema.statics.getUsersRegistered = async function(idapp) {
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
};
return User.count(myfind);
return await User.count(myfind);
};
UserSchema.statics.getUsersOnLineToday = async function(idapp) {
@@ -3020,7 +3020,7 @@ UserSchema.statics.getUsersOnLineToday = async function(idapp) {
lasttimeonline: {$gt: starttoday},
};
return User.count(myfind);
return await User.count(myfind);
};
/*
@@ -3089,7 +3089,7 @@ UserSchema.statics.getEmailNotVerified = async function(idapp) {
verified_email: false,
};
return User.count(myfind);
return await User.count(myfind);
};
UserSchema.statics.getUsersTelegramAttivo = async function(idapp) {
@@ -3101,7 +3101,7 @@ UserSchema.statics.getUsersTelegramAttivo = async function(idapp) {
'profile.teleg_id': {$gt: 0},
};
return User.count(myfind);
return await User.count(myfind);
};
UserSchema.statics.getUsersAutorizzati = async function(idapp) {
@@ -3114,7 +3114,7 @@ UserSchema.statics.getUsersAutorizzati = async function(idapp) {
verified_by_aportador: true,
};
return User.count(myfind);
return await User.count(myfind);
};
UserSchema.statics.getUsersAutorizzare = async function(idapp) {
@@ -3127,7 +3127,7 @@ UserSchema.statics.getUsersAutorizzare = async function(idapp) {
verified_by_aportador: {$exists: false},
};
return User.count(myfind);
return await User.count(myfind);
};
UserSchema.statics.getUsersTelegramPending = async function(idapp) {
@@ -3139,7 +3139,7 @@ UserSchema.statics.getUsersTelegramPending = async function(idapp) {
'profile.teleg_checkcode': {$gt: 0},
};
return User.count(myfind);
return await User.count(myfind);
};
UserSchema.statics.getNumUsers = async function(idapp) {
@@ -3150,7 +3150,7 @@ UserSchema.statics.getNumUsers = async function(idapp) {
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
};
return User.count(myfind);
return await User.count(myfind);
};
UserSchema.statics.getUsersZoom = async function(idapp) {
@@ -3162,7 +3162,7 @@ UserSchema.statics.getUsersZoom = async function(idapp) {
'profile.saw_zoom_presentation': true,
};
return User.count(myfind);
return await User.count(myfind);
};
UserSchema.statics.getUsersResidenti = async function(idapp) {
@@ -3174,7 +3174,7 @@ UserSchema.statics.getUsersResidenti = async function(idapp) {
'profile.socioresidente': {$exists: true, $eq: true},
};
return User.find(myfind, {username: 1, name: 1, surname: 1});
return await User.find(myfind, {username: 1, name: 1, surname: 1});
};
UserSchema.statics.getSaw_and_Accepted = async function(idapp) {
@@ -3186,7 +3186,7 @@ UserSchema.statics.getSaw_and_Accepted = async function(idapp) {
'profile.saw_and_accepted': shared_consts.ALL_SAW_AND_ACCEPTED,
};
return User.count(myfind);
return await User.count(myfind);
};
UserSchema.statics.getUsersDreams = async function(idapp) {
@@ -3199,7 +3199,7 @@ UserSchema.statics.getUsersDreams = async function(idapp) {
'$expr': {'$gt': [{'$strLenCP': '$profile.my_dream'}, 10]},
};
return User.count(myfind);
return await User.count(myfind);
};
UserSchema.statics.getLastUsers = async function(idapp) {
@@ -3207,7 +3207,7 @@ UserSchema.statics.getLastUsers = async function(idapp) {
const lastn = await Settings.getValDbSettings(idapp, 'SHOW_LAST_N_USERS', 5);
return User.find(
return await User.find(
{
idapp,
$or: [
@@ -3231,7 +3231,7 @@ UserSchema.statics.getLastUsers = async function(idapp) {
UserSchema.statics.checkUser = async function(idapp, username) {
const User = this;
return User.findOne({idapp, username}, {
return await User.findOne({idapp, username}, {
verified_email: 1,
verified_by_aportador: 1,
notask_verif: 1,
@@ -3301,7 +3301,7 @@ UserSchema.statics.getDistinctNationalityQuery = function(idapp) {
UserSchema.statics.findAllDistinctNationality = async function(idapp) {
const User = this;
return User.aggregate(User.getDistinctNationalityQuery(idapp)).then(ris => {
return await User.aggregate(User.getDistinctNationalityQuery(idapp)).then(ris => {
// console.table(ris);
return ris;
});
@@ -3403,7 +3403,7 @@ UserSchema.statics.getnumRegNDays = function(idapp, nrec) {
UserSchema.statics.calcnumRegUntilDay = async function(idapp) {
const User = this;
return User.aggregate(User.getnumRegNDays(idapp, 30)).then((arr) => {
return await User.aggregate(User.getnumRegNDays(idapp, 30)).then((arr) => {
return arr.reduce((sum, rec) => sum + rec.count, 0);
});
@@ -3412,7 +3412,7 @@ UserSchema.statics.calcnumRegUntilDay = async function(idapp) {
UserSchema.statics.calcRegDaily = async function(idapp) {
const User = this;
return User.aggregate(User.getUsersRegDaily(idapp, 60)).then(ris => {
return await User.aggregate(User.getUsersRegDaily(idapp, 60)).then(ris => {
// console.table(ris);
return ris;
});
@@ -3421,7 +3421,7 @@ UserSchema.statics.calcRegDaily = async function(idapp) {
UserSchema.statics.calcRegWeekly = async function(idapp) {
const User = this;
return User.aggregate(User.getUsersRegWeekly(idapp, 20 * 7)).then(ris => {
return await User.aggregate(User.getUsersRegWeekly(idapp, 20 * 7)).then(ris => {
// console.table(ris);
return ris.slice(0, -1);
});

View File

@@ -1,5 +1,5 @@
var mongoose = require('mongoose').set('debug', false)
var mongoose = require('mongoose').set('debug', process.env.DEBUG)
var variantSchema = mongoose.Schema({
productID: {

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const Schema = mongoose.Schema;
const tools = require('../tools/general');
@@ -44,7 +44,7 @@ WhereSchema.statics.findAllIdApp = async function (idapp) {
const myfind = { idapp };
return Where.find(myfind, (err, arrrec) => {
return await Where.find(myfind, (err, arrrec) => {
return arrrec
});
};