finished ##201

api that user can storno transaction
This commit is contained in:
Tim Gröger 2020-02-27 15:53:49 +01:00
parent fcc76a639f
commit f296986924
1 changed files with 28 additions and 1 deletions

View File

@ -233,4 +233,31 @@ def _deleteTransactJob(**kwargs):
userController.deleteTransactJob(from_user, to_user, date)
return jsonify({"ok": "ok"})
except Exception as err:
return jsonify({"error": str(err)}), 409
return jsonify({"error": str(err)}), 409
@user.route("/user/storno", methods=['POST'])
@login_required(groups=[USER])
def _storno(**kwargs):
""" Function for Baruser to storno amount
This function added to the user with the posted userID the posted amount.
Returns:
JSON-File with userID and the amount
or ERROR 401 Permission Denied
"""
try:
if 'accToken' in kwargs:
accToken = kwargs['accToken']
user = accToken.user
data = request.get_json()
amount = int(data['amount'])
date = datetime.now()
userController.addCredit(user.uid, amount, year=date.year, month=date.month)
accToken.user = userController.getUser(accToken.user.uid)
retVal = accToken.user.toJSON()
retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte}
return jsonify(retVal)
except Exception as err:
return jsonify({"error": str(err)}), 409