Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
payer = User.query.get(wallet_transaction.payer_id)
if payer is None:
return json_response(ResponseCode.NOT_FOUND)
payee = User.query.get(wallet_transaction.payee_id)
if payee is None:
return json_response(ResponseCode.NOT_FOUND)
count = User.query.filter(
and_(User.id == payer.id, User.wallet_money >= wallet_transaction.amount,
User.wallet_money == payer.wallet_money)
).update({
User.wallet_money: payer.wallet_money - wallet_transaction.amount
})
if count == 0:
session.rollback()
return json_response(ResponseCode.TRANSACTION_FAILURE)
count = User.query.filter(
and_(User.id == payee.id, User.wallet_money == payee.wallet_money)
).update({
User.wallet_money: payee.wallet_money + wallet_transaction.amount
})
if count == 0:
session.rollback()
return json_response(ResponseCode.TRANSACTION_FAILURE)
session.add(wallet_transaction)
session.commit()
return json_response(wallet_transaction=WalletTransactionSchema().dump(wallet_transaction))
and_(User.id == payer.id, User.wallet_money >= wallet_transaction.amount,
User.wallet_money == payer.wallet_money)
).update({
User.wallet_money: payer.wallet_money - wallet_transaction.amount
})
if count == 0:
session.rollback()
return json_response(ResponseCode.TRANSACTION_FAILURE)
count = User.query.filter(
and_(User.id == payee.id, User.wallet_money == payee.wallet_money)
).update({
User.wallet_money: payee.wallet_money + wallet_transaction.amount
})
if count == 0:
session.rollback()
return json_response(ResponseCode.TRANSACTION_FAILURE)
session.add(wallet_transaction)
session.commit()
return json_response(wallet_transaction=WalletTransactionSchema().dump(wallet_transaction))