Circuits OK

Accounts Ok
Movements OK
This commit is contained in:
Paolo Arena
2022-09-14 11:32:04 +02:00
parent 2f24a02a63
commit 845e244470
90 changed files with 362 additions and 258 deletions

View File

@@ -1,7 +1,7 @@
/*
Account is a User's single Circuit
*/
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const mongoose = require('mongoose').set('debug', false);
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -18,7 +18,10 @@ mongoose.plugin(schema => {
const AccountSchema = new Schema({
_id: {
type: Number,
type: String,
default: function () {
return new ObjectID().toString()
}
},
idapp: {
type: String,
@@ -27,7 +30,7 @@ const AccountSchema = new Schema({
type: String,
},
circuitId: { // ----- REF TO Circuit
type: Number,
type: String,
},
name: {
type: String,
@@ -72,16 +75,7 @@ AccountSchema.statics.findAllIdApp = async function(idapp) {
AccountSchema.pre('save', async function(next) {
if (this.isNew) {
const myrec = await Account.findOne().limit(1).sort({_id: -1});
if (!!myrec) {
if (myrec._doc._id === 0)
this._id = 1;
else
this._id = myrec._doc._id + 1;
} else {
this._id = 1;
}
this._id = new ObjectID().toString()
}
next();
@@ -130,6 +124,14 @@ AccountSchema.statics.addtoSaldo = async function(id, amount) {
return null;
};
AccountSchema.pre('save', async function(next) {
if (this.isNew) {
this.date_created = new Date();
}
next();
});
AccountSchema.statics.getAccountByUsernameAndCircuitId = async function(idapp, username, {circuitId, circuitName}, createifnotexist) {
const Account = this;
@@ -152,26 +154,35 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function(idapp, u
myquery.circuitName = circuitName;
}
const mycircuit = await Circuit.getCircuitById(circuitId);
let mycircuit;
if (circuitId)
mycircuit = await Circuit.getCircuitById(circuitId);
else
mycircuit = await Circuit.findOne({name: circuitName}).lean();
let myaccount = await Account.findOne(myquery).lean();
if (!myaccount && createifnotexist) {
myaccount = new Account({
idapp,
username,
circuitId: mycircuit._id,
deperibile: false,
fidoConcesso: mycircuit.fido_scoperto_default,
qta_maxConcessa: mycircuit.qta_max_default,
importo_iniziale: 0,
saldo: 0,
});
if (mycircuit) {
let myaccount = await Account.findOne(myquery).lean();
return await myaccount.save();
if (!myaccount && createifnotexist) {
myaccount = new Account({
_id: new ObjectID().toString(),
idapp,
username,
circuitId: mycircuit._id,
deperibile: false,
fidoConcesso: mycircuit.fido_scoperto_default,
qta_maxConcessa: mycircuit.qta_max_default,
importo_iniziale: 0,
saldo: 0,
});
return await myaccount.save();
}
return myaccount;
}
return myaccount;
return null;
} catch (e) {
console.error('error', e);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const mongoose = require('mongoose').set('debug', false);
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -17,7 +17,10 @@ mongoose.plugin(schema => {
const CircuitSchema = new Schema({
_id: {
type: Number,
type: String,
default: function () {
return new ObjectID().toString()
}
},
idapp: {
type: String,
@@ -165,16 +168,7 @@ const CircuitSchema = new Schema({
CircuitSchema.pre('save', async function(next) {
if (this.isNew) {
const myrec = await Circuit.findOne().limit(1).sort({_id: -1});
if (!!myrec) {
if (myrec._doc._id === 0)
this._id = 1;
else
this._id = myrec._doc._id + 1;
} else {
this._id = 1;
}
this._id = new ObjectID().toString();
this.date_created = new Date();
}
@@ -210,7 +204,7 @@ CircuitSchema.statics.executeQueryTable = function(idapp, params) {
CircuitSchema.statics.getWhatToShow = function(idapp, username) {
// FOR ME, PERMIT ALL
return {
circuitId: 1,
_id: 1,
groupnameId: 1,
path: 1,
name: 1,
@@ -245,7 +239,6 @@ CircuitSchema.statics.removeAdminOfMyCircuit = async function(idapp, username, n
CircuitSchema.statics.getWhatToShow_Unknown = function(idapp, username) {
return {
circuitId: 1,
groupnameId: 1,
path: 1,
name: 1,
@@ -271,7 +264,7 @@ CircuitSchema.statics.getWhatToShow_Unknown = function(idapp, username) {
};
};
CircuitSchema.statics.getCircuitsByUsername = async function(idapp, username, req) {
CircuitSchema.statics.getCircuitsByUsername = async function(idapp, username, user) {
try {
const {User} = require('../models/user');
@@ -327,7 +320,7 @@ CircuitSchema.statics.getCircuitsByUsername = async function(idapp, username, re
asked_circuits,
refused_circuits,
manage_mycircuits,
mycircuits: req.user.profile.mycircuits,
mycircuits: user.profile.mycircuits,
};
} catch (e) {
@@ -381,7 +374,7 @@ CircuitSchema.statics.getCircuitByName = async function(idapp, name) {
CircuitSchema.statics.getCircuitById = async function(circuitId) {
const myfind = {
circuitId,
_id: circuitId,
};
try {

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,5 +1,5 @@
var bcrypt = require('bcryptjs');
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const mongoose = require('mongoose').set('debug', false)
const validator = require('validator');
const jwt = require('jsonwebtoken');
const _ = require('lodash');
@@ -16,7 +16,7 @@ mongoose.plugin(schema => {
schema.options.usePushEach = true
});
mongoose.set('debug', process.env.DEBUG);
mongoose.set('debug', false);
var ExtraListSchema = new mongoose.Schema({
idapp: {

View File

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

View File

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

View File

@@ -1,5 +1,5 @@
const bcrypt = require('bcryptjs');
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const mongoose = require('mongoose').set('debug', false)
const validator = require('validator');
const jwt = require('jsonwebtoken');
const _ = require('lodash');
@@ -20,7 +20,7 @@ mongoose.plugin(schema => {
schema.options.usePushEach = true
});
mongoose.set('debug', process.env.DEBUG);
mongoose.set('debug', false);
const GraduatoriaSchema = new mongoose.Schema({
idapp: {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const mongoose = require('mongoose').set('debug', false);
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -16,7 +16,10 @@ mongoose.plugin(schema => {
const MovementSchema = new Schema({
_id: {
type: Number,
type: String,
default: function () {
return new ObjectID().toString()
}
},
idapp: {
type: String,
@@ -25,10 +28,10 @@ const MovementSchema = new Schema({
type: Date,
},
accountFromId: {
type: Number,
type: String,
},
accountToId: {
type: Number,
type: String,
},
causal_table: {
type: String,
@@ -62,16 +65,8 @@ MovementSchema.statics.findAllIdApp = async function(idapp) {
MovementSchema.pre('save', async function(next) {
if (this.isNew) {
const myrec = await Movement.findOne().limit(1).sort({_id: -1});
if (!!myrec) {
if (myrec._doc._id === 0)
this._id = 1;
else
this._id = myrec._doc._id + 1;
} else {
this._id = 1;
}
this.transactionDate = new Date();
}
next();
@@ -94,6 +89,7 @@ MovementSchema.statics.addMov = async function(idapp, accountFromId, accountToId
try {
let mymov = Movement(
{
_id: new ObjectID().toString(),
idapp,
transactionDate: new Date(),
accountFromId: accountFromId._id,
@@ -105,12 +101,15 @@ MovementSchema.statics.addMov = async function(idapp, accountFromId, accountToId
},
);
// Update saldo dell'Account
Account.addtoSaldo(accountToId, amount);
const rismov = await mymov.save();
if (rismov) {
// Update saldo dell'Account
Account.addtoSaldo(accountToId, amount);
Account.addtoSaldo(accountFromId, -amount);
Account.addtoSaldo(accountFromId, -amount);
return await mymov.save();
return rismov;
}
} catch (e) {
console.error('Error in addMov', e.message);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
var mongoose = require('mongoose').set('debug', process.env.DEBUG)
var mongoose = require('mongoose').set('debug', false)
const _ = require('lodash');
@@ -16,7 +16,7 @@ mongoose.plugin(schema => {
schema.options.usePushEach = true
});
mongoose.set('debug', process.env.DEBUG);
mongoose.set('debug', false);
var ProjectSchema = new mongoose.Schema({
idapp: {

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const mongoose = require('mongoose').set('debug', false);
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
@@ -84,7 +84,6 @@ const sendNotifSchema = new Schema({
options: {
type: Array,
},
});
sendNotifSchema.statics.setNotifAsRead = function(idapp, username, idnotif) {
@@ -326,10 +325,27 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
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_SENDCOINSREQ_SENT) {
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ_TO_ME', recnotif.paramsObj.extrarec.qty.toString(),
recnotif.paramsObj.extrarec.symbol, recnotif.paramsObj.extrarec.dest);
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.toString(), recnotif.paramsObj.extrarec.symbol,
recnotif.paramsObj.username_action);
tag = 'sendcoin';
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_ACCEPTED_SENT) {
newdescr = i18n.__('ID_CIRCUIT_COINS_ACCEPTED_TO_ME', recnotif.paramsObj.extrarec.qty.toString(), recnotif.paramsObj.extrarec.symbol,
recnotif.paramsObj.extrarec.dest);
tag = 'sendcoin';
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_REFUSED) {
newdescr = i18n.__('ID_CIRCUIT_COINS_REFUSED', recnotif.paramsObj.extrarec.qty.toString(), recnotif.paramsObj.extrarec.symbol,
recnotif.paramsObj.username_action);
tag = 'sendcoin';
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_REFUSED_SENT) {
newdescr = i18n.__('ID_CIRCUIT_COINS_REFUSED_TO_ME', recnotif.paramsObj.extrarec.qty.toString(), recnotif.paramsObj.extrarec.symbol,
recnotif.paramsObj.extrarec.dest);
tag = 'sendcoin';
}
}
@@ -469,7 +485,9 @@ sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysa
newstatus = shared_consts.GroupsNotifs.STATUS_GROUPS_DELETED;
}
} else if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS) {
idnotiftosearch = myrecnotif.paramsObj.extrarec.notifId;
if (myrecnotif.paramsObj.extrarec)
idnotiftosearch = myrecnotif.paramsObj.extrarec.notifId;
typeidsearch = shared_consts.TypeNotifs.ID_CIRCUIT_NEW_REC;
dest = myrecnotif.dest;
if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_ACCEPTED) {
@@ -490,6 +508,14 @@ sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysa
} 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;
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_ACCEPTED_SENT) {
if (myrecnotif.paramsObj.extrarec.hasOwnProperty('notifIdToUpdate'))
idnotiftosearch = myrecnotif.paramsObj.extrarec.notifIdToUpdate;
newstatus = shared_consts.CircuitsNotif.STATUS_COINS_ACCEPTED_SENT;
} else if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_REFUSED_SENT) {
if (myrecnotif.paramsObj.extrarec.hasOwnProperty('notifIdToUpdate'))
idnotiftosearch = myrecnotif.paramsObj.extrarec.notifIdToUpdate;
newstatus = shared_consts.CircuitsNotif.STATUS_COINS_REFUSED_SENT;
}
}
@@ -663,12 +689,11 @@ sendNotifSchema.statics.createNewNotifToSingleUser = async function(req, res, pa
myrecnotif = this.getExtraParam(myrecnotif, paramsObj);
await SendNotif.sendToSingleUserDest(myrecnotif, req, res, onlysave);
return await SendNotif.sendToSingleUserDest(myrecnotif, req, res, onlysave);
return true;
} catch (e) {
console.error('createNewNotification', e);
return false;
return null;
}
};
@@ -773,7 +798,7 @@ sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotifpass, r
if (send) {
let myrecnotif = new SendNotif(myrecnotifpass);
myrecnotif.dest = user.username;
await SendNotif.saveAndSendNotif(myrecnotif, req, res, user);
return await SendNotif.saveAndSendNotif(myrecnotif, req, res, user);
}
}
}
@@ -795,9 +820,9 @@ sendNotifSchema.statics.sendToSingleUserDest = async function(myrecnotif, req, r
: myrecnotif.dest;
if (onlysave) {
await SendNotif.saveNotif(myrecnotif);
return await SendNotif.saveNotif(myrecnotif);
} else {
await SendNotif.saveAndSendNotif(myrecnotif, req, res, null);
return await SendNotif.saveAndSendNotif(myrecnotif, req, res, null);
}
} catch (e) {

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
const mongoose = require('mongoose').set('debug', process.env.DEBUG)
const mongoose = require('mongoose').set('debug', false)
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', process.env.DEBUG);
mongoose.set('debug', false);
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
var mongoose = require('mongoose').set('debug', process.env.DEBUG)
var mongoose = require('mongoose').set('debug', false)
const _ = require('lodash');
@@ -18,7 +18,7 @@ mongoose.plugin(schema => {
schema.options.usePushEach = true
});
mongoose.set('debug', process.env.DEBUG);
mongoose.set('debug', false);
var TodoSchema = new mongoose.Schema({
userId: {

View File

@@ -1,5 +1,5 @@
const bcrypt = require('bcryptjs');
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const mongoose = require('mongoose').set('debug', false);
const validator = require('validator');
const jwt = require('jsonwebtoken');
const _ = require('lodash');
@@ -32,7 +32,7 @@ mongoose.plugin(schema => {
schema.options.usePushEach = true;
});
mongoose.set('debug', process.env.DEBUG);
mongoose.set('debug', false);
const UserSchema = new mongoose.Schema({
userId: {
@@ -2107,6 +2107,9 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
// Elimina eventualmente se era bloccato:
update = {$pull: {refused_users: {username: {$in: [usernameOrig]}}}};
await Circuit.updateOne({idapp, name: circuitname}, update);
await Account.createAccount(idapp, usernameOrig, circuitname);
} else {
ris = false;
}
@@ -2137,7 +2140,6 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
};
ris = await Circuit.updateOne({idapp, name: circuitname}, update);
await Account.createAccount(idapp, usernameOrig, circuitname);
}
if (ris) {
// Invia una notifica alla persona
@@ -2215,7 +2217,7 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
ris = ris2;
} else if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT) {
} else if ((cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT) || (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REFUSE)) {
// Before to accept, I see if it's already set !
let ris2 = {
@@ -2231,7 +2233,11 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
risStatus = i18n.__('STATUS_REFUSED');
}
if (!await SendNotif.checkIfCoinsAlreadySent(extrarec.notifId)) {
ris2 = await Circuit.sendCoins(false, idapp, usernameOrig, extrarec);
if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT) {
ris2 = await Circuit.sendCoins(false, idapp, usernameOrig, extrarec);
} else {
ris2.cansend = true;
}
if (ris2.cansend) {
// Invia una notifica di moneta alla persona
@@ -2239,6 +2245,8 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
}
ris2.recnotif = await SendNotif.getRecNotif(extrarec.notifId);
ris2.user = await User.getExtraInfoByUsername(idapp, username_action);
} else {
ris2.cansend = false;
@@ -3734,7 +3742,18 @@ UserSchema.statics.DbOp = async function(idapp, mydata) {
};
UserSchema.statics.addExtraInfo = async function(idapp, recUser, req) {
UserSchema.statics.getExtraInfoByUsername = async function(idapp, username) {
const User = this;
let myuser = await User.findOne({idapp, username});
if (myuser) {
myuserextra = await User.addExtraInfo(idapp, myuser);
}
return myuser._doc;
};
UserSchema.statics.addExtraInfo = async function(idapp, recUser) {
try {
const listSentMyRequestFriends = await User.find({
@@ -3795,7 +3814,7 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser, req) {
// Circuit>
const circuitobj = await Circuit.getCircuitsByUsername(idapp, recUser.username, req);
const circuitobj = await Circuit.getCircuitsByUsername(idapp, recUser.username, recUser);
const useraccounts = await Account.getUserAccounts(idapp, recUser.username);

View File

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

View File

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