fixed double send coins... if user clicked twice.
This commit is contained in:
@@ -12,6 +12,7 @@ const tools = require('../tools/general');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
@@ -56,6 +57,9 @@ const AccountSchema = new Schema({
|
||||
totTransato: {
|
||||
type: Number,
|
||||
},
|
||||
regulation_ok: {
|
||||
type: Boolean,
|
||||
},
|
||||
deleted: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
@@ -134,7 +138,7 @@ AccountSchema.statics.calcTotCircolante = async function(idapp, circuitId) {
|
||||
}
|
||||
|
||||
};
|
||||
AccountSchema.methods.addtoSaldo = async function(amount) {
|
||||
AccountSchema.methods.addtoSaldoSave = async function(amount) {
|
||||
const account = this;
|
||||
|
||||
if (account) {
|
||||
@@ -150,6 +154,36 @@ AccountSchema.methods.addtoSaldo = async function(amount) {
|
||||
return null;
|
||||
};
|
||||
|
||||
AccountSchema.statics.addtoSaldo = async function(myaccount, amount) {
|
||||
const Account = this;
|
||||
|
||||
try {
|
||||
let myaccountupdate = {};
|
||||
|
||||
if (myaccount) {
|
||||
myaccount.saldo = myaccount.saldo + amount;
|
||||
if (!myaccount.totTransato) {
|
||||
myaccount.totTransato = 0;
|
||||
}
|
||||
myaccount.totTransato += Math.abs(amount);
|
||||
myaccount.date_updated = new Date();
|
||||
|
||||
myaccountupdate.saldo = myaccount.saldo;
|
||||
myaccountupdate.totTransato = myaccount.totTransato;
|
||||
myaccountupdate.date_updated = myaccount.date_updated;
|
||||
|
||||
return await Account.updateOne({_id: myaccount.id},
|
||||
{
|
||||
$set: myaccountupdate
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('error', e);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
AccountSchema.pre('save', async function(next) {
|
||||
if (this.isNew) {
|
||||
this.date_created = new Date();
|
||||
|
||||
Reference in New Issue
Block a user