mirror of
https://github.com/GSA/notifications-admin.git
synced 2025-12-11 07:33:36 -05:00
adding templates and refactor to use dashboard data endpoint
This commit is contained in:
@@ -77,17 +77,17 @@ def get_organization_message_allowance(org_id):
|
||||
|
||||
|
||||
def get_services_usage(organization, year):
|
||||
|
||||
try:
|
||||
services_and_usage = organization.services_and_usage(financial_year=year, include_all_services=True)["services"]
|
||||
dashboard_data = organizations_client.get_organization_dashboard(organization.id, year)
|
||||
services = dashboard_data.get("services", [])
|
||||
except Exception as e:
|
||||
current_app.logger.error(f"Error fetching services and usage: {e}")
|
||||
current_app.logger.error(f"Error fetching dashboard data: {e}")
|
||||
return []
|
||||
|
||||
services = []
|
||||
for service in services_and_usage:
|
||||
for service in services:
|
||||
service["id"] = service.get("service_id")
|
||||
service["name"] = service.get("service_name")
|
||||
service["recent_template"] = service.get("recent_sms_template_name")
|
||||
|
||||
emails_sent = service.get("emails_sent", 0)
|
||||
sms_sent = service.get("sms_billable_units", 0)
|
||||
@@ -105,8 +105,6 @@ def get_services_usage(organization, year):
|
||||
|
||||
service["usage"] = ", ".join(usage_parts) if usage_parts else "No usage"
|
||||
|
||||
services.append(service)
|
||||
|
||||
return services
|
||||
|
||||
|
||||
|
||||
@@ -83,5 +83,11 @@ class OrganizationsClient(NotifyAdminAPIClient):
|
||||
url="/organizations/{}/message-allowance".format(org_id),
|
||||
)
|
||||
|
||||
def get_organization_dashboard(self, org_id, year):
|
||||
return self.get(
|
||||
url=f"/organizations/{org_id}/dashboard",
|
||||
params={"year": str(year)},
|
||||
)
|
||||
|
||||
|
||||
organizations_client = OrganizationsClient()
|
||||
|
||||
Reference in New Issue
Block a user