mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-17 04:58:50 -04:00
Ad a reference to the model
- used if 3rd party needs to record an ID for reconciliation purposes
This commit is contained in:
@@ -9,7 +9,8 @@ from app.dao.notifications_dao import (
|
||||
dao_update_notification,
|
||||
delete_failed_notifications_created_more_than_a_week_ago,
|
||||
delete_successful_notifications_created_more_than_a_day_ago,
|
||||
dao_get_notification_statistics_for_service_and_day
|
||||
dao_get_notification_statistics_for_service_and_day,
|
||||
update_notification_reference_by_id
|
||||
)
|
||||
from app.dao.jobs_dao import dao_update_job, dao_get_job_by_id
|
||||
from app.dao.users_dao import delete_codes_older_created_more_than_a_day_ago
|
||||
@@ -205,7 +206,7 @@ def send_sms(service_id, notification_id, encrypted_notification, created_at):
|
||||
client.send_sms(
|
||||
to=notification['to'],
|
||||
content=template.replaced,
|
||||
notification_id=notification_id
|
||||
reference=str(notification_id)
|
||||
)
|
||||
except FiretextClientException as e:
|
||||
current_app.logger.error(
|
||||
@@ -273,12 +274,13 @@ def send_email(service_id, notification_id, subject, from_address, encrypted_not
|
||||
values=notification.get('personalisation', {})
|
||||
)
|
||||
|
||||
client.send_email(
|
||||
reference = client.send_email(
|
||||
from_address,
|
||||
notification['to'],
|
||||
subject,
|
||||
template.replaced
|
||||
)
|
||||
update_notification_reference_by_id(notification_id, reference)
|
||||
except AwsSesClientException as e:
|
||||
current_app.logger.debug(e)
|
||||
notification_db_object.status = 'failed'
|
||||
|
||||
@@ -64,6 +64,7 @@ def update_job_sent_count(notification):
|
||||
|
||||
|
||||
def dao_update_notification(notification):
|
||||
notification.updated_at = datetime.utcnow()
|
||||
db.session.add(notification)
|
||||
db.session.commit()
|
||||
|
||||
@@ -90,6 +91,28 @@ def update_notification_status_by_to(to, status):
|
||||
return count
|
||||
|
||||
|
||||
def update_notification_status_by_reference(reference, status):
|
||||
count = db.session.query(Notification).filter_by(
|
||||
refernce=reference
|
||||
).update({
|
||||
Notification.status: status,
|
||||
Notification.updated_at: datetime.utcnow()
|
||||
})
|
||||
db.session.commit()
|
||||
return count
|
||||
|
||||
|
||||
def update_notification_reference_by_id(id, reference):
|
||||
count = db.session.query(Notification).filter_by(
|
||||
id=id
|
||||
).update({
|
||||
Notification.reference: reference,
|
||||
Notification.updated_at: datetime.utcnow()
|
||||
})
|
||||
db.session.commit()
|
||||
return count
|
||||
|
||||
|
||||
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()
|
||||
|
||||
|
||||
@@ -265,6 +265,7 @@ class Notification(db.Model):
|
||||
onupdate=datetime.datetime.now)
|
||||
status = db.Column(
|
||||
db.Enum(*NOTIFICATION_STATUS_TYPES, name='notification_status_types'), nullable=False, default='sent')
|
||||
reference = db.Column(db.String, nullable=True, index=True)
|
||||
|
||||
|
||||
INVITED_USER_STATUS_TYPES = ['pending', 'accepted', 'cancelled']
|
||||
|
||||
Reference in New Issue
Block a user