fixed double send coins... if user clicked twice.
This commit is contained in:
@@ -24,6 +24,9 @@ const MovementSchema = new Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
},
|
||||
notifId: {
|
||||
type: String,
|
||||
},
|
||||
transactionDate: {
|
||||
type: Date,
|
||||
},
|
||||
@@ -85,13 +88,13 @@ MovementSchema.statics.executeQueryTable = function(idapp, params) {
|
||||
return tools.executeQueryTable(this, 0, params);
|
||||
};
|
||||
|
||||
MovementSchema.statics.addMov = async function(idapp, accountFromIdTable, accountToIdTable, amount, causal) {
|
||||
MovementSchema.statics.addMov = async function(idapp, accountFromIdTable, accountToIdTable, amount, causal, notifId) {
|
||||
|
||||
try {
|
||||
// Only positive values
|
||||
amount = Math.abs(amount);
|
||||
|
||||
let mymov = Movement(
|
||||
let mymov = await Movement.create(
|
||||
{
|
||||
_id: new ObjectID().toString(),
|
||||
idapp,
|
||||
@@ -101,18 +104,18 @@ MovementSchema.statics.addMov = async function(idapp, accountFromIdTable, accoun
|
||||
amount,
|
||||
causal,
|
||||
residual: 0,
|
||||
notifId,
|
||||
// expiringDate:
|
||||
},
|
||||
);
|
||||
|
||||
const rismov = await mymov.save();
|
||||
if (rismov) {
|
||||
if (mymov) {
|
||||
// Update saldo dell'Account
|
||||
await accountToIdTable.addtoSaldo(amount);
|
||||
await Account.addtoSaldo(accountToIdTable, amount);
|
||||
|
||||
await accountFromIdTable.addtoSaldo(-amount);
|
||||
await Account.addtoSaldo(accountFromIdTable, amount);
|
||||
|
||||
return rismov;
|
||||
return mymov;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error in addMov', e.message);
|
||||
@@ -230,6 +233,7 @@ MovementSchema.statics.getQueryMovsByCircuitId = async function(idapp, username,
|
||||
transactionDate: 1,
|
||||
amount: 1,
|
||||
causal: 1,
|
||||
notifId: 1,
|
||||
'circuitfrom.symbol': 1,
|
||||
'circuitto.symbol': 1,
|
||||
'userfrom.username': 1,
|
||||
@@ -376,6 +380,7 @@ MovementSchema.statics.getQueryAllUsersMovsByCircuitId = async function(idapp, c
|
||||
transactionDate: 1,
|
||||
amount: 1,
|
||||
causal: 1,
|
||||
notifId: 1,
|
||||
'circuitfrom.symbol': 1,
|
||||
'circuitto.symbol': 1,
|
||||
'userfrom.username': 1,
|
||||
@@ -410,6 +415,22 @@ MovementSchema.statics.getMovsByCircuitId = async function(idapp, username, circ
|
||||
return [];
|
||||
};
|
||||
|
||||
MovementSchema.statics.checkIfCoinsAlreadySent = async function(notifId) {
|
||||
const MyMovement = this;
|
||||
|
||||
try {
|
||||
const rec = await MyMovement.findOne({notifId}, {_id: 1});
|
||||
|
||||
return !!rec;
|
||||
|
||||
} catch (e) {
|
||||
// If Error, don't send the coins
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
const Movement = mongoose.model('Movement', MovementSchema);
|
||||
|
||||
module.exports = {Movement};
|
||||
|
||||
Reference in New Issue
Block a user