mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 23:55:58 -05:00
Removed update reference from updating the provider stats
- single focus method - allows not to pollute DAO with research mode
This commit is contained in:
@@ -37,7 +37,7 @@ from app.dao.notifications_dao import (
|
||||
dao_update_notification,
|
||||
delete_notifications_created_more_than_a_week_ago,
|
||||
dao_get_notification_statistics_for_service_and_day,
|
||||
update_notification_after_sent_to_provider
|
||||
update_provider_stats
|
||||
)
|
||||
|
||||
from app.dao.jobs_dao import (
|
||||
@@ -268,7 +268,7 @@ def send_sms(service_id, notification_id, encrypted_notification, created_at):
|
||||
reference=str(notification_id)
|
||||
)
|
||||
|
||||
update_notification_after_sent_to_provider(
|
||||
update_provider_stats(
|
||||
notification_id,
|
||||
'sms',
|
||||
provider.get_name()
|
||||
@@ -349,13 +349,15 @@ def send_email(service_id, notification_id, from_address, encrypted_notification
|
||||
reply_to_addresses=reply_to_addresses,
|
||||
)
|
||||
|
||||
update_notification_after_sent_to_provider(
|
||||
update_provider_stats(
|
||||
notification_id,
|
||||
'email',
|
||||
provider.get_name(),
|
||||
reference=reference
|
||||
provider.get_name()
|
||||
)
|
||||
|
||||
notification_db_object.reference = reference
|
||||
dao_update_notification(notification_db_object)
|
||||
|
||||
except EmailClientException as e:
|
||||
current_app.logger.exception(e)
|
||||
notification_db_object.status = 'technical-failure'
|
||||
|
||||
@@ -278,9 +278,13 @@ def dao_update_notification(notification):
|
||||
|
||||
|
||||
@transactional
|
||||
def update_notification_after_sent_to_provider(id_, notification_type, provider_name, reference=None):
|
||||
provider = ProviderDetails.query.filter_by(identifier=provider_name).one()
|
||||
def update_provider_stats(
|
||||
id_,
|
||||
notification_type,
|
||||
provider_name):
|
||||
|
||||
notification = Notification.query.filter(Notification.id == id_).one()
|
||||
provider = ProviderDetails.query.filter_by(identifier=provider_name).one()
|
||||
|
||||
def unit_count():
|
||||
if notification_type == TEMPLATE_TYPE_EMAIL:
|
||||
@@ -304,10 +308,6 @@ def update_notification_after_sent_to_provider(id_, notification_type, provider_
|
||||
|
||||
db.session.add(provider_stats)
|
||||
|
||||
if reference:
|
||||
notification.reference = reference
|
||||
db.session.add(notification)
|
||||
|
||||
|
||||
def get_notification_for_job(service_id, job_id, notification_id):
|
||||
return Notification.query.filter_by(service_id=service_id, job_id=job_id, id=notification_id).one()
|
||||
|
||||
Reference in New Issue
Block a user