diff --git a/app/api/routes/routes.py b/app/api/routes/routes.py index 9b03b0c..62f6f86 100644 --- a/app/api/routes/routes.py +++ b/app/api/routes/routes.py @@ -447,7 +447,7 @@ def get_office_sidebar(): @api.route('/office/users', methods=['GET']) def get_office_users(): - # Call the dashboard service + logger.info('API::get office users') filters = {} result = OfficeUsersService.get_office_users(filters) return jsonify(result) diff --git a/app/api/services/office_users.py b/app/api/services/office_users.py index fd87bd5..8ebfb75 100644 --- a/app/api/services/office_users.py +++ b/app/api/services/office_users.py @@ -4,32 +4,40 @@ from app.api.services.base_service import BaseService from sqlalchemy import func, desc from datetime import datetime, timedelta, timezone from app.extensions import db -from app.models import MembersProducts, Products, Members, ProductsDetails, ProductsDetails, ProvisionActions, Payments, \ - OfficeUsers +from app.models import OfficeUsers class OfficeUsersService(BaseService): @staticmethod def get_office_users(filters): - office_users = OfficeUsers.get_office_users_list() - office_users_data = [] - if office_users: - for t in office_users: - office_users_data.append({ - 'id': t.id, - 'uid': t.uid, - 'product_id': t.product_id, - 'description': t.description, - 'name': t.name, - 'status': t.status, - 'added': t.added.isoformat() if t.added else None, - 'updated': t.updated.isoformat() if t.updated else None, - 'banner': t.banner, - }) + logger.info('get office users') + try: + office_users = OfficeUsers.get_office_users_list() + office_users_data = [] + if office_users: + for t in office_users: + office_users_data.append({ + 'id': t.id, + 'uid': t.uid, + 'username': t.username, + 'firstname': t.firstname, + 'lastname': t.lastname, + 'acc_level': t.acc_level, + 'status': t.status, + 'added': t.added.isoformat() if t.added else None + }) + + office_users_result = { + "office_users": office_users_data, + } + return office_users_result + + except Exception as e: + logger.error(f"An error occurred: {str(e)}", exc_info=True) + office_users_result = { + "error": f"An error occurred: {str(e)}", + } + return office_users_result - office_users_result = { - "office_users": office_users_data, - } - return office_users_result diff --git a/app/models/office_users.py b/app/models/office_users.py index e8cdc89..c6f3eb2 100644 --- a/app/models/office_users.py +++ b/app/models/office_users.py @@ -37,9 +37,6 @@ class OfficeUsers(db.Model): @classmethod def get_office_users_list(cls): - """ - Return all offers in dictionary format. - """ users_list = cls.query.all() if not users_list: