mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
Provider stats only updated if the provider successfully sends the message.
This commit is contained in:
@@ -176,22 +176,6 @@ def dao_create_notification(notification, notification_type, provider_identifier
|
||||
service_id=notification.service_id)
|
||||
db.session.add(template_stats)
|
||||
|
||||
update_count = db.session.query(ProviderStatistics).filter_by(
|
||||
day=date.today(),
|
||||
service_id=notification.service_id,
|
||||
provider_id=provider.id
|
||||
).update({'unit_count': ProviderStatistics.unit_count + (
|
||||
1 if notification_type == TEMPLATE_TYPE_EMAIL else get_sms_fragment_count(notification.content_char_count))})
|
||||
|
||||
if update_count == 0:
|
||||
provider_stats = ProviderStatistics(
|
||||
day=notification.created_at.date(),
|
||||
service_id=notification.service_id,
|
||||
provider_id=provider.id,
|
||||
unit_count=1 if notification_type == TEMPLATE_TYPE_EMAIL else get_sms_fragment_count(
|
||||
notification.content_char_count))
|
||||
db.session.add(provider_stats)
|
||||
|
||||
db.session.add(notification)
|
||||
|
||||
|
||||
@@ -293,14 +277,28 @@ def dao_update_notification(notification):
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def update_notification_reference_by_id(id, reference):
|
||||
count = db.session.query(Notification).filter_by(
|
||||
id=id
|
||||
).update({
|
||||
Notification.reference: reference
|
||||
})
|
||||
db.session.commit()
|
||||
return count
|
||||
@transactional
|
||||
def update_notification_after_sent_to_provider(id_, notification_type, provider_name, reference=None):
|
||||
provider = ProviderDetails.query.filter_by(identifier=provider_name).one()
|
||||
notification = Notification.query.filter(Notification.id == id_).one()
|
||||
if reference:
|
||||
notification.reference = reference
|
||||
db.session.add(notification)
|
||||
update_count = db.session.query(ProviderStatistics).filter_by(
|
||||
day=date.today(),
|
||||
service_id=notification.service_id,
|
||||
provider_id=provider.id
|
||||
).update({'unit_count': ProviderStatistics.unit_count + (
|
||||
1 if notification_type == TEMPLATE_TYPE_EMAIL else get_sms_fragment_count(notification.content_char_count))})
|
||||
|
||||
if update_count == 0:
|
||||
provider_stats = ProviderStatistics(
|
||||
day=notification.created_at.date(),
|
||||
service_id=notification.service_id,
|
||||
provider_id=provider.id,
|
||||
unit_count=1 if notification_type == TEMPLATE_TYPE_EMAIL else get_sms_fragment_count(
|
||||
notification.content_char_count))
|
||||
db.session.add(provider_stats)
|
||||
|
||||
|
||||
def get_notification_for_job(service_id, job_id, notification_id):
|
||||
|
||||
Reference in New Issue
Block a user