diff --git a/geruecht/baruser/routes.py b/geruecht/baruser/routes.py index 92ac2bb..a8c47a4 100644 --- a/geruecht/baruser/routes.py +++ b/geruecht/baruser/routes.py @@ -95,6 +95,37 @@ def _getUsers(**kwargs): retVal = ldap.getAllUser() return jsonify(retVal) +@baruser.route("/bar/storno", methods=['POST']) +@login_required(groups=[BAR]) +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 + """ + data = request.get_json() + userID = data['userId'] + amount = int(data['amount']) + + date = datetime.now() + userController.addCredit(userID, amount, year=date.year, month=date.month) + user = userController.getUser(userID) + geruecht = user.getGeruecht(year=date.year) + month = geruecht.getMonth(month=date.month) + amount = abs(month[0] - month[1]) + all = geruecht.getSchulden() + if all >= 0: + type = 'credit' + else: + type = 'amount' + dic = user.toJSON() + dic['amount'] = abs(all) + dic['type'] = type + + return jsonify(dic) @baruser.route("/barGetUser", methods=['POST']) @login_required(groups=[BAR])