diff --git a/app/dao/fact_notification_status_dao.py b/app/dao/fact_notification_status_dao.py index a810ff0db..b1afcc70f 100644 --- a/app/dao/fact_notification_status_dao.py +++ b/app/dao/fact_notification_status_dao.py @@ -1,4 +1,4 @@ -from datetime import timedelta +from datetime import date, timedelta from sqlalchemy import Date, case, func from sqlalchemy.dialects.postgresql import insert @@ -136,7 +136,10 @@ def fetch_notification_status_for_service_for_today_and_7_previous_days( ), FactNotificationStatus.notification_status.cast(db.Text).label("status"), *( - [FactNotificationStatus.template_id.label("template_id")] + [ + FactNotificationStatus.template_id.label("template_id"), + FactNotificationStatus.local_date.label("last_used"), + ] if by_template else [] ), @@ -151,7 +154,14 @@ def fetch_notification_status_for_service_for_today_and_7_previous_days( db.session.query( Notification.notification_type.cast(db.Text), Notification.status.cast(db.Text), - *([Notification.template_id] if by_template else []), + *( + [ + Notification.template_id, + literal(date.today()).label("last_used"), + ] + if by_template + else [] + ), func.count().label("count"), ) .filter( @@ -174,6 +184,8 @@ def fetch_notification_status_for_service_for_today_and_7_previous_days( Template.name.label("template_name"), False, # TODO: this is related to is_precompiled_letter all_stats_table.c.template_id, + Template.folder.name.label("folder"), + Template.created_by.name.label("created_by"), ] if by_template else [] diff --git a/app/template_statistics/rest.py b/app/template_statistics/rest.py index 03a319ecc..08467cfeb 100644 --- a/app/template_statistics/rest.py +++ b/app/template_statistics/rest.py @@ -23,7 +23,7 @@ def get_template_statistics_for_service_by_day(service_id): try: whole_days = int(whole_days) except ValueError: - error = "{} is not an integer".format(whole_days) + error = f"{whole_days} is not an integer" message = {"whole_days": [error]} raise InvalidRequest(message, status_code=400)