Quando aggiungi e rimuovi poi quando lo riaggiungi controlla che già non ci sia un ACCOUNTS ! (ora crea un'altro ACCOUNTS !)
This commit is contained in:
@@ -192,7 +192,7 @@ AccountSchema.pre('save', async function(next) {
|
||||
next();
|
||||
});
|
||||
|
||||
AccountSchema.statics.getAccountByUsernameAndCircuitId = async function(idapp, username, {circuitId, circuitName}, createifnotexist) {
|
||||
AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp, username, circuitId, createifnotexist) {
|
||||
const Account = this;
|
||||
|
||||
try {
|
||||
@@ -205,20 +205,10 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function(idapp, u
|
||||
let myquery = {
|
||||
'idapp': idapp,
|
||||
'username': username,
|
||||
circuitId,
|
||||
};
|
||||
|
||||
if (circuitId) {
|
||||
myquery.circuitId = circuitId;
|
||||
}
|
||||
if (circuitName) {
|
||||
myquery.circuitName = circuitName;
|
||||
}
|
||||
|
||||
let mycircuit;
|
||||
if (circuitId)
|
||||
mycircuit = await Circuit.getCircuitById(circuitId);
|
||||
else
|
||||
mycircuit = await Circuit.findOne({name: circuitName});
|
||||
let mycircuit = await Circuit.getCircuitById(circuitId);
|
||||
|
||||
if (mycircuit) {
|
||||
let myaccount = await Account.findOne(myquery);
|
||||
@@ -251,7 +241,19 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function(idapp, u
|
||||
|
||||
AccountSchema.statics.createAccount = async function (idapp, username, circuitName) {
|
||||
|
||||
return await Account.getAccountByUsernameAndCircuitId(idapp, username, {circuitName}, true);
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
try {
|
||||
mycircuit = await Circuit.findOne({ name: circuitName }, {_id: 1});
|
||||
if (mycircuit) {
|
||||
return await Account.getAccountByUsernameAndCircuitId(idapp, username, mycircuit._id, true);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('error', e);
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -614,8 +614,8 @@ CircuitSchema.statics.sendCoins = async function(onlycheck, idapp, usernameOrig,
|
||||
if (circuittable) {
|
||||
const myqty = Math.abs(extrarec.qty);
|
||||
|
||||
const accountdestTable = await Account.getAccountByUsernameAndCircuitId(idapp, extrarec.dest, {circuitId: circuittable._id}, true);
|
||||
const accountorigTable = await Account.getAccountByUsernameAndCircuitId(idapp, usernameOrig, {circuitId: circuittable._id}, true);
|
||||
const accountdestTable = await Account.getAccountByUsernameAndCircuitId(idapp, extrarec.dest, circuittable._id, true);
|
||||
const accountorigTable = await Account.getAccountByUsernameAndCircuitId(idapp, usernameOrig, circuittable._id, true);
|
||||
|
||||
const circolantePrec = this.getCircolanteSingolaTransaz(accountorigTable, accountdestTable);
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ MovementSchema.statics.getQueryMovsByCircuitId = async function(idapp, username,
|
||||
if (!circuitId) {
|
||||
return [];
|
||||
}
|
||||
const myaccount = await Account.getAccountByUsernameAndCircuitId(idapp, username, {circuitId}, false);
|
||||
const myaccount = await Account.getAccountByUsernameAndCircuitId(idapp, username, circuitId, false);
|
||||
|
||||
if (myaccount) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user