def orders(*args, **kwargs): user = kwargs['user'].as_dict() user_id = kwargs['user'].id if(request.method == 'GET'): return OrderController.index(user_id) elif(request.method == 'POST'): return OrderController.create(request, user)
def admin_orders(*args, **kwargs): user = kwargs['user'] if user.role_id != ROLE['admin']: return Response(json.dumps({'message': 'unauthorized'}), status=401, mimetype='application/json') order_user = request.json['order_user'] if 'order_user' in request.json else None user = db.session.query( User).filter(or_(User.username.like(order_user), User.email.like(order_user))).first() if user is None: return json.dumps({ 'data': None, 'meta': { 'success': False, 'message': 'User with specified email or username not found' } }) return OrderController.create(request, user.as_dict())