intrgrating suggestions after betta 1
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from flask import Blueprint, request, jsonify
|
||||
from models.client import Clients
|
||||
from models.user import Users
|
||||
|
||||
from flask_jwt_extended import jwt_required, get_jwt_identity
|
||||
|
||||
@@ -10,6 +11,10 @@ clients_bp = Blueprint("clients", __name__, url_prefix="/clients")
|
||||
def list_clients():
|
||||
clients_db = Clients()
|
||||
user_id = get_jwt_identity()
|
||||
users = Users()
|
||||
user = users.get_user_by_id(user_id)
|
||||
if user['user_role'] == 'company_user':
|
||||
user_id = user['company_id']
|
||||
clients = clients_db.get_all_by_user(user_id)
|
||||
return jsonify(clients), 200
|
||||
|
||||
@@ -19,6 +24,10 @@ def create_client():
|
||||
clients_db = Clients()
|
||||
user_id = get_jwt_identity()
|
||||
data = request.get_json()
|
||||
users = Users()
|
||||
user = users.get_user_by_id(user_id)
|
||||
if user['user_role'] == 'company_user':
|
||||
user_id = user['company_id']
|
||||
client_id = clients_db.create(
|
||||
user_id=user_id,
|
||||
name=data["name"],
|
||||
|
||||
Reference in New Issue
Block a user