mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 00:41:35 -05:00
Refactored to put notifications update last
This commit is contained in:
@@ -281,25 +281,33 @@ def dao_update_notification(notification):
|
|||||||
def update_notification_after_sent_to_provider(id_, notification_type, provider_name, reference=None):
|
def update_notification_after_sent_to_provider(id_, notification_type, provider_name, reference=None):
|
||||||
provider = ProviderDetails.query.filter_by(identifier=provider_name).one()
|
provider = ProviderDetails.query.filter_by(identifier=provider_name).one()
|
||||||
notification = Notification.query.filter(Notification.id == id_).one()
|
notification = Notification.query.filter(Notification.id == id_).one()
|
||||||
if reference:
|
|
||||||
notification.reference = reference
|
def unit_count():
|
||||||
db.session.add(notification)
|
if notification_type == TEMPLATE_TYPE_EMAIL:
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
return get_sms_fragment_count(notification.content_char_count)
|
||||||
|
|
||||||
update_count = db.session.query(ProviderStatistics).filter_by(
|
update_count = db.session.query(ProviderStatistics).filter_by(
|
||||||
day=date.today(),
|
day=date.today(),
|
||||||
service_id=notification.service_id,
|
service_id=notification.service_id,
|
||||||
provider_id=provider.id
|
provider_id=provider.id
|
||||||
).update({'unit_count': ProviderStatistics.unit_count + (
|
).update({'unit_count': ProviderStatistics.unit_count + unit_count()})
|
||||||
1 if notification_type == TEMPLATE_TYPE_EMAIL else get_sms_fragment_count(notification.content_char_count))})
|
|
||||||
|
|
||||||
if update_count == 0:
|
if update_count == 0:
|
||||||
provider_stats = ProviderStatistics(
|
provider_stats = ProviderStatistics(
|
||||||
day=notification.created_at.date(),
|
day=notification.created_at.date(),
|
||||||
service_id=notification.service_id,
|
service_id=notification.service_id,
|
||||||
provider_id=provider.id,
|
provider_id=provider.id,
|
||||||
unit_count=1 if notification_type == TEMPLATE_TYPE_EMAIL else get_sms_fragment_count(
|
unit_count=unit_count()
|
||||||
notification.content_char_count))
|
)
|
||||||
|
|
||||||
db.session.add(provider_stats)
|
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):
|
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()
|
return Notification.query.filter_by(service_id=service_id, job_id=job_id, id=notification_id).one()
|
||||||
|
|||||||
Reference in New Issue
Block a user