diff --git a/geruecht/user/routes.py b/geruecht/user/routes.py index beaade9..ab041de 100644 --- a/geruecht/user/routes.py +++ b/geruecht/user/routes.py @@ -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 \ No newline at end of file + 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