Update the resultset to relect how users will consume the information.

- Do not show "hidden" or precompiled templates, users don't know about them.
- Remove the client reference if it is the file name of an uploaded file.
- Format the date for created_at
- Added a test for all the different types of letters.
 1) One off templated letter
 2) Letter created by a csv upload or job.
 3) Uploaded letter
 4) Templated letter sent by the API
 5) Precompiled letter sent by the API
This commit is contained in:
Rebecca Law
2019-12-23 16:00:59 +00:00
parent cd29acc2f4
commit e9baece3e7
4 changed files with 106 additions and 37 deletions

View File

@@ -74,6 +74,8 @@ def fetch_returned_letters(service_id, report_date):
Template.name.label('template_name'),
table.template_id,
table.template_version,
Template.hidden,
table.api_key_id,
table.created_by_id,
User.name.label('user_name'),
User.email_address,

View File

@@ -12,7 +12,7 @@ from notifications_utils.timezones import convert_utc_to_bst
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.exc import NoResultFound
from app import DATE_FORMAT, DATETIME_FORMAT
from app import DATE_FORMAT
from app.config import QueueNames
from app.dao import fact_notification_status_dao, notifications_dao
from app.dao.dao_utils import dao_rollback
@@ -963,17 +963,20 @@ def get_returned_letters(service_id):
json_results = [
{'notification_id': x.notification_id,
'client_reference': x.client_reference,
# client reference can only be added on API letters
'client_reference': x.client_reference if x.api_key_id else None,
'reported_at': x.reported_at.strftime(DATE_FORMAT),
'created_at': x.created_at.strftime(DATETIME_FORMAT),
'template_name': x.template_name,
'template_id': x.template_id,
'template_version': x.template_version,
'user_name': x.user_name,
'email_address': x.email_address,
'created_at': x.created_at.strftime("%Y-%m-%d %H:%M:%S"),
# it doesn't make sense to show hidden/precompiled templates
'template_name': x.template_name if not x.hidden else None,
'template_id': x.template_id if not x.hidden else None,
'template_version': x.template_version if not x.hidden else None,
'user_name': x.user_name or 'API',
'email_address': x.email_address or 'API',
'original_file_name': x.original_file_name,
'job_row_number': x.job_row_number,
'uploaded_letter': x.client_reference if x.user_name and not x.original_file_name else None
# the file name for a letter uploaded via the UI
'uploaded_letter': x.client_reference if x.hidden and not x.api_key_id else None
} for x in results]
return jsonify(sorted(json_results, key=lambda i: i['created_at'], reverse=True))